void initialize() { bool ok = true; int i; if (MPIRank == 0) { ok = X11_Init(); } if (!ok) { MPI_Finalize(); exit(EXIT_FAILURE); } distributeWork(); if (MPIRank != 0) { srandom(RandomSeed * MPISize + MPIRank); if (MPIRank == 1) { ParticleXs[0] = ENVIRONMENT_WIDTH / 2 - 1; ParticleYs[0] = ENVIRONMENT_WIDTH / 2 - 1; ParticleStates[0] = STUCK; i = 1; } else { i = ParticleDispls[MPIRank]; } for (; i < ParticleDispls[MPIRank] + ParticleCounts[MPIRank]; i++) { ParticleXs[i] = ENVIRONMENT_WIDTH * random() / RAND_MAX; ParticleYs[i] = ENVIRONMENT_HEIGHT * random() / RAND_MAX; ParticleStates[i] = FREE; } } }
/************************ * FUNCTION DEFINITIONS * ************************/ int main(int argc, char **argv) { int numRects = 10; double area = 0.0; int myRank = 0; int numProcs = 1; int myNumRects = 0; int myDispl = 0; setupMPI(&argc, &argv, &myRank, &numProcs); getUserOptions(argc, argv, &numRects); distributeWork(numRects, myRank, numProcs, &myNumRects, &myDispl); calculateArea(numRects, myNumRects, (1.0 / numRects), myDispl, &area); syncData(myRank, numProcs, &area); if (myRank == 0) { calculateAndPrintPi(area); } MPI_Finalize(); return 0; }