/*-------------------------------------------------------------------------- * method: initmpi * Scope: Global (called from patched main) * Purpose: Initialize mpi * * Notes: This method is the first thing called in Pymain, the reasons for this * are as follows. * * 1) MPI_Init has issues if it is not called right away, before any file * descriptors are modified in the process * 2) MPI_Init usually cleans up the argument list which tends to trip up * the getopt() loop in patchedmain.c on some systems * * Therefore, this method gets called BEFORE python actually gets intialized, * hence we cannot use any python calls within it. * ---------------------------------------------------------------------------*/ void initmpi(int* argc,char*** argv) { int MPIisReady; int myRank = 0; /* ----------------------------------------------- */ /* Assemble the argc and argv arrays */ /* and initialize MPI (if not already done) */ /* I have a stub here for alternate startup */ /* We use PETSC which must initialize MPI */ /* ----------------------------------------------- */ PyAlternateMPIStartup(&initializeMPI,&PyMPI_finalizeMPI); if ( MPI_Initialized(&MPIisReady) != MPI_SUCCESS ) { fprintf(stderr,"MPI Failure, MPI_Initialized()\n"); exit(1); } if(MPIisReady) { printf("pyMPI: MPI already initialized, continuing\n"); }else{ /* call MPI_Init or alternate Startup function here! */ /* (rwh) Have VTK do MPI_Init and init global controller ... */ if ( !vtkSetup(argc, argv) ) { if(initializeMPI(argc,argv) != MPI_SUCCESS) { fprintf(stderr,"MPI Failure, MPI_Init()\n"); exit(1); } } } MPI_Comm_rank( MPI_COMM_WORLD, &myRank ); }
int main(int argc, char** argv) { int problemToSolve = 2; int initializationValue = 1; int numberOfAlterations = 5; initializeMPI(); if (argc >= 4) { problemToSolve = atoi (argv[1]); initializationValue = atoi (argv[2]); numberOfAlterations = atoi (argv[3]); } else if (procRank == 0) { printf("No valid arguments, default values used.\n\n"); } struct timespec begin = {0,0}, end = {0,0}; clock_gettime(CLOCK_REALTIME, &begin); if (problemToSolve == 1) solveProblem1(numberOfAlterations, initializationValue); else if (problemToSolve == 2) solveProblem2(numberOfAlterations, initializationValue); clock_gettime(CLOCK_REALTIME, &end); if (procRank == 0) printf ("\nExecution time: %.0f ms\n", (((double)end.tv_sec + 1.0e-9*end.tv_nsec) - ((double)begin.tv_sec + 1.0e-9*begin.tv_nsec)) * 1000.0); finalizeMPI(); return 0; }