在多线程应用程序中使用MPI

时间:2012-05-07 08:56:42

标签: multithreading mpi

我正在尝试在多线程应用程序中使用MPI。在主线程中,我初始化MPI环境并创建一个Manager对象。 Manager对象启动另外两个线程,一个用于接收对象,另一个用于GUI线程。每当用户点击发送按钮时,就应该将对象发送到相应的Rank。有时操作成功,但有时会出现此错误:

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");
        }
}

我一直试图解决这个问题已经有两个星期了,所以任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

您是否使用MPI_Init()初始化MPI?如果是这样,那对于多线程程序来说是错误的。您需要使用MPI_Init_thread()。见http://www.mpi-forum.org/docs/mpi-20-html/node165.htm