/* Try evaluating everything in the file to make sure it's OK */ int nbVerifyFile(const NBodyFlags* nbf) { NBodyCtx ctx = EMPTY_NBODYCTX; NBodyState st = EMPTY_NBODYSTATE; HistogramParams hp; if (nbSetup(&ctx, &st, nbf) || nbHistogramParamsCheck(nbf, &hp) || nbVerifyPotentialFunction(nbf, &ctx, &st)) { mw_printf("File failed\n"); destroyNBodyState(&st); return FALSE; } else { mw_printf("File is OK\n"); printNBodyCtx(&ctx); printHistogramParams(&hp); destroyNBodyState(&st); return TRUE; } }
int runNBodySimulation(const NBodyFlags* nbf) { NBodyCtx* ctx = &_ctx; NBodyState* st = &_st; int rc = 0; real chisq; double ts = 0.0, te = 0.0; nbodySetCtxFromFlags(ctx, nbf); if (setupRun(ctx, st, &ctx->histogramParams, nbf)) { return warn1("Failed to setup run\n"); } if (initOutput(st, nbf)) { return warn1("Failed to open output files\n"); } if (createSharedScene(st, ctx, nbf->inputFile)) { return warn1("Failed to create shared scene\n"); } ts = mwGetTime(); rc = runSystem(ctx, st, nbf); if (rc) return warn1("Error running system\n"); te = mwGetTime(); if (nbf->printTiming) { printf("<run_time> %f </run_time>\n", te - ts); } /* Get the likelihood */ chisq = nbodyChisq(ctx, st, nbf, &ctx->histogramParams); if (isnan(chisq)) { warn("Failed to calculate chisq\n"); rc = 1; } finalOutput(ctx, st, nbf, chisq); destroyNBodyState(st); return rc; }
int verifyFile(const NBodyFlags* nbf) { int rc; NBodyCtx ctx = EMPTY_NBODYCTX; NBodyState st = EMPTY_NBODYSTATE; rc = setupNBody(&ctx, &st, &ctx.histogramParams, nbf); if (rc) warn("File failed\n"); else { warn("File is OK\n"); printNBodyCtx(&ctx); printHistogramParams(&ctx.histogramParams); } destroyNBodyState(&st); return rc; }
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 nbMain(const NBodyFlags* nbf) { NBodyCtx* ctx = &_ctx; NBodyState* st = &_st; CLRequest clr; NBodyStatus rc = NBODY_SUCCESS; real ts = 0.0, te = 0.0; if (!nbOutputIsUseful(nbf)) { return NBODY_USER_ERROR; } nbSetCLRequestFromFlags(&clr, nbf); /* Find out what device we're using so we can tell the workunit * about it */ if (NBODY_OPENCL && !nbf->noCL) { rc = nbInitCL(st, ctx, &clr); if (nbStatusIsFatal(rc)) { destroyNBodyState(st); return rc; } } rc = nbResumeOrNewRun(ctx, st, nbf); if (nbStatusIsFatal(rc)) { destroyNBodyState(st); return rc; } nbSetCtxFromFlags(ctx, nbf); /* Do this after setup to avoid the setup clobbering the flags */ nbSetStateFromFlags(st, nbf); if (NBODY_OPENCL && !nbf->noCL) { rc = nbInitNBodyStateCL(st, ctx); if (nbStatusIsFatal(rc)) { destroyNBodyState(st); return rc; } } if (nbCreateSharedScene(st, ctx)) { mw_printf("Failed to create shared scene\n"); } if (nbf->visualizer && st->scene) { /* Make sure the first scene is available for the launched graphics */ nbForceUpdateDisplayedBodies(ctx, st); /* Launch graphics and make sure we are sure the graphics is * attached in case we are using blocking mode */ nbLaunchVisualizer(st, nbf->graphicsBin, nbf->visArgs); } if (nbf->reportProgress) { nbSetupCursesOutput(); } ts = mwGetTime(); rc = nbRunSystem(ctx, st); te = mwGetTime(); if (nbf->reportProgress) { nbCleanupCursesOutput(); } nbReportSimulationComplete(st); if (nbStatusIsFatal(rc)) { mw_printf("Error running system: %s (%d)\n", showNBodyStatus(rc), rc); destroyNBodyState(st); return rc; } else { if (nbStatusIsWarning(rc)) { mw_printf("System complete with warnings: %s (%d)\n", showNBodyStatus(rc), rc); } if (nbf->printTiming) { printf("<run_time> %f </run_time>\n", te - ts); } } rc = nbReportResults(ctx, st, nbf); destroyNBodyState(st); return rc; }