Ejemplo n.º 1
0
/* If possible, resume from a checkpoint. Otherwise do the necessary
 * initialization for a new run */
static NBodyStatus nbResumeOrNewRun(NBodyCtx* ctx, NBodyState* st, const NBodyFlags* nbf)
{
    if (nbResolveCheckpoint(st, nbf->checkpointFileName))
    {
        mw_printf("Failed to resolve checkpoint\n");
        return NBODY_ERROR;
    }

    /* If the checkpoint exists (and we want to use it), try to use it */
    if (nbf->ignoreCheckpoint || !nbResolvedCheckpointExists(st))
    {
        if (!nbf->inputFile)
        {
            mw_printf("No input file and no checkpoint\n");
            return NBODY_USER_ERROR;
        }

        if (nbSetup(ctx, st, nbf))
        {
            mw_printf("Failed to read input parameters file\n");
            return NBODY_PARAM_FILE_ERROR;
        }
    }
    else /* Resume from checkpoint */
    {
        if (nbf->inputFile && !BOINC_APPLICATION)
        {
            mw_printf("Warning: input file '%s' unused\n", nbf->inputFile);
        }

        if (nbReadCheckpoint(ctx, st))
        {
            mw_report("Failed to read checkpoint\n");
            return NBODY_CHECKPOINT_ERROR;
        }
        else
        {
            mw_report("Resumed from checkpoint '%s'\n", nbf->checkpointFileName);
        }
    }

    if (ctx->potentialType == EXTERNAL_POTENTIAL_CUSTOM_LUA)
    {
        /* We're using a custom potential, so we'll reevaluate the
         * script. We must do this once per thread.
         */
        if (nbOpenPotentialEvalStatePerThread(st, nbf))
        {
            return NBODY_PARAM_FILE_ERROR;
        }
    }

    return NBODY_SUCCESS;
}
Ejemplo n.º 2
0
NBodyStatus nbRunSystemPlain(const NBodyCtx* ctx, NBodyState* st)
{
    NBodyStatus rc = NBODY_SUCCESS;

    rc |= nbGravMap(ctx, st); /* Calculate accelerations for 1st step this episode */
    if (nbStatusIsFatal(rc))
        return rc;

    while (st->step < ctx->nStep)
    {
        nbAddTracePoint(ctx, st);
        nbUpdateDisplayedBodies(ctx, st);
        rc |= nbStepSystemPlain(ctx, st);
        if (nbStatusIsFatal(rc))   /* advance N-body system */
            return rc;

        rc |= nbCheckpoint(ctx, st);
        if (nbStatusIsFatal(rc))
            return rc;

        nbReportProgress(ctx, st);
    }

    if (BOINC_APPLICATION || ctx->checkpointT >= 0)
    {
        mw_report("Making final checkpoint\n");
        if (nbWriteCheckpoint(ctx, st))
        {
            mw_printf("Failed to write final checkpoint\n");
            return NBODY_CHECKPOINT_ERROR;
        }
    }

    return rc;
}
static int runSystem(const NBodyCtx* ctx, NBodyState* st, const NBodyFlags* nbf)
{
    const real tstop = ctx->timeEvolve - ctx->timestep / 1024.0;

    if (nbf->visualizer)
    {
        launchVisualizer(st, nbf->visArgs);
    }

    while (st->tnow < tstop)
    {
        updateDisplayedBodies(st);

        if (stepSystem(ctx, st))   /* advance N-body system */
            return 1;

        nbodyCheckpoint(ctx, st);
    }

    if (BOINC_APPLICATION || ctx->checkpointT >= 0)
    {
        mw_report("Making final checkpoint\n");
        if (writeCheckpoint(ctx, st))
            return warn1("Failed to write final checkpoint\n");
    }

    return 0;
}
Ejemplo n.º 4
0
int main(int argc, const char* argv[])
{
    int rc;
    VisArgs flags;
    scene_t* scene = NULL;

    if (nbglBoincGraphicsInit(FALSE))
        return 1;

    if (nbglHandleVisArguments(argc, (const char**) argv, &flags))
    {
        freeVisArgs(&flags);
        return 1;
    }

    if (!flags.file)
    {
        scene = nbglConnectSharedScene(flags.instanceId);
        if (!scene)
        {
            freeVisArgs(&flags);
            return 1;
        }

        if (nbglCheckConnectedVersion(scene) || nbglGetExclusiveSceneAccess(scene))
        {
            freeVisArgs(&flags);
            return 1;
        }

        mw_report("Process %d acquired instance id %d\n", (int) getpid(), flags.instanceId);

        nbglInstallExitHandlers();
        g_scene = scene;
    }
    else
    {
        scene = nbglLoadStaticSceneFromFile(flags.file);
        if (!scene)
        {
            freeVisArgs(&flags);
            return 1;
        }
    }

    rc = nbglRunGraphics(scene, &flags);

    if (flags.file)
    {
        free(scene);
    }

    freeVisArgs(&flags);
    mw_finish(rc);

    return rc;
}
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;
}
Ejemplo n.º 6
0
static void setNumThreads(int numThreads)
{
    if (numThreads != 0)
    {
        omp_set_num_threads(numThreads);
        mw_report("Using OpenMP %d max threads on a system with %d processors\n",
                  omp_get_max_threads(),
                  omp_get_num_procs());
    }
}
int main(int argc, const char* argv[])
{
    int rc;
    SeparationFlags sf;
    SeparationPrefs preferences;
    const char** argvCopy = NULL;

  #ifdef NDEBUG
    mwDisableErrorBoxes();
  #endif /* NDEBUG */

    argvCopy = mwFixArgv(argc, argv);
    rc = parseParameters(argc, argvCopy ? argvCopy : argv, &sf);
    if (rc)
    {
        if (BOINC_APPLICATION)
        {
            freeSeparationFlags(&sf);
            mwBoincInit(MW_PLAIN);
            parseParameters(argc, argvCopy, &sf);
            printVersion(TRUE, FALSE);
        }

        mw_printf("Failed to parse parameters\n");
        free(argvCopy);
        mw_finish(EXIT_FAILURE);
    }


    rc = separationInit(sf.debugBOINC);
    free(argvCopy);
    if (rc)
        return rc;

    separationReadPreferences(&preferences);
    setFlagsFromPreferences(&sf, &preferences, argv[0]);

    if (sf.processPriority != MW_PRIORITY_INVALID)
    {
        mwSetProcessPriority(sf.processPriority);
    }

    rc = worker(&sf);

    freeSeparationFlags(&sf);

    if (!sf.ignoreCheckpoint && sf.cleanupCheckpoint && rc == 0)
    {
        mw_report("Removing checkpoint file '%s'\n", CHECKPOINT_FILE);
        mw_remove(CHECKPOINT_FILE);
    }

    mw_finish(rc);
    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 */
}
Ejemplo n.º 9
0
int main(int argc, const char* argv[])
{
    NBodyFlags nbf = EMPTY_NBODY_FLAGS;
    int rc = 0;

    specialSetup();

    if (readParameters(argc, argv, &nbf))
        exit(EXIT_FAILURE);
    free(argvCopy);

    if (nbodyInit(&nbf))
    {
        exit(EXIT_FAILURE);
    }

    nbodyPrintVersion();
    setDefaultFlags(&nbf);
    setNumThreads(nbf.numThreads);

    if (nbf.verifyOnly)
    {
        rc = verifyFile(&nbf);
    }
    else
    {
        rc = runNBodySimulation(&nbf);
        if (nbf.cleanCheckpoint)
        {
            mw_report("Removing checkpoint file '%s'\n", nbf.checkpointFileName);
            mw_remove(nbf.checkpointFileName);
        }
    }

    freeNBodyFlags(&nbf);
    mw_finish(rc);

    return rc;
}
Ejemplo n.º 10
0
int main(int argc, const char* argv[])
{
    NBodyFlags nbf;
    int rc = 0;
    const char** argvCopy = mwFixArgv(argc, argv);

    nbSpecialSetup();

    if (nbReadParameters(argc, argvCopy ? argvCopy : argv, &nbf))
    {
        if (BOINC_APPLICATION)
        {
            mwBoincInit(MW_PLAIN);
            nbReadParameters(argc, argvCopy ? argvCopy : argv, &nbf);
            nbPrintVersion(TRUE, FALSE);
        }

        mw_finish(EXIT_FAILURE);
    }

    if (nbInit(&nbf))
    {
        exit(EXIT_FAILURE);
    }

    if (BOINC_APPLICATION && mwIsFirstRun())
    {
        nbPrintVersion(TRUE, FALSE);
    }

    nbSetDefaultFlags(&nbf);
    if (nbSetNumThreads(nbf.numThreads))
    {
        mw_finish(EXIT_FAILURE);
    }

    if (nbf.verifyOnly)
    {
        rc = nbVerifyFile(&nbf);
    }
    else if (nbf.matchHistogram)
    {
        double emd;

        emd = nbMatchHistogramFiles(nbf.histogramFileName, nbf.matchHistogram);
        mw_printf("%.15f\n", emd);
        rc = isnan(emd);
    }
    else
    {
        rc = nbMain(&nbf);
        rc = nbStatusToRC(rc);

        if (!nbf.noCleanCheckpoint)
        {
            mw_report("Removing checkpoint file '%s'\n", nbf.checkpointFileName);
            mw_remove(nbf.checkpointFileName);
        }
    }

    fflush(stderr);
    fflush(stdout); /* Odd things happen with the OpenCL one where stdout starts disappearing */


    freeNBodyFlags(&nbf);

    if (BOINC_APPLICATION)
    {
        mw_finish(rc);
    }

    return rc;
}