This is the example code:
#include <mpi.h>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int size, rank;
const int root = 0;
int datasize = atoi(argv[1]);
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int nodeDest = rank + 1;
if (nodeDest > size - 1) {
nodeDest = 0;
}
int nodeFrom = rank - 1;
if (nodeFrom < 0) {
nodeFrom = size - 1;
}
MPI_Status status;
MPI_Request req[2];
int *data = new int[datasize];
int *data2 = new int[datasize];
for (int i = 0; i < datasize; i++) data[i] = rank;
cout << "Before send" << endl;
MPI_Isend(data, datasize, MPI_INT, nodeDest, 0, MPI_COMM_WORLD, &req[0]);
delete[] data;
cout << "After send" << endl;
MPI_Recv(data2, datasize, MPI_INT, nodeFrom, 0, MPI_COMM_WORLD,&status);
cout << "After Irecv" << endl;
MPI_Wait(&req[0], MPI_STATUS_IGNORE);
cout << "After wait" << endl;
delete[] data2;
MPI_Finalize();
return 0;
}
I use mpich-4.1.2 and intel mpi(oneAPI 2020). When the buffer size is small, both are ok.
mpirun -np 4 ./test 100
/opt/intel/compilers_and_libraries_2020.0.139/linux/mpi/intel64/bin/mpirun -np 4 ./test 100
But when the buffer size is huge, mpich got EXIT CODE: 9
mpirun -np 4 ./test 100000
Before send
Before send
After send
Before sendBefore send
After send
After send
After send
===================================================================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= PID 321877 RUNNING AT
= EXIT CODE: 9
= CLEANING UP REMAINING PROCESSES
= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
===================================================================================
YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)
This typically refers to a problem with your application.
Please see the FAQ page for debugging suggestions
I know what caused this problem is line delete[] data;
, but not clear about the details behind it.