#include #include #include #include #include #include //Example compilation //mpicc scatter_starter.c -lm -o scatter_starter //Example execution //mpirun -np 1 -hostfile myhostfile.txt ./scatter_starter 10000 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); //Process command-line arguments unsigned int N; if (argc != 2) { if (my_rank==0) fprintf(stderr,"Please provide the following on the command line: N (total size of array)\n"); MPI_Finalize(); exit(0); } sscanf(argv[1],"%d",&N); if (N%nprocs!=0) { if (my_rank==0) fprintf(stderr,"Please enter a new value of N. N mod p !=0\n"); MPI_Finalize(); exit(0); } //Global array (rank 0 allocates this) unsigned int * data; //Local array for the rank unsigned int * localData=(unsigned int *)malloc(sizeof(unsigned int)*(N/nprocs)); if (my_rank==0) { data=(unsigned int *)malloc(sizeof(unsigned int)*N); //generate data on rank 0 for (int i=0; i