【发布时间】:2012-05-15 19:05:26
【问题描述】:
我正在尝试在多线程应用程序中使用 MPI。在主线程中,我初始化 MPI 环境并创建一个 Manager 对象。 Manager 对象启动两个额外的线程,一个用于接收对象,一个用于 GUI 线程。每当用户单击发送按钮时,都应该将对象发送到相应的等级。有时操作会成功,但在某些情况下我会收到此错误:
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at MPI.Unsafe.MPI_Recv(IntPtr buf, Int32 count, Int32 datatype, Int32 source, Int32 tag, Int32 comm, MPI_Status& status)
at MPI.Communicator.Receive[T](Int32 source, Int32 tag, T& value, CompletedStatus& status)
at MPI.Communicator.Receive[T](Int32 source, Int32 tag, T& value)
at MPI.Communicator.Receive[T](Int32 source, Int32 tag)
代码:
public Manager(String managerID)
{
//other actions...
(new Thread(new ThreadStart(startGUIThread))).Start();
ReceiverThread = new Thread(new ThreadStart(MachineReceiver));
ReceiverThread.Start();
}
public void MachineReceiver()
{
while (IsRunning)
{
System.Console.Out.WriteLine("initiated");
Data data = Communicator.world.Receive<Data>(source, 100);
System.Console.Out.Write("Received");
}
}
【问题讨论】:
-
为了更好的文本格式:请在每行的末尾放置两个空格,以换行。您的错误消息将看起来更具可读性
-
请发布其他代码 - 特别是您进行 MPI 相关调用的地方。另外,您是否尝试在
gdb(或类似的)中运行它? -
您的 MPI 实现支持什么级别的线程?低级
MPI_Thread_init返回级别,也可以使用MPI_Query_thread。请查阅您的 MPI 包装器文档以了解如何获取它。如果提供的级别不是MPI_THREAD_MULTIPLE或MPI_THREAD_SERIALIZED,那么您不应从与调用MPI_Init_thread的线程不同的线程进行MPI 调用。
标签: multithreading mpi