#include #include #include #define approx_val 2.19328059 #define N 10000000 /* Number of intervals in each processor */ double integrate_f(); /* Integral function */ double simpson(); main(int argc, char *argv[]) { int Procs; /* Number of processors */ int my_rank; /* Processor number */ double total; double exact_val_of_Pi, pi, y, processor_output_share[64], x1, x2, l, sum; int i; MPI_Status status; /* Let the system do what it needs to start up MPI */ MPI_Init(&argc, &argv); /* Added this to check processors */ char name[1024]; int len; MPI_Get_processor_name(name, &len); printf("Processor %s checking in\n",name); /* Original program starts again */ /* Get my process rank */ MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /* Find out how many processes are being used. */ MPI_Comm_size(MPI_COMM_WORLD, &Procs); /* Each processor computes its interval */ x1 = ((double) my_rank)/((double) Procs); x2 = ((double) (my_rank + 1))/((double) Procs); /* l is the same for all processes. */ l = 1.0/((double) (2 * N * Procs)); int iloop,loopsize=10; for(iloop=0;iloop