#include // printf #include // EXIT_SUCCESS #include #include "prng_shared.h" int main(int argc, char* argv[]) { int seed; int N; int i; int number_of_workers; int N_per_worker; int my_process_id; double *seq; double *my_seq; // initialize MPI sybsystem MPI_Init(&argc,&argv); // get number of available processes, and a unique id for this process MPI_Comm_rank(MPI_COMM_WORLD, &my_process_id); MPI_Comm_size(MPI_COMM_WORLD, &number_of_workers); // get parameters from command line arguments read_arguments(&seed, &N, argc, argv); // get number of workers and this workers id MPI_Comm_rank(MPI_COMM_WORLD, &my_process_id); MPI_Comm_size(MPI_COMM_WORLD, &number_of_workers); // exit if work cannot be divided equally among workers if ( (N % number_of_workers) != 0 ) { printf("Cannot equally divide %d numbers by %d workers \n", N, number_of_workers); exit(EXIT_FAILURE); } // calculate numbers to be generated by each process N_per_worker = N / number_of_workers; // allocate and array to hold N_per_worker random numbers my_seq = malloc(N_per_worker * sizeof(double)); // exit if allocation fails if (my_seq == NULL) { printf("Cannot allocate space for %d numbers\n", N_per_worker); exit(EXIT_FAILURE); } // adjust seed so that each process creates a different number sequence seed = seed + my_process_id; // generate N_per_worker random numbers and save them in the array // please remember that each process will have its own memory context for (i=0; i