Hello,<div><br></div><div><br></div><div>I having a question regarding the usage of MPI_THREAD_MULTIPLE.</div><div><br></div><div>I was wondering whether this scenario works with MPI</div><div><br></div><div>Process 0</div>
<div>Thread 1 -> probes and receives</div><div>Thread 2 -> Sends to process 0</div><div><br></div><div>Process 1</div><div><br></div><div>Thread 1 -> probes and receives</div><div>Thread 2 -> Sends to process 1</div>
<div><br></div><div>I wrote a simple code, and it seems to hang with mpich2. I am not sure whether or not this feature is supported with MPI, can anyone let me know whether what I do here is correct or wrong?</div><div><br>
</div><div><br></div><div>Here is the code.. This code hangs when I use it with two processes. It works with one process. </div><div><br></div><div>Thanks</div><div>Ramesh</div><div>____________________________________________________________________________________________________________________________________________________</div>
<div><div><div>#include <stdio.h></div><div>#include <stdlib.h></div><div>#include <mpi.h></div><div>#include <string.h></div><div>#include <assert.h></div><div><br></div><div>typedef struct</div>
<div>{</div><div> int thread;</div><div> MPI_Comm comm;</div><div> int rank;</div><div>} thdata;</div><div><br></div><div>void probe_recv (void *ptr){</div><div> thdata *data;</div><div> data = (thdata *) ptr;</div><div>
int count, flag = 0;</div><div> MPI_Status status;</div><div> char buf[256];</div><div> </div><div> printf("%d :Thread :%d Prbes and receives \n", data->rank, data->thread);</div><div> while (!flag){</div>
<div> MPI_Iprobe(data->rank, 0, data->comm, &flag, &status);</div><div> }</div><div> MPI_Get_count( &status, MPI_CHAR, &count);</div><div> printf("%d :Thread :%d count : %d \n", data->rank, data->thread, count);</div>
<div><br></div><div> MPI_Recv( &buf, </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> count, </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> MPI_CHAR, </div><div>
<span class="Apple-tab-span" style="white-space:pre"> </span> data->rank, </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> status.MPI_TAG, </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> data->comm, </div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> MPI_STATUS_IGNORE);</div><div> </div><div> printf("%d Message : %s \n", data->rank,buf);</div><div>}</div><div><br></div><div>void send(void *ptr){</div>
<div> thdata *data;</div><div> char buffer[256];</div><div> data = (thdata *) ptr;</div><div> printf("%d: Thread :%d Sends \n", data->rank, data->thread);</div><div> strcpy(buffer,"Hello World");</div>
<div> MPI_Send(&buffer,256, MPI_CHAR, data->rank, 0, data->comm);</div><div> printf("%d: Thread :%d send completed \n",</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> data->rank,</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> data->thread);</div><div>}</div><div><br></div><div><br></div><div>int main(int argc, char *argv[]){</div><div><br></div><div> int provided, i[2], rank, size;</div>
<div> MPI_Status status;</div><div> pthread_t thread_a, thread_b;</div><div> MPI_Comm communicator[2];</div><div> thdata data1, data2;</div><div><br></div><div> MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); <span class="Apple-tab-span" style="white-space:pre"> </span></div>
<div><br></div><div> if (provided != MPI_THREAD_MULTIPLE){</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>printf("Error\n");<span class="Apple-tab-span" style="white-space:pre"> </span></div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>MPI_Abort(911, MPI_COMM_WORLD);</div><div> }</div><div> MPI_Comm_rank(MPI_COMM_WORLD, &rank);</div><div> MPI_Comm_size(MPI_COMM_WORLD, &size);</div>
<div> assert (size == 2);</div><div> MPI_Comm_dup(MPI_COMM_WORLD,&communicator[rank]);</div><div> </div><div> data1.comm = communicator[rank];</div><div> data1.thread = 1;</div><div> data1.rank = rank;</div><div>
pthread_create (&thread_a, NULL, (void *) &probe_recv, (void *)&data1);</div><div><br></div><div> data2.comm = communicator[rank];</div><div> data2.thread = 2;</div><div> data2.rank = rank;</div><div> pthread_create (&thread_b, NULL, (void *) &send, (void *)&data2);</div>
<div><br></div><div> pthread_join(thread_a, NULL);</div><div> pthread_join(thread_b, NULL);</div><div> MPI_Finalize();</div></div><div>}</div><div><br></div><div><br></div></div><div><br></div>