问题
The man page for Open MPI's implementation of MPI_Rsend states that
A ready send may only be called if the user can guarantee that a receive is already posted. It is an error if the receive is not posted before the ready send is called.
I'm trying to write a small program to see how this error would manifest itself (I thought it would be a runtime error followed by abort), but this program works perfectly:
#include <assert.h>
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h> /* malloc */
#include <unistd.h> /* sleep */
int main(int argc, char** argv) {
MPI_Init(NULL, NULL);
int my_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
const int ARRAY_SIZE = 100000;
int* array = (int*)malloc(sizeof(int) * ARRAY_SIZE);
assert(array != NULL);
if (my_rank == 0) {
// Populate array with something.
for (int i = 0; i < ARRAY_SIZE; ++i) { array[i] = i; }
int error_val;
printf("[%d] Called Rsend\n", my_rank);
error_val = MPI_Rsend(array, ARRAY_SIZE, MPI_INT, 1, 0, MPI_COMM_WORLD);
printf("[%d] Done with success? %d\n", my_rank, error_val == MPI_SUCCESS);
}
else {
sleep(5);
MPI_Recv(array, ARRAY_SIZE, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("[%d] Last element of array is: %d\n", my_rank,
array[ARRAY_SIZE -1 ]);
}
MPI_Finalize();
return 0;
}
Output is:
$ mpicc -o mpi_rsend_example mpi_rsend_example.c
$ mpiexec -n 2 ./mpi_rsend_example
[0] Called Rsend
[0] Done with success? 1
[1] Last element of array is: 99999
Shouldn't there be an error, since the MPI_Recv
call certainly happens after the MPI_Rsend
call? (I'm running the program locally, so both ranks run on my computer).
来源:https://stackoverflow.com/questions/34223226/mpi-rsend-not-raising-error-when-it-should