MPI_ERR_TRUNCATE: Broadcast

I have an int I intend to translate from root ( rank==(FIELD=0) ).

 int winner if (rank == FIELD) { winner = something; } MPI_Barrier(MPI_COMM_WORLD); MPI_Bcast(&winner, 1, MPI_INT, FIELD, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); if (rank != FIELD) { cout << rank << " informed that winner is " << winner << endl; } 

But it looks like I'm getting

 [JM:6892] *** An error occurred in MPI_Bcast [JM:6892] *** on communicator MPI_COMM_WORLD [JM:6892] *** MPI_ERR_TRUNCATE: message truncated [JM:6892] *** MPI_ERRORS_ARE_FATAL: your MPI job will now abort 

Found that I can increase the buffer size in Bcast

 MPI_Bcast(&winner, NUMPROCS, MPI_INT, FIELD, MPI_COMM_WORLD); 

Where NUMPROCS is the number of running processes. (it actually seems that I just need it to be 2). Then it starts, but gives an unexpected result ...

 1 informed that winner is 103 2 informed that winner is 103 3 informed that winner is 103 5 informed that winner is 103 4 informed that winner is 103 

When I cout winner , it should be -1

+4
c ++ mpi openmpi
Nov 08
source share
1 answer

There is an error at the beginning of the code:

 if (rank == FIELD) { // randomly place ball, then broadcast to players ballPos[0] = rand() % 128; ballPos[1] = rand() % 64; MPI_Bcast(ballPos, 2, MPI_INT, FIELD, MPI_COMM_WORLD); } 

This is a very common mistake. MPI_Bcast is a collective operation, and it must be called by all processes to complete. What happens in your case is that this translation is not called by all processes in MPI_COMM_WORLD (but only by the root) and, therefore, interferes with the next translation operation, namely inside the loop. The second broadcast operation actually receives messages sent by the first (two int elements) to the buffer for only one int and, therefore, a truncation error message. In Open MPI, each broadcast uses the same message tag values ​​within itself, and therefore, different broadcasts can interfere with each other and not be displayed in sequence. This complies with the (old) MPI standard - in MPI-2.2 there can be several outstanding collective operations (in MPI-3.0 there can be several outstanding non-blocking collective operations). You should rewrite the code as:

 if (rank == FIELD) { // randomly place ball, then broadcast to players ballPos[0] = rand() % 128; ballPos[1] = rand() % 64; } MPI_Bcast(ballPos, 2, MPI_INT, FIELD, MPI_COMM_WORLD); 
+8
Nov 08
source share



All Articles