I use the version 1.4.1 and adding the pthread.h did make it work<div><br></div><div><div><div>Thanks</div><div>Ramesh</div><div><br></div><div><br></div><div class="gmail_quote">On Tue, Jun 26, 2012 at 7:49 AM, Darius Buntinas <span dir="ltr"><<a href="mailto:buntinas@mcs.anl.gov" target="_blank">buntinas@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">What's the output you see?<br>
<span><font color="#888888"><br>
-d<br>
</font></span><div><br>
On Jun 25, 2012, at 10:31 PM, Ramesh Vinayagam wrote:<br>
<br>
</div><div><div>> It hangs at the pthread join of the second process, which did not make sense because its the same way I use for the first process, also I use different communicators for communication.<br>
><br>
><br>
> Thanks<br>
><br>
><br>
> On Mon, Jun 25, 2012 at 5:50 PM, Darius Buntinas <<a href="mailto:buntinas@mcs.anl.gov" target="_blank">buntinas@mcs.anl.gov</a>> wrote:<br>
> I didn't test your program, but I didn't see any obvious problems. MPICH does support using threads in the way you described. What is the output you get? Where does it hang?<br>
><br>
> -d<br>
><br>
><br>
> On Jun 25, 2012, at 5:58 PM, Ramesh Vinayagam wrote:<br>
><br>
> > Hello,<br>
> ><br>
> ><br>
> > I having a question regarding the usage of MPI_THREAD_MULTIPLE.<br>
> ><br>
> > I was wondering whether this scenario works with MPI<br>
> ><br>
> > Process 0<br>
> > Thread 1 -> probes and receives<br>
> > Thread 2 -> Sends to process 0<br>
> ><br>
> > Process 1<br>
> ><br>
> > Thread 1 -> probes and receives<br>
> > Thread 2 -> Sends to process 1<br>
> ><br>
> > 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?<br>
> ><br>
> ><br>
> > Here is the code.. This code hangs when I use it with two processes. It works with one process.<br>
> ><br>
> > Thanks<br>
> > Ramesh<br>
> > ____________________________________________________________________________________________________________________________________________________<br>
> > #include <stdio.h><br>
> > #include <stdlib.h><br>
> > #include <mpi.h><br>
> > #include <string.h><br>
> > #include <assert.h><br>
> ><br>
> > typedef struct<br>
> > {<br>
> > int thread;<br>
> > MPI_Comm comm;<br>
> > int rank;<br>
> > } thdata;<br>
> ><br>
> > void probe_recv (void *ptr){<br>
> > thdata *data;<br>
> > data = (thdata *) ptr;<br>
> > int count, flag = 0;<br>
> > MPI_Status status;<br>
> > char buf[256];<br>
> ><br>
> > printf("%d :Thread :%d Prbes and receives \n", data->rank, data->thread);<br>
> > while (!flag){<br>
> > MPI_Iprobe(data->rank, 0, data->comm, &flag, &status);<br>
> > }<br>
> > MPI_Get_count( &status, MPI_CHAR, &count);<br>
> > printf("%d :Thread :%d count : %d \n", data->rank, data->thread, count);<br>
> ><br>
> > MPI_Recv( &buf,<br>
> > count,<br>
> > MPI_CHAR,<br>
> > data->rank,<br>
> > status.MPI_TAG,<br>
> > data->comm,<br>
> > MPI_STATUS_IGNORE);<br>
> ><br>
> > printf("%d Message : %s \n", data->rank,buf);<br>
> > }<br>
> ><br>
> > void send(void *ptr){<br>
> > thdata *data;<br>
> > char buffer[256];<br>
> > data = (thdata *) ptr;<br>
> > printf("%d: Thread :%d Sends \n", data->rank, data->thread);<br>
> > strcpy(buffer,"Hello World");<br>
> > MPI_Send(&buffer,256, MPI_CHAR, data->rank, 0, data->comm);<br>
> > printf("%d: Thread :%d send completed \n",<br>
> > data->rank,<br>
> > data->thread);<br>
> > }<br>
> ><br>
> ><br>
> > int main(int argc, char *argv[]){<br>
> ><br>
> > int provided, i[2], rank, size;<br>
> > MPI_Status status;<br>
> > pthread_t thread_a, thread_b;<br>
> > MPI_Comm communicator[2];<br>
> > thdata data1, data2;<br>
> ><br>
> > MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);<br>
> ><br>
> > if (provided != MPI_THREAD_MULTIPLE){<br>
> > printf("Error\n");<br>
> > MPI_Abort(911, MPI_COMM_WORLD);<br>
> > }<br>
> > MPI_Comm_rank(MPI_COMM_WORLD, &rank);<br>
> > MPI_Comm_size(MPI_COMM_WORLD, &size);<br>
> > assert (size == 2);<br>
> > MPI_Comm_dup(MPI_COMM_WORLD,&communicator[rank]);<br>
> ><br>
> > data1.comm = communicator[rank];<br>
> > data1.thread = 1;<br>
> > data1.rank = rank;<br>
> > pthread_create (&thread_a, NULL, (void *) &probe_recv, (void *)&data1);<br>
> ><br>
> > data2.comm = communicator[rank];<br>
> > data2.thread = 2;<br>
> > data2.rank = rank;<br>
> > pthread_create (&thread_b, NULL, (void *) &send, (void *)&data2);<br>
> ><br>
> > pthread_join(thread_a, NULL);<br>
> > pthread_join(thread_b, NULL);<br>
> > MPI_Finalize();<br>
> > }<br>
> ><br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > mpich-discuss mailing list <a href="mailto:mpich-discuss@mcs.anl.gov" target="_blank">mpich-discuss@mcs.anl.gov</a><br>
> > To manage subscription options or unsubscribe:<br>
> > <a href="https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss" target="_blank">https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss</a><br>
><br>
> _______________________________________________<br>
> mpich-discuss mailing list <a href="mailto:mpich-discuss@mcs.anl.gov" target="_blank">mpich-discuss@mcs.anl.gov</a><br>
> To manage subscription options or unsubscribe:<br>
> <a href="https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss" target="_blank">https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss</a><br>
><br>
> _______________________________________________<br>
> mpich-discuss mailing list <a href="mailto:mpich-discuss@mcs.anl.gov" target="_blank">mpich-discuss@mcs.anl.gov</a><br>
> To manage subscription options or unsubscribe:<br>
> <a href="https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss" target="_blank">https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss</a><br>
<br>
_______________________________________________<br>
mpich-discuss mailing list <a href="mailto:mpich-discuss@mcs.anl.gov" target="_blank">mpich-discuss@mcs.anl.gov</a><br>
To manage subscription options or unsubscribe:<br>
<a href="https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss" target="_blank">https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss</a><br>
</div></div></blockquote></div><br></div>
</div>