static int worker(const SeparationFlags* sf) { AstronomyParameters ap; BackgroundParameters bgp = EMPTY_BACKGROUND_PARAMETERS; Streams streams = EMPTY_STREAMS; IntegralArea* ias = NULL; StreamConstants* sc = NULL; SeparationResults* results = NULL; int rc; CLRequest clr; memset(&ap, 0, sizeof(ap)); memset(&clr, 0, sizeof(clr)); setCLReqFlags(&clr, sf); ias = prepareParameters(sf, &ap, &bgp, &streams); if (!ias) return 1; rc = setAstronomyParameters(&ap, &bgp); if (rc) { mwFreeA(ias); freeStreams(&streams); return 1; } setExpStreamWeights(&ap, &streams); sc = getStreamConstants(&ap, &streams); if (!sc) { mw_printf("Failed to get stream constants\n"); mwFreeA(ias); freeStreams(&streams); return 1; } results = newSeparationResults(ap.number_streams); rc = evaluate(results, &ap, ias, &streams, sc, sf->star_points_file, &clr, sf->do_separation, sf->ignoreCheckpoint, sf->separation_outfile); if (rc) mw_printf("Failed to calculate likelihood\n"); printSeparationResults(results, ap.number_streams); mwFreeA(ias); mwFreeA(sc); freeStreams(&streams); freeSeparationResults(results); return rc; }
/* FIXME: Kill this with fire when we switch to JSON everything for separation */ static SeparationResults* freadReferenceResults(FILE* f, unsigned int nStream) { SeparationResults* r; char buf[256] = ""; unsigned int i; double tmp; r = newSeparationResults(nStream); /* Can put comments at start of this junk */ while (buf[0] == '#' || buf[0] == ' ' || !strncmp(buf, "", sizeof(buf))) fgets(buf, sizeof(buf), f); if (sscanf(buf, "likelihood: %lf\n", &tmp) != 1) goto fail_read; r->likelihood = tmp; if (fscanf(f, "background_integral: %lf\n", &tmp) != 1) goto fail_read; tmp = r->backgroundIntegral; if (fscanf(f, "background_likelihood: %lf\n", &tmp) != 1) goto fail_read; tmp = r->backgroundLikelihood; for (i = 0; i < nStream; ++i) { if (fscanf(f, "stream_integral: %lf\n", &tmp) != 1) goto fail_read; r->streamIntegrals[i] = tmp; if (fscanf(f, "stream_likelihood: %lf\n", &tmp) != 1) goto fail_read; r->streamLikelihoods[i] = tmp; } return r; fail_read: freeSeparationResults(r); return NULL; }
//Needs to loop to account for number of WUs being crunched static int worker(const SeparationFlags* sf) { AstronomyParameters ap; BackgroundParameters bgp = EMPTY_BACKGROUND_PARAMETERS; Streams streams = EMPTY_STREAMS; IntegralArea* ias = NULL; StreamConstants* sc = NULL; SeparationResults* results = NULL; int rc; CLRequest clr; memset(&ap, 0, sizeof(ap)); memset(&clr, 0, sizeof(clr)); ap.modfit = sf->modfit; if(sf->background) { ap.background_profile = BROKEN_POWER_LAW; } else { ap.background_profile = FAST_HERNQUIST; } setCLReqFlags(&clr, sf); /*Assume we are crunching at least 1 work unit (These numbers will be properly set in prepareParameters when the parameter file is read)*/ ias = prepareParameters(sf, &ap, &bgp, &streams); if (!ias) return 1; if(sf->nForwardedArgs) { ap.totalWUs = sf->nForwardedArgs/ap.params_per_workunit; } else { ap.totalWUs = 1; } mw_printf("<number_WUs> %d </number_WUs>\n", ap.totalWUs); mw_printf("<number_params_per_WU> %d </number_params_per_WU>\n", ap.params_per_workunit); int ignoreCheckpoint = sf->ignoreCheckpoint; for(ap.currentWU = 0; ap.currentWU < ap.totalWUs; ap.currentWU++) { if (sf->numArgs && setParameters(&ap, &bgp, &streams, &(sf->numArgs[ap.params_per_workunit * ap.currentWU]), ap.params_per_workunit)) { mwFreeA(ias); freeStreams(&streams); return 1; } rc = setAstronomyParameters(&ap, &bgp); if (rc) { mwFreeA(ias); freeStreams(&streams); return 1; } setExpStreamWeights(&ap, &streams); sc = getStreamConstants(&ap, &streams); if (!sc) { mw_printf("Failed to get stream constants\n"); mwFreeA(ias); freeStreams(&streams); return 1; } results = newSeparationResults(ap.number_streams); int currentWU = ap.currentWU; rc = evaluate(results, &ap, ias, &streams, sc, sf->LikelihoodToText, sf->star_points_file, &clr, sf->do_separation, &ignoreCheckpoint, sf->separation_outfile); if (rc) mw_printf("Failed to calculate likelihood\n"); } mwFreeA(ias); mwFreeA(sc); freeStreams(&streams); if(results) freeSeparationResults(results); return rc; }