コード例 #1
0
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;
}
コード例 #2
0
static void calculateIntegralsIntFp(const AstronomyParameters* ap,
                               const IntegralArea* ias,
                               const StreamConstantsIntFp* sc,
                               const StreamGauss sg,
                               EvaluationState* es,
                               const CLRequest* clr,
                               GPUInfo* ci,
                               int useImages)
{
    const IntegralArea* ia;
    double t1, t2;
    int rc;
    
  #if SEPARATION_CAL
    if (separationLoadKernel(ci, ap, sc) != CAL_RESULT_OK)
        fail("Failed to load integral kernel");
  #endif /* SEPARATION_OPENCL */
        
    for (; es->currentCut < es->numberCuts; es->currentCut++)
    {
        es->cut = &es->cuts[es->currentCut];
        ia = &ias[es->currentCut];
        es->current_calc_probs = completedIntegralProgress(ias, es);

        t1 = mwGetTime();
      #if SEPARATION_OPENCL
        rc = integrateCL(ap, ia, sc, sg, es, clr, ci, (cl_bool) useImages);
      #elif SEPARATION_CAL
        rc = integrateCAL(ap, ia, sg, es, clr, ci);
      #else
        rc = integrateIntFp(ap, ia, sc, sg, es, clr);
      #endif /* SEPARATION_OPENCL */

        t2 = mwGetTime();
        warn("Integral %u time = %f s\n", es->currentCut, t2 - t1);

        if (rc || isnan(es->cut->bgIntegral))
            fail("Failed to calculate integral %u\n", es->currentCut);

        cleanStreamIntegralsIntFp(es->cut->streamIntegrals, sc, ap->number_streams);
        clearEvaluationStateTmpSums(es);
    }

  #if SEPARATION_CAL
    mwUnloadKernel(ci);
  #endif /* SEPARATION_CAL */
}
コード例 #3
0
/* Pretty much boinc_rename() mangled a bit to fit here temporarily */
static int mw_boinc_rename(const char* old, const char* newf)
{
    int retval;
    const double fileRetryInterval = 5;

    retval = mw_boinc_rename_aux(old, newf);
    if (retval)
    {
        double start = mwGetTime();
        do
        {
            mw_boinc_sleep(2.0 * (double) rand() / (double) RAND_MAX);
            retval = mw_boinc_rename_aux(old, newf);
            if (!retval)
                break;
        }
        while (mwGetTime() < start + fileRetryInterval);
    }

    return retval;
}
コード例 #4
0
double mwGetTimeMilli(void)
{
    return 1.0e3 * mwGetTime();
}
コード例 #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;
}