int testcheckpoint(PV_Init * initObj, int rank) { PV_Arguments * arguments = initObj->getArguments(); arguments->resetState(); // Make sure either restartFlag or checkpointReadDir are set (both cannot be set or PV_Arguments will error out). bool hasrestart = (arguments->getRestartFlag() || arguments->getCheckpointReadDir()!=NULL); if (!hasrestart) { if (rank==0) { fprintf(stderr, "%s error: --testcheckpoint requires either the -r or the -c option.\n", arguments->getProgramName()); } MPI_Barrier(MPI_COMM_WORLD); exit(EXIT_FAILURE); } if (rank==0) { printf("%s --testcheckpoint running PetaVision with arguments\n", arguments->getProgramName()); arguments->printState(); } int status = rebuildandrun(initObj, NULL, &assertAllZeroes, NULL, 0); return status; }
int main(int argc, char * argv[]) { int rank = 0; PV_Init * initObj = new PV_Init(&argc, &argv, false/*allowUnrecognizedArguments*/); MPI_Comm_rank(MPI_COMM_WORLD, &rank); char const * paramFile1 = "input/CheckpointParameters1.params"; char const * paramFile2 = "input/CheckpointParameters2.params"; int status = PV_SUCCESS; PV_Arguments * arguments = initObj->getArguments(); if (arguments->getParamsFile()!=NULL) { if (rank==0) { fprintf(stderr, "%s should be run without the params file argument.\n", arguments->getProgramName()); } status = PV_FAILURE; } if (arguments->getCheckpointReadDir()!=NULL) { if (rank==0) { fprintf(stderr, "%s should be run without the checkpoint directory argument.\n", argv[0]); } status = PV_FAILURE; } if (arguments->getRestartFlag()) { if (rank==0) { fprintf(stderr, "%s should be run without the restart flag.\n", argv[0]); } status = PV_FAILURE; } if (status != PV_SUCCESS) { if (rank==0) { fprintf(stderr, "This test uses two hard-coded params files, %s and %s. The second run is started from a checkpoint from the first run, and the results of the two runs are compared.\n", paramFile1, paramFile2); } MPI_Barrier(MPI_COMM_WORLD); exit(EXIT_FAILURE); } if (rank==0) { char const * rmcommand = "rm -rf checkpoints1 checkpoints2 output"; status = system(rmcommand); if (status != 0) { fprintf(stderr, "deleting old checkpoints and output directories failed: \"%s\" returned %d\n", rmcommand, status); exit(EXIT_FAILURE); } } ParamGroupHandler * customGroupHandler = new CustomGroupHandler; arguments->setParamsFile(paramFile1); arguments->setBatchWidth(2); status = rebuildandrun(initObj, NULL, NULL, &customGroupHandler, 1); if( status != PV_SUCCESS ) { fprintf(stderr, "%s: rank %d running with params file %s returned error %d.\n", arguments->getProgramName(), rank, paramFile1, status); exit(status); } arguments->setParamsFile(paramFile2); arguments->setCheckpointReadDir("checkpoints1/batchsweep_00/Checkpoint12:checkpoints1/batchsweep_01/Checkpoint12"); status = rebuildandrun(initObj, NULL, &customexit, &customGroupHandler, 1); if( status != PV_SUCCESS ) { fprintf(stderr, "%s: rank %d running with params file %s returned error %d.\n", arguments->getProgramName(), rank, paramFile2, status); } delete customGroupHandler; delete initObj; return status==PV_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE; }