|
|
guosong wrote:
I am new to open MPI
I am not, but I'm not real familiar with thread-safe MPI programming.
Still, I saw no other replies to your question, so I'll make an attempt
to answer.
MPI does not guarantee thread safety. E.g., see
http://www.mpi-forum.org/docs/mpi-20-html/node162.htm#Node162 and the
ensuing pages.
To do what you want to do, you need to make sure you have thread
safety. There is a standard MPI interface for doing so. I'm not good
at C++, so here is a C example:
#include <stdio.h>
#include <mpi.h>
int main(int argc, char **argv) {
int provided;
/* start MPI, asking for support for multiple threads */
MPI_Init_thread(&argc,&argv,MPI_THREAD_MULTIPLE,&provided);
/* report what level of support is actually provided */
if ( MPI_THREAD_SINGLE == provided ) printf("
MPI_THREAD_SINGLE\n");
if ( MPI_THREAD_FUNNELED == provided ) printf("
MPI_THREAD_FUNNELED\n");
if ( MPI_THREAD_SERIALIZED == provided ) printf("
MPI_THREAD_SERIALIZED\n");
if ( MPI_THREAD_MULTIPLE == provided ) printf("
MPI_THREAD_MULTIPLE\n");
/* exit */
MPI_Finalize();
return 0;
}
Run this program. If the program does not print out
"MPI_THREAD_MULTIPLE", you're not getting the level of thread support
you require and your program is not guaranteed to run properly. You
have to make sure you're using a thread-safe MPI before you can expect
your program to work.
The next question is whether Open MPI is thread safe, and I'll leave
you with this:
http://www.open-mpi.org/faq/?category=supported-systems#thread-support
Good luck. Again, I'm not experienced with thread-safe MPI programming
(though I understand the general concepts).
|
|
|