#include <stdio.h>#include <stdarg.h>#include <time.h>/* get definition of MPI constants */#include "mpi.h"/* get definition of MP constants */#include "MacMP.h"#define NINT 1000000000void adder(int *, int *, double *, double *);int main (int argc, char *argv[])/* This program calculates the variance of the first 10^9 integers     *//* using MPI with multiple Macintoshes.                                 */{int n, n1, n2, start1, start2;clock_t start_program, end_program;double sum11, sum12, sum21, sum22, mean, mesq;int ierror, nproc, idproc, root=0, idtask, nargs=4;double partial[2], result[2];typedef void (*aProcPtr)(...);/* initialize the MPI environment */ierror = MPI_Init(&argc, &argv);ierror = MPI_Comm_size(MPI_COMM_WORLD,&nproc);ierror = MPI_Comm_rank(MPI_COMM_WORLD,&idproc);start_program = clock ();/* set arguments for each node, last node might have more work */n = NINT / nproc;start1 = n * idproc;n1 = n + start1;if (idproc == (nproc-1))   n1 = NINT;/* initialize the MP environment */MP_Init(&nproc);/* set arguments for each task */n = n/2;n2 = n1;n1 -= n;start2 = start1 + n;MP_Taskstart(&idtask,(aProcPtr)&adder,&nargs,&n2,&start2,&sum21,&sum22);adder (&n1, &start1, &sum11, &sum12);MP_Taskwait(&idtask);/* terminate the MP environment */MP_End();/* add up all the partial sums from each node */partial[0] = sum11 + sum21;partial[1] = sum12 + sum22;ierror = MPI_Reduce(partial,result,2,MPI_DOUBLE,MPI_SUM,root,                    MPI_COMM_WORLD);/* terminate MPI environment */ierror = MPI_Barrier(MPI_COMM_WORLD);ierror = MPI_Finalize();/* node 0 has the results */if (idproc == root) {   n = NINT;   mean = result[0] / n;   mesq = result[1] / n;   printf("%15d %20.3f %20.3f\n", n, mean, mesq - (mean * mean));}end_program = clock ();printf("\ntime in sec: %7.2f\n", (end_program-start_program)/60.);if (idproc == root) {   printf("hit carriage return to continue\n");   getchar();}return 0;}voidadder (int *n, int *start, double *s1, double *s2){int i;double ls1 = 0.0, ls2 = 0.0;for (i=(*start);i<(*n);i++)   {      ls1+=(double) i;      ls2+=(double) i*i;   }*s1 = ls1;*s2 = ls2;}