MPI - Printing in an order

后端 未结 5 1288
臣服心动
臣服心动 2020-12-03 20:12

I\'m trying to write a function in C where every processor prints it\'s own data. Here is what i have:

void print_mesh(int p,int myid,int** U0,int X,int Y){
         


        
5条回答
  •  星月不相逢
    2020-12-03 20:34

    There is no way to guarantee that messages from many different processes will arrive in the "correct" order when they arrive to another process. This is essentially what is happening here.

    Even though you aren't explicitly sending messages, when you print something to the screen, it has to be sent to the process on your local system (mpiexec or mpirun) where it can be printed to the screen. There is no way for MPI to know what the correct order for these messages is so it just prints them as they arrive.

    If you require that your messages are printed in a specific order, you must send them all to one rank which can print them in whatever order you like. As long as one rank does all of the printing, all of the messages will be ordered correctly.

    It should be said that there will probably be answers that you can find out there which say you can put a newline at the end of your string or use flush() to ensure that the buffers are flushed, but that won't guarantee ordering on the remote end for the reasons mentioned above.

提交回复
热议问题