I just recently learned that MPI_Send cannot send too long data at a time, so I decided to divide the data into pieces and send them in a for loop. Below is a test case. The problem here is that if I use a small amount of data and divide it into pieces, the program will run; However, when the data is long, no matter how many pieces I divide it into, the program just won't run. When I run it, I just heard my computer makes big noise. So I wonder what is the cause and how can i make MPI_Send to send a large data set to other processors. Thank you!
#include<iostream>
#include<mpi.h>
#include<vector>
using namespace std;
//This set of N and N+Parts won't work
#define N 1024*1024*5
#define N_PARTS 1000
//This works
#define N 1024*5
#define N_PARTS 10
#define MASTER 0
int main(int argc, char** argv)
{
int np, pid;
vector<int> arr;
for(int i=0; i<N; ++i) arr.push_back(i);
int LENGTH = N/N_PARTS;
int N_RES = N%N_PARTS;
// cout << LENGTH << endl;
// cout << N_RES << endl;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &np);
MPI_Comm_rank(MPI_COMM_WORLD, &pid);
for(int i=0; i< N_PARTS-1; ++i){
MPI_Send(&arr[0]+i*LENGTH,LENGTH,MPI_INT,MASTER,0,MPI_COMM_WORLD);
}
MPI_Send(&arr[0]+LENGTH*(N_PARTS-1),N_RES,MPI_INT,MASTER,0,MPI_COMM_WORLD);
MPI_Finalize();
}