将 MPI 与线程一起使用的正确方法是什么

What is the correct way to use MPI with thread

本文关键字:方法 是什么 MPI 线程 一起      更新时间:2023-10-16

我有一段这样的代码,运行在 4 MPI 进程上。

for (i=0;i<niter;i++){
    //.. do something with temprs
    memcpy(rs, temprs,..) // copy temprs content to rs     
    MPI_Gather(rs,...0...); //gather result to 0
    if (mpiRank == 0) writeToDisk(rs);
}

我想将最后 2 行代码放入一个函数中comm_and_save然后将其线程化,以便它可以与其余代码并行运行,如下所示:

boost::thread t1;
for (i=0;i<niter;i++){
    //.. do something with temprs
    t1.join(); // make sure previous comm_and_save done
    memcpy(rs, temprs,..) // copy temprs content to rs 
    t1 = boost::thread( comm_and_save, rs );
}
但是,代码有时运行,有时

挂起,有时抛出一些错误:

local QP operation err (QPN 5a0407, WQE @ 00000f02, CQN 280084, index 100677)
  [ 0] 005a0407
  [ 4] 00000000
  [ 8] 00000000
  [ c] 00000000
  [10] 0270c84f
  [14] 00000000
  [18] 00000f02
  [1c] ff100000

请启发我我做错了哪一部分谢谢

使用 MPI_Init_thread :http://www.mpi-forum.org/docs/mpi-20-html/node165.htm

并检查返回状态:可用的线程支持级别

干杯。