我正尝试在多线程应用程序中使用MPI。在主线程中,我初始化MPI环境并创建一个Manager对象。 Manager对象启动两个附加线程,一个用于接收对象和一个GUI线程。每当用户点击一个Send按钮时,一个对象应该被发送到相应的Rank。有时部份操作成功,但也有情况下,当我得到这个错误:在多线程应用程序中使用MPI
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调用。 –