int maybeResume(EvaluationState* es) { if (mw_file_exists(resolvedCheckpointPath)) { mw_report("Checkpoint exists. Attempting to resume from it\n"); if (readCheckpoint(es)) { mw_report("Reading checkpoint failed\n"); mw_remove(CHECKPOINT_FILE); return 1; } else mw_report("Successfully resumed checkpoint\n"); } return 0; }
static NBodyStatus setupRun(NBodyCtx* ctx, NBodyState* st, HistogramParams* hp, const NBodyFlags* nbf) { if (resolveCheckpoint(st, nbf->checkpointFileName)) { warn("Failed to resolve checkpoint\n"); return NBODY_ERROR; } /* If the checkpoint exists, try to use it */ if (nbf->ignoreCheckpoint || !resolvedCheckpointExists(st)) { if (setupNBody(ctx, st, hp, nbf)) { warn("Failed to read input parameters file\n"); return NBODY_ERROR; } } else { mw_report("Checkpoint exists. Attempting to resume from it.\n"); if (nbf->inputFile && !BOINC_APPLICATION) warn("Warning: input file '%s' unused\n", nbf->inputFile); if (readCheckpoint(ctx, st)) { mw_report("Failed to read checkpoint\n"); destroyNBodyState(st); return NBODY_CHECKPOINT_ERROR; } else { mw_report("Successfully read checkpoint\n"); } } return gravMap(ctx, st); /* Start 1st step */ }
int Simulation::start(){ // +1 to let final survey run totalSimDuration = _population->_transmissionModel->vectorInitDuration() + Global::maxAgeIntervals + Surveys.getFinalTimestep() + 1; int testCheckpointStep = -1; // declare here so goto doesn't cross initialization if (isCheckpoint()) { readCheckpoint(); } else { _population->createInitialHumans(); } // phase loop while (true) { // loop for steps within a phase while (Global::simulationTime < simPeriodEnd) { // checkpoint if (util::BoincWrapper::timeToCheckpoint() || Global::simulationTime == testCheckpointStep) { writeCheckpoint(); util::BoincWrapper::checkpointCompleted(); if (Global::simulationTime == testCheckpointStep) throw util::cmd_exit ("Checkpoint test: checkpoint written"); } // interventions if (Global::timeStep == Surveys.currentTimestep) { _population->newSurvey(); Surveys.incrementSurveyPeriod(); } _population->implementIntervention(Global::timeStep); // update ++Global::simulationTime; _population->update1(); ++Global::timeStep; util::BoincWrapper::reportProgress (double(Global::simulationTime) / totalSimDuration); } // phase transition: end of one phase to start of next if (phase == STARTING_PHASE) { simPeriodEnd = _population->_transmissionModel->vectorInitDuration(); phase = VECTOR_FITTING; } else if (phase == VECTOR_FITTING) { int extend = _population->_transmissionModel->vectorInitIterate (); if (extend > 0) { // repeat phase simPeriodEnd += extend; totalSimDuration += extend; } else { // next phase simPeriodEnd += Global::maxAgeIntervals; phase = ONE_LIFE_SPAN; } } else if (phase == ONE_LIFE_SPAN) { simPeriodEnd = totalSimDuration; Global::timeStep=0; _population->preMainSimInit(); _population->newSurvey(); // Only to reset TransmissionModel::innoculationsPerAgeGroup Surveys.incrementSurveyPeriod(); phase = MAIN_PHASE; } else if (phase == MAIN_PHASE) { phase = END_SIM; break; } testCheckpointStep = -1; if (util::CommandLine::option (util::CommandLine::TEST_CHECKPOINTING)) testCheckpointStep = Global::simulationTime + (simPeriodEnd - Global::simulationTime) / 2; } delete _population; // must destroy all Human instances to make sure they reported past events Surveys.writeSummaryArrays(); // Write scenario checksum, only if simulation completed. cksum.writeToFile (util::BoincWrapper::resolveFile ("scenario.sum")); return 0; }