1

我正在尝试在多线程应用程序中使用 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");
        }
}
4

1 回答 1

0

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

于 2012-05-07T09:19:28.823 回答