[mpich-discuss] Question reg usage with MPI_THREAD_MULTIPLE

Darius Buntinas buntinas at mcs.anl.gov
Mon Jun 25 19:50:28 CDT 2012


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?

-d


On Jun 25, 2012, at 5:58 PM, Ramesh Vinayagam wrote:

> Hello,
> 
> 
> I having a question regarding the usage of MPI_THREAD_MULTIPLE.
> 
> I was wondering whether this scenario works with MPI
> 
> Process 0
> Thread 1 -> probes and receives
> Thread 2 -> Sends to  process 0
> 
> Process 1
> 
> Thread 1 -> probes and receives
> Thread 2 -> Sends to  process 1
> 
> 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?
> 
> 
> Here is the code.. This code hangs when I use it with two processes. It works with one process. 
> 
> Thanks
> Ramesh
> ____________________________________________________________________________________________________________________________________________________
> #include <stdio.h>
> #include <stdlib.h>
> #include <mpi.h>
> #include <string.h>
> #include <assert.h>
> 
> typedef struct
> {
>   int thread;
>   MPI_Comm comm;
>   int rank;
> } thdata;
> 
> void probe_recv (void *ptr){
>   thdata *data;
>   data = (thdata *) ptr;
>   int count, flag = 0;
>   MPI_Status status;
>   char buf[256];
>   
>   printf("%d :Thread :%d Prbes and receives \n", data->rank, data->thread);
>   while (!flag){
>     MPI_Iprobe(data->rank, 0, data->comm, &flag, &status);
>   }
>   MPI_Get_count( &status, MPI_CHAR, &count);
>   printf("%d :Thread :%d count : %d \n", data->rank, data->thread, count);
> 
>   MPI_Recv( &buf, 
> 	    count, 
> 	    MPI_CHAR, 
> 	    data->rank, 
> 	    status.MPI_TAG, 
> 	    data->comm, 
> 	    MPI_STATUS_IGNORE);
>   
>   printf("%d Message : %s \n", data->rank,buf);
> }
> 
> void send(void *ptr){
>   thdata *data;
>   char buffer[256];
>   data = (thdata *) ptr;
>   printf("%d: Thread :%d Sends \n", data->rank, data->thread);
>   strcpy(buffer,"Hello World");
>   MPI_Send(&buffer,256, MPI_CHAR, data->rank, 0, data->comm);
>   printf("%d: Thread :%d send completed \n",
> 	 data->rank,
> 	 data->thread);
> }
> 
> 
> int main(int argc, char *argv[]){
> 
>   int provided, i[2], rank, size;
>   MPI_Status  status;
>   pthread_t thread_a, thread_b;
>   MPI_Comm communicator[2];
>   thdata data1, data2;
> 
>   MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);  	
> 
>   if (provided != MPI_THREAD_MULTIPLE){
> 	printf("Error\n");	
> 	MPI_Abort(911, MPI_COMM_WORLD);
>   }
>   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
>   MPI_Comm_size(MPI_COMM_WORLD, &size);
>   assert (size == 2);
>   MPI_Comm_dup(MPI_COMM_WORLD,&communicator[rank]);
>  
>   data1.comm = communicator[rank];
>   data1.thread = 1;
>   data1.rank = rank;
>   pthread_create (&thread_a, NULL, (void *) &probe_recv, (void *)&data1);
> 
>   data2.comm = communicator[rank];
>   data2.thread = 2;
>   data2.rank = rank;
>   pthread_create (&thread_b, NULL, (void *) &send, (void *)&data2);
> 
>   pthread_join(thread_a, NULL);
>   pthread_join(thread_b, NULL);
>   MPI_Finalize();
> }
> 
> 
> 
> _______________________________________________
> mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
> To manage subscription options or unsubscribe:
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss



More information about the mpich-discuss mailing list