MPI program output is not in order RRS feed

  • Question

  • Hi,I am a newer in MPI programing.I find the output of the MPI program is not in order.

    The below is my test program.I build and link it in vs2010 win7.

    #include "mpi.h"
    #include <windows.h>

    int _tmain(int argc, _TCHAR* argv[])
     int processId, processNum;
        MPI_Comm_rank(MPI_COMM_WORLD, &processId); 
        MPI_Comm_size(MPI_COMM_WORLD, &processNum);

     char message[100];
     MPI_Status status; 
     if(processId!= 0) //processId 1
      sprintf(message, "Greetings from process %d!",processId);
      printf("start sending...\n");
      MPI_Send(message,strlen(message)+1, MPI_CHAR, 0,1,MPI_COMM_WORLD); 
      printf("end sending...\n");
     else //processId 0
       printf("start receiving...\n");
       MPI_Recv(message, 100, MPI_CHAR, 1, 1, MPI_COMM_WORLD,&status);
       printf("end receiving...\n");
       printf("1:%s\n", message);
     return 0;

    C:\msmpi_v8\Bin>mpiexec -n 2 1sendRecv.exe

    I think the output shall be:
    start receiving...

    start sending...

    end sending...

    end receiving...

    but it is:
    start receiving...
    end receiving...
    1:Greetings from process 1!
    start sending...
    end sending...

     And before"start receiving...”, I wait for 5 seconds,can anyone help to explain it ?


    Friday, March 17, 2017 8:29 AM

All replies

  • Hi,

    Process 0 and Process 1 both have stdout redirected to mpiexec and there's no ordering guaranteed across processes. Only output within a process is ordered (assuming single threaded application). Another issue worth mentioning is that the MPI_Send call can be buffered by the MPI implementation, so this output is also possible

    1 : Greeting from process 1!

    start sending...

    end sending ...

    start receiving...

    end receiving...

    Thursday, March 23, 2017 9:34 PM