简体   繁体   English

在线程上使用MPI的正确方法是什么

[英]What is the correct way to use MPI with thread

I have a piece of code like this, running on 4 MPI process. 我有一段这样的代码,在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);
}

I want to put 2 last line of code into a function comm_and_save then threaded it so that It can run in parallel with the remaining code, something like below: 我想将最后两行代码放入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 );
}

However, the code sometime run, sometime hang, sometime throws some error: 但是,代码有时会运行,有时会挂起,有时会引发一些错误:

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

Please enlighten me which part I'm doing incorrectly Thank you 请告诉我我做错了哪一部分谢谢

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

and check return status: Available level of thread support 并检查返回状态:线程支持的可用级别

Cheerz. Cheerz。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM