#include #include #include #include #include #include void generateData(int * data, int SIZE); int compfn (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } //Do not change the seed #define SEED 72 #define MAXVAL 1000000 //Total input size is N, divided by nprocs //Doesn't matter if N doesn't evenly divide nprocs #define N 1000000000 int main(int argc, char **argv) { int my_rank, nprocs; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&my_rank); MPI_Comm_size(MPI_COMM_WORLD,&nprocs); //seed rng do not modify srand(SEED+my_rank); //local input size N/nprocs const unsigned int localN=N/nprocs; //All ranks generate data int * data=(int*)malloc(sizeof(int)*localN); generateData(data, localN); int * sendDataSetBuffer=(int*)malloc(sizeof(int)*localN); //most that can be sent is localN elements int * recvDatasetBuffer=(int*)malloc(sizeof(int)*localN); //most that can be received is localN elements int * myDataSet=(int*)malloc(sizeof(int)*N); //upper bound size is N elements for the rank //Write code here //free free(data); free(sendDataSetBuffer); free(recvDatasetBuffer); free(myDataSet); MPI_Finalize(); return 0; } //generates data [0,MAXVAL) void generateData(int * data, int SIZE) { for (int i=0; i