How to make two processes with two threads recieve, send to each other in MPI?

444 views Asked by At

Basically I want to achieve something like this:

Process 1
  Thread 1
    Receive X from process 2
  Thread 2
    Receive Y from process 2
Process 2
  Thread 1
    Send X to process 1
  Thread 2
    Send Y to process 1

in MPI for C language with pthreads library.
I did it already in PVM, here's the source code:
master.c : http://pastebin.com/wwEie7gn ,
slave.c : http://pastebin.com/gfeCkcss .
What I tried to do:
prog.c : http://pastebin.com/tCVKN3fe
Somehow receiver threads don't receive anything. I don't know what the problem is. I hope that someone can show me the proper way to do it.
I'm running MPI compiled without thread support.

1

There are 1 answers

2
Hristo Iliev On

You would like to use different tags for both messages, e.g. you can tag the message with the (known?) ID of the receiver thread. Then each thread in process 1 would post a receive with its ID as tag and that receive would only match the message directed to that particular thread.

Please note that MPI 2.2 provides limited interoperability with threading. By default most MPI implementations are not thread-safe. Open MPI for example requires one to explicitly enable full threading support during configuration time (it is disabled by default). You need to at least have MPI_THREAD_SERIALIZED threading level as returned in the provided argument of MPI_Thread_init (or MPI_Query_thread) in order be able to make MPI calls in different threads. If your MPI library only provides MPI_THREAD_SINGLE or MPI_THREAD_FUNNELED levels, you are out of luck and cannot make MPI calls in other than the main thread. If the provided level is MPI_THREAD_SERIALIZED, then you can make MPI calls from any thread, but you have to explicitly serialise the calls, i.e. make sure that no two or more calls are made simulatenously (e.g. with critial sections or mutexes). If the provided level is MPI_THREAD_MULTIPLE then you have full multithreaded support and can make MPI calls from whatever thread and at whatever point in time.