Example #1
0
void performQuery(ADIOS_QUERY_TEST_INFO *queryInfo, ADIOS_FILE *f, int use_streaming, int print_points, int read_results)
{
    int timestep = 0 ;
    ADIOS_VARINFO * tempVar = adios_inq_var(f, queryInfo->varName);

    if (use_streaming)
    	for (timestep = 0; timestep < queryInfo->fromStep; ++timestep)
    		assert(adios_advance_step(f, 0, 0) == 0);

    fprintf(stderr,"times steps for variable is: [%d, %d], batch size is %" PRIu64 "\n", queryInfo->fromStep, queryInfo->fromStep + queryInfo->numSteps, queryInfo->batchSize);
    for (timestep = queryInfo->fromStep; timestep < queryInfo->fromStep + queryInfo->numSteps; timestep ++) {
        fprintf(stderr, "querying on timestep %d \n", timestep);

        ADIOS_SELECTION* currBatch = NULL;

        while (adios_query_evaluate(queryInfo->query, queryInfo->outputSelection, use_streaming ? 0 : timestep, queryInfo->batchSize, &currBatch) >= 0) {
        	if (currBatch == NULL) {
        		break;
        	}
        	assert(currBatch->type ==ADIOS_SELECTION_POINTS);
        	const ADIOS_SELECTION_POINTS_STRUCT * retrievedPts = &(currBatch->u.points);
        	/* fprintf(stderr,"retrieved points %" PRIu64 " \n", retrievedPts->npoints); */

        	if (print_points) {
        		printPoints(retrievedPts, timestep);
        	}

        	if (read_results) {
        		int elmSize = adios_type_size(tempVar->type, NULL);
        		void *data = malloc(retrievedPts->npoints * elmSize);

        		// read returned temp data
        		adios_schedule_read (f, currBatch, queryInfo->varName, use_streaming ? 0 : timestep, 1, data);
        		adios_perform_reads(f, 1);

        		free(data);
        	}

        	fprintf(stderr,"Total data retrieved:%"PRIu64"\n", retrievedPts->npoints);
        	/* if (tempVar->type == adios_double) { */
        	/*     for (i = 0; i < retrievedPts->npoints; i++) { */
        	/*         fprintf(stderr,"%.6f\t", ((double*)data)[i]); */
        	/*     } */
        	/*     fprintf(stderr,"\n"); */
        	/* } */
        	/* else if (tempVar->type == adios_real) { */
        	/*     for (i = 0; i < retrievedPts->npoints; i++) { */
        	/*         fprintf(stderr,"%.6f\t", ((float*)data)[i]); */
        	/*     } */
        	/*     fprintf(stderr,"\n"); */
        	/* } */

        	adios_selection_delete(currBatch);
        	currBatch = NULL;
        }

        if (use_streaming) {
        	const int err = adios_advance_step(f, 0, 0);
        	if (timestep < queryInfo->fromStep + queryInfo->numSteps - 1) {
        		assert(err == 0);
        	} else {
        		assert(err == err_end_of_stream || err == err_step_notready);
        	}
        }
    }

    adios_query_free(queryInfo->query);
}
Example #2
0
void performQuery(ADIOS_QUERY_TEST_INFO *queryInfo, ADIOS_FILE *f, int use_streaming, int print_points, int read_results)
{
    int timestep = 0 ;
    ADIOS_VARINFO * tempVar = adios_inq_var(f, queryInfo->varName);
    adios_inq_var_blockinfo(f, tempVar);

    if (use_streaming)
    	for (timestep = 0; timestep < queryInfo->fromStep; ++timestep)
    		assert(adios_advance_step(f, 0, 0) == 0);

    fprintf(stderr,"times steps for variable is: [%d, %d], batch size is %" PRIu64 "\n", queryInfo->fromStep, queryInfo->fromStep + queryInfo->numSteps, queryInfo->batchSize);
    for (timestep = queryInfo->fromStep; timestep < queryInfo->fromStep + queryInfo->numSteps; timestep ++) {
        fprintf(stderr, "querying on timestep %d \n", timestep);

        while (1)
        {
            ADIOS_QUERY_RESULT *currBatch = NULL;
            currBatch = adios_query_evaluate(
                            queryInfo->query,
                            queryInfo->outputSelection,
                            use_streaming ? 0 : timestep,
                            queryInfo->batchSize
                        );
            if (currBatch == NULL) {
                fprintf(stderr, "Unexpected error status in querying evaluation, returned NULL as result. "
                        "ADIOS error message: %s \n", adios_errmsg());
                break;
            }
            if (currBatch->status == ADIOS_QUERY_RESULT_ERROR) {
                fprintf(stderr, "ERROR in querying evaluation: %s \n", adios_errmsg());
                break;
            }
            if (currBatch->nselections == 0) {
                /* this is normal, we processed everything in previous loop or there is 0 total result */
                break;
            }

            int n;
            if (currBatch->selections->type == ADIOS_SELECTION_POINTS)
            {
                for (n = 0; n < currBatch->nselections; n++)
                {
                    const ADIOS_SELECTION_POINTS_STRUCT * retrievedPts = &(currBatch->selections[n].u.points);
                    /* fprintf(stderr,"retrieved points %" PRIu64 " \n", retrievedPts->npoints); */

                    uint64_t * wboffs = calloc (retrievedPts->ndim, sizeof(uint64_t));
                    if (retrievedPts->container_selection &&
                            retrievedPts->container_selection->type == ADIOS_SELECTION_WRITEBLOCK)
                    {
                        int i;
                        int blockidx = retrievedPts->container_selection->u.block.index;
                        if (use_streaming) {
                            adios_inq_var_blockinfo(f, tempVar);
                        } else {
                            for (i = 0; i < timestep-1; i++)
                                blockidx += tempVar->nblocks[i];
                        }
                        for (i = 0; i < retrievedPts->ndim; ++i) {
                            wboffs[i] = tempVar->blockinfo[blockidx].start[i];
                        }
                    }

                    if (print_points) {
                        printPoints(retrievedPts, timestep, wboffs);
                    }
                    free (wboffs);

                    if (read_results) {
                        int elmSize = adios_type_size(tempVar->type, NULL);
                        void *data = malloc(retrievedPts->npoints * elmSize);

                        // read returned temp data
                        adios_schedule_read (f, &currBatch->selections[n], queryInfo->varName, use_streaming ? 0 : timestep, 1, data);
                        adios_perform_reads(f, 1);

                        free(data);
                    }

                    fprintf(stderr,"Total points retrieved %"PRIu64" in %d blocks\n",
                            currBatch->npoints, currBatch->nselections);
                    /* if (tempVar->type == adios_double) { */
                    /*     for (i = 0; i < retrievedPts->npoints; i++) { */
                    /*         fprintf(stderr,"%.6f\t", ((double*)data)[i]); */
                    /*     } */
                    /*     fprintf(stderr,"\n"); */
                    /* } */
                    /* else if (tempVar->type == adios_real) { */
                    /*     for (i = 0; i < retrievedPts->npoints; i++) { */
                    /*         fprintf(stderr,"%.6f\t", ((float*)data)[i]); */
                    /*     } */
                    /*     fprintf(stderr,"\n"); */
                    /* } */
                }
            }
            else if  (currBatch->selections->type == ADIOS_SELECTION_WRITEBLOCK)
            {
                fprintf(stderr,"Number of blocks retrieved: %d\n", currBatch->nselections);
                if (print_points) {
                    for (n = 0; n < currBatch->nselections; n++)
                    {
                        fprintf(stdout,"%d %d\n", timestep, currBatch->selections[n].u.block.index);
                    }
                }
            }
            free(currBatch->selections);
            if (currBatch->status == ADIOS_QUERY_NO_MORE_RESULTS) {
                free (currBatch);
                break;
            }

            free(currBatch);
        }

        if (use_streaming) {
            const int err = adios_advance_step(f, 0, 0);
            if (timestep < queryInfo->fromStep + queryInfo->numSteps - 1) {
                assert(err == 0);
            } else {
                assert(err == err_end_of_stream || err == err_step_notready);
            }
        }
    }

    adios_query_free(queryInfo->query);
}