/* paralleladder.c */ /* © Copyright 2003 Dauger Research, Inc. Our lawyers made us say this: DISCLAIMER: We provide the following on an "AS IS" basis. Use it at your own risk. */ #include /* standard I/O routines */ #include /* standard library routines, such as memory */ #include /* math libraries */ #include "mpi.h" /* MPI library */ /* A routine performing elemental work. This can be replaced with a much larger routine. */ double kernelroutine(double input); double kernelroutine(double input) { return (input+1)*(input+1); } /* HighestIndex specifies how highest index to sample */ #define HighestIndex 10000L void computeloop(double *theSum, double **theArray, int idproc, int nproc); void computeloop(double *theSum, double **theArray, int idproc, int nproc) { /* local copies of the data to be output */ double *myArray, mySum=0; /* limit of the loop */ long loopEnd=(HighestIndex+nproc-1)/nproc; /* just this proc's piece */ /* this processor's index offset */ long offset=idproc*loopEnd; /* allocate an array to hold all the results */ myArray=malloc(sizeof(double)*loopEnd); if (myArray) { long index; /* loop over indicies */ for(index=0; index #endif int ppinit(int argc, char *argv[], int *idproc, int *nproc) { /* this subroutine initializes parallel processing idproc = processor id nproc = number of real or virtual processors obtained */ int ierr; *nproc=0; /* initialize the MPI execution environment */ ierr = MPI_Init(&argc, &argv); if (!ierr) { /* determine the rank of the calling process in the communicator */ ierr = MPI_Comm_rank(MPI_COMM_WORLD, idproc); /* determine the size of the group associated with a communicator */ ierr = MPI_Comm_size(MPI_COMM_WORLD, nproc); #ifdef __MWERKS__ /* only for Metrowerks CodeWarrior */ SIOUXSettings.asktosaveonclose=0; SIOUXSettings.autocloseonquit=1; #endif } return ierr; } void ppexit(void) { /* this subroutine terminates parallel processing */ int ierr; /* terminate MPI execution environment */ ierr = MPI_Finalize(); }