#include #include #include "mpi.h" #define NELTS 50000 /* number of elements in the vector */ #define MASTER 0 /* id of the first process */ #define MAXPROCS 1024 /* maximum number of processes */ main(int argc, char **argv) { double v[NELTS], /* the vector to be summed */ sum, /* the overall vector sum */ ptSums[MAXPROCS]; /* partial sums received from slaves */ int numProcs, /* number of processes in virtual machine */ rank, /* our rank */ i, /* simple counter */ count; /* the number of elements in a partition */ /******** master and slaves *********/ // initialize MPI, etc. MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &numProcs); // compute partition size count = NELTS/numProcs; /********* master process ***********/ if (rank == MASTER) { // Initialize the vector for (i=0; i