Exemplo n.º 1
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;
}
Exemplo 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;

    #ifdef NBODY_BLENDER_OUTPUT
        mkdir("./frames", S_IRWXU | S_IRWXG);
        deleteOldFiles(st);
        mwvector startCmPos;
        mwvector perpendicularCmPos;
        mwvector nextCmPos;
        nbFindCenterOfMass(&startCmPos, st);
        perpendicularCmPos=startCmPos;
        printf("Total frames: %d\n", (int)(ctx->nStep));
    #endif

    while (st->step < ctx->nStep)
    {
        #ifdef NBODY_BLENDER_OUTPUT
            nbFindCenterOfMass(&nextCmPos, st);
            blenderPossiblyChangePerpendicularCmPos(&nextCmPos,&perpendicularCmPos,&startCmPos);
        #endif
        rc |= nbStepSystemPlain(ctx, st);
        if (nbStatusIsFatal(rc))   /* advance N-body system */
            return rc;

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

        /* We report the progress at step + 1. 0 is the original
           center of mass. */
        nbReportProgress(ctx, st);
        nbUpdateDisplayedBodies(ctx, st);
    }
    
    #ifdef NBODY_BLENDER_OUTPUT
        blenderPrintMisc(st, ctx, startCmPos, perpendicularCmPos);
    #endif

    return nbWriteFinalCheckpoint(ctx, st);
}
Exemplo n.º 3
0
/* Maximum exit code is 255 which ruins everything even though we want
 * to have or'able errors. */
static int nbStatusToRC(NBodyStatus rc)
{
    unsigned int n = (unsigned int) rc;
    unsigned int shift = 0;

    if (rc == NBODY_SUCCESS || (nbStatusIsWarning(rc) && !nbStatusIsFatal(rc)))
    {
        return 0;
    }

    while (n >> shift)
    {
        ++shift;
    }

    return (int) shift - 1;
}
Exemplo n.º 4
0
NBodyStatus nbGravMap(const NBodyCtx* ctx, NBodyState* st)
{
    NBodyStatus rc;

    if (mw_likely(ctx->criterion != Exact))
    {
        rc = makeTree(ctx, st);
        if (nbStatusIsFatal(rc))
            return rc;

        nbMapForceBody(ctx, st);
    }
    else
    {
        nbMapForceBody_Exact(ctx, st);
    }

    if (st->potentialEvalError)
    {
        return NBODY_LUA_POTENTIAL_ERROR;
    }

    return nbIncestStatusCheck(ctx, st); /* Check if incest occured during step */
}
Exemplo n.º 5
0
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;
}