/* ******** gageQuerySet() ** ** sets a query in a pervolume. Does recursive expansion of query ** to cover all prerequisite measures. ** ** Sets: pvl->query ** ** the gageContext is not actually used here, but I'm cautiously ** including it in case its used in the future. */ int gageQuerySet(gageContext *ctx, gagePerVolume *pvl, gageQuery query) { char me[]="gageQuerySet", err[BIFF_STRLEN]; gageQuery lastQuery; int pi, ii; AIR_UNUSED(ctx); if (!( pvl )) { sprintf(err, "%s: got NULL pointer", me); biffAdd(GAGE, err); return 1; } GAGE_QUERY_COPY(pvl->query, query); if (pvl->verbose) { fprintf(stderr, "%s: original ", me); gageQueryPrint(stderr, pvl->kind, pvl->query); } /* recursive expansion of prerequisites */ do { GAGE_QUERY_COPY(lastQuery, pvl->query); ii = pvl->kind->itemMax+1; do { ii--; if (GAGE_QUERY_ITEM_TEST(pvl->query, ii)) { for (pi=0; pi<GAGE_ITEM_PREREQ_MAXNUM; pi++) { if (0 != pvl->kind->table[ii].prereq[pi]) { GAGE_QUERY_ITEM_ON(pvl->query, pvl->kind->table[ii].prereq[pi]); } } } } while (ii); } while (!GAGE_QUERY_EQUAL(pvl->query, lastQuery)); if (pvl->verbose) { fprintf(stderr, "%s: expanded ", me); gageQueryPrint(stderr, pvl->kind, pvl->query); } /* doing this kind of error checking here is not really the way gage should work-- it should be done at the time of gageUpdate()-- but the novelty of pvl->data encourages putting new smarts at superficial levels instead of deeper levels */ if (!pvl->data) { for (ii=1; ii<=pvl->kind->itemMax; ii++) { if (GAGE_QUERY_ITEM_TEST(pvl->query, ii) && pvl->kind->table[ii].needData) { sprintf(err, "%s: item %d (%s) needs data, but pvl->data is NULL", me, ii, airEnumStr(pvl->kind->enm, ii)); biffAdd(GAGE, err); return 1; } } } pvl->flag[gagePvlFlagQuery] = AIR_TRUE; return 0; }
pullTask * _pullTaskNew(pullContext *pctx, int threadIdx) { char me[]="_pullTaskNew", err[BIFF_STRLEN]; pullTask *task; unsigned int ii, offset; task = (pullTask *)calloc(1, sizeof(pullTask)); if (!task) { sprintf(err, "%s: couldn't allocate task", me); biffAdd(PULL, err); return NULL; } task->pctx = pctx; for (ii=0; ii<pctx->volNum; ii++) { if (!(task->vol[ii] = _pullVolumeCopy(pctx->vol[ii]))) { sprintf(err, "%s: trouble copying vol %u/%u", me, ii, pctx->volNum); biffAdd(PULL, err); return NULL; } } if (0) { gagePerVolume *pvl; const double *ans; double pos[3]; int gret; for (ii=0; ii<pctx->volNum; ii++) { pvl = task->vol[ii]->gctx->pvl[0]; fprintf(stderr, "!%s: vol[%u] query:\n", me, ii); gageQueryPrint(stderr, pvl->kind, pvl->query); ans = gageAnswerPointer(task->vol[ii]->gctx, pvl, gageSclValue); ELL_3V_SET(pos, 0.6, 0.6, 0.3); gret = gageProbeSpace(task->vol[ii]->gctx, pos[0], pos[1], pos[2], AIR_FALSE, AIR_TRUE); fprintf(stderr, "!%s: (%d) val(%g,%g,%g) = %g\n", me, gret, pos[0], pos[1], pos[2], *ans); ELL_3V_SET(pos, 0.5, 0.0, 0.0); gret = gageProbeSpace(task->vol[ii]->gctx, pos[0], pos[1], pos[2], AIR_FALSE, AIR_TRUE); fprintf(stderr, "!%s: (%d) val(%g,%g,%g) = %g\n", me, gret, pos[0], pos[1], pos[2], *ans); } } offset = 0; for (ii=0; ii<=PULL_INFO_MAX; ii++) { unsigned int volIdx; if (pctx->ispec[ii]) { volIdx = pctx->ispec[ii]->volIdx; task->ans[ii] = gageAnswerPointer(task->vol[volIdx]->gctx, task->vol[volIdx]->gpvl, pctx->ispec[ii]->item); fprintf(stderr, "!%s: task->ans[%u] = %p\n", me, ii, task->ans[ii]); } else { task->ans[ii] = NULL; } } if (pctx->threadNum > 1) { task->thread = airThreadNew(); } task->threadIdx = threadIdx; task->rng = airRandMTStateNew(pctx->rngSeed + threadIdx); task->pointBuffer = pullPointNew(pctx); pctx->idtagNext = 0; /* because pullPointNew incremented it */ task->neighPoint = AIR_CAST(pullPoint **, calloc(_PULL_NEIGH_MAXNUM, sizeof(pullPoint*))); task->returnPtr = NULL; task->stuckNum = 0; return task; }