Esempio n. 1
0
void ADIOS1CommonRead::ScheduleReadCommon(const std::string &name,
                                          const Dims &offs, const Dims &ldims,
                                          const int fromStep, const int nSteps,
                                          const bool readAsLocalValue,
                                          const bool readAsJoinedArray,
                                          void *data)
{
    if (readAsLocalValue)
    {
        /* Get all the requested values from metadata now */
        ADIOS_VARINFO *vi = adios_inq_var(m_fh, name.c_str());
        if (vi)
        {
            adios_inq_var_stat(m_fh, vi, 0, 1);
            int elemsize = adios_type_size(vi->type, nullptr);
            long long blockidx = 0;
            for (int i = 0; i < fromStep; i++)
            {
                blockidx += vi->nblocks[i];
            }
            char *dest = (char *)data;
            for (int i = fromStep; i < fromStep + nSteps; i++)
            {
                for (int j = 0; j < vi->nblocks[i]; j++)
                {
                    memcpy(dest, vi->statistics->blocks->mins[blockidx],
                           elemsize);
                    ++blockidx;
                    dest += elemsize;
                }
            }
            adios_free_varinfo(vi);
        }
    }
    else
    {
        uint64_t start[32], count[32];
        for (int i = 0; i < ldims.size(); i++)
        {
            start[i] = (uint64_t)offs[i];
            count[i] = (uint64_t)ldims[i];
        }
        ADIOS_SELECTION *sel = nullptr;
        if (ldims.size() > 0)
        {
            sel = adios_selection_boundingbox(ldims.size(), start, count);
        }
        adios_schedule_read(m_fh, sel, name.c_str(), (int)fromStep, (int)nSteps,
                            data);
        adios_selection_delete(sel);
    }
}
Esempio n. 2
0
int main (int argc, char ** argv) 
{
    int         rank, size, i, j;
    MPI_Comm    comm = MPI_COMM_WORLD;
    enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP;

    MPI_Init (&argc, &argv);
    MPI_Comm_rank (comm, &rank);
    MPI_Comm_size (comm, &size);

    adios_read_init_method (method, comm, "verbose=3");
    ADIOS_FILE * f = adios_read_open_file("adios_stat.bp", method, comm);
    if (f == NULL)
    {
        fprintf (stderr, "%s\n", adios_errmsg());
        return -1;
    }

    ADIOS_VARINFO * v = adios_inq_var (f, "temperature");
    if (v) {
        /* get statistics, for each individual time-step */ 
        adios_inq_var_stat (f, v, 1, 0);


        printf("Global MIN of temperature: %lf\n", * (double *) v->statistics->min);
        printf("Global MAX of temperature: %lf\n", * (double *) v->statistics->max);
        printf("Global AVG of temperature: %lf\n", * (double *) v->statistics->avg);
        printf("Global STD DEV of temperature: %lf\n", * (double *) v->statistics->std_dev);

        printf("\n");
        printf("---------------------------------------------------------------------------\n");
        if (v->statistics->steps) {
            printf("MIN\t\tMAX\t\tAVG\t\tSTD_DEV\t\tHISTOGRAM\n");
            for(i = 0; i < v->nsteps; i++)
            {
                if (v->statistics->steps->mins[i]) 
                    printf("%lf\t", * (double *) v->statistics->steps->mins[i]);
                else
                    printf("--\t\t");
                if (v->statistics->steps->maxs[i]) 
                    printf("%lf\t", * (double *) v->statistics->steps->maxs[i]);
                else
                    printf("--\t\t");
                if (v->statistics->steps->avgs[i]) 
                    printf("%lf\t", * (double *) v->statistics->steps->avgs[i]);
                else
                    printf("--\t\t");
                if (v->statistics->steps->std_devs[i]) 
                    printf("%lf\t", * (double *) v->statistics->steps->std_devs[i]);
                else
                    printf("--\t\t");
                if (v->statistics->histogram) {
                    for(j = 0; j <= v->statistics->histogram->num_breaks; j++) {
                        printf("%d ", v->statistics->histogram->frequencies[i][j]);
                    }
                    printf("\n");
                } else {
                    printf("--\t\t");
                }
                printf("\n");
            }	
        } else {
            printf ("Per step statistics is missing\n"); 
        }
        printf("---------------------------------------------------------------------------\n");
        printf("\n");

        if (v->statistics->histogram) {
            printf("Break points:\t\t\t");
            for(j = 0; j < v->statistics->histogram->num_breaks; j++)
                printf("%6.2lf\t", v->statistics->histogram->breaks[j]);

            printf("\n");

            printf("Frequencies:\t\t\t");
            for(j = 0; j <= v->statistics->histogram->num_breaks; j++)
                printf("%6d\t", v->statistics->histogram->gfrequencies[j]);
        }

        printf("\n\n");

#if 0 
        printf ("Auto covariance of MIN values of temperature over time: %lf\n", adios_stat_cov (v, v, "min", 0, 12, 0));
        printf ("Auto correlation of MAX values of temperature over time, with lag 2 units: %lf\n", adios_stat_cor (v, v, "max", 0, 8, 2));
        printf("\n\n");
#endif 

        adios_free_varinfo (v);

    } else {
        fprintf (stderr, "ERROR: Cannot inquire statistics of variable 'temperature': %s\n", adios_errmsg());
    }

    v = adios_inq_var (f, "complex");
    if (v) {
        adios_inq_var_stat (f, v, 1, 0);
        double *C = v->statistics->min;
        printf("Global Minimum of variable complex - Magnitude: %lf\n", C[0]);
        printf("Global Minimum of variable complex - Real part: %lf\n", C[1]);
        printf("Global Minimum of variable complex - Imaginary part: %lfi\n", C[2]);

        double ** Cmin;
        Cmin = (double **) v->statistics->steps->mins;

        printf("\nMagnitude\t\tReal\t\t\tImaginary\n");
        for (j = 0; j < v->nsteps; j++)
        {
            printf ("%lf\t\t%lf\t\t%lf\n", Cmin[j][0], Cmin[j][1], Cmin[j][2]);
        }
        printf("\n");
        adios_free_varinfo (v);

    } else {
        fprintf (stderr, "ERROR: Cannot inquire statistics of variable 'complex': %s\n", adios_errmsg());
    }

    adios_read_close (f);
    MPI_Barrier (comm);
    adios_read_finalize_method (method);
    MPI_Finalize ();
    return 0;
}
Esempio n. 3
0
int print_scalar (ADIOS_FILE *f, char * name) 
{
    ADIOS_VARINFO * v;
    int i,j,k;

    v = adios_inq_var (f, name);
    adios_inq_var_blockinfo (f, v);

    printf ("Scalar '%s':\n",  name);
    printf ("nsteps = %d\n",  v->nsteps);
    printf ("nblocks per step = %d\n",  v->nblocks[0]);

    int err;

    /* Read one writeblock across all timesteps */
    int *data = (int*) calloc (v->nsteps, sizeof(int));
    ADIOS_SELECTION *s;
    printf ("Read same instance across all timesteps:\n");
    for (i=0; i < v->nblocks[0]; i++) {
        s = adios_selection_writeblock(i);
        err = adios_schedule_read_byid(f, s, v->varid, 0, v->nsteps, data);
        if (!err) 
        { 
            err = adios_perform_reads(f, 1);
            if (!err) 
            { 
                err = 0;
                printf ("  block %d = [",  i);
                for (j=0; j < v->nsteps; j++) {
                    printf ("%d", data[j]);
                    if (data[j] != 
                        block_offset [j*nblocks_per_step*size + i]) 
                    {
                        err = 1;
                    }
                    if (j < v->nsteps-1) printf(",");
                }
                printf("]");

                if (err) 
                {
                    nerrors++;
                    printf ("\tERROR expected = [");
                    for (j=0; j < v->nsteps; j++) {
                        printf ("%llu", block_offset [j*nblocks_per_step*size + i]);
                        if (j < v->nsteps-1) printf(",");
                    }
                    printf("]");
                }
                printf("\n");

            } else {
                printf ("ERROR at reading scalar '%s': %s\n", name, adios_errmsg());
            } 
        } else {
                printf ("ERROR at scheduling read for scalar '%s': %s\n", name, adios_errmsg());
        }
        adios_selection_delete(s);
    }

    /* Now read piecewise, one writeblock at a time */
    printf ("Read each instance individually:\n");
    for (j=0; j < v->nsteps; j++) {
        printf ("  step %d: \n",  j);
        for (i=0; i < v->nblocks[j]; i++) {
            s = adios_selection_writeblock(i);
            err = adios_schedule_read_byid(f, s, v->varid, j, 1, data);
            if (!err) 
            { 
                err = adios_perform_reads(f, 1);
                if (!err) 
                { 
                    printf ("    block %d = %d", i, data[0]);
                    if (data[0] != 
                        block_offset [j*nblocks_per_step*size + i]) 
                    {
                        printf ("\tERROR expected = %llu", 
                                block_offset [j*nblocks_per_step*size + i]);
                        nerrors++;
                    }
                    printf ("\n");
                } else {
                    printf ("ERROR at reading scalar '%s': %s\n", name, adios_errmsg());
                } 
            } else {
                printf ("ERROR at scheduling read for scalar '%s': %s\n", name, adios_errmsg());
            }
            adios_selection_delete(s);
        }
    }

    /* Now get them piecewise, but not with reading but through statistics */
    printf ("Get each instance individually from available statistics:\n");
    adios_inq_var_stat (f, v, 0, 1);
    if (v->statistics && v->statistics->blocks) {
        ADIOS_VARSTAT *stat = v->statistics;
        int blockid = 0;
        for (j=0; j < v->nsteps; j++) {
            printf ("  step %d: \n",  j);
            for (i=0; i < v->nblocks[j]; i++) {
                printf ("    block %d = %d", i, *(int*)stat->blocks->mins[blockid]);
                if (*(int*)stat->blocks->mins[blockid] != 
                        block_offset [j*nblocks_per_step*size + i]) 
                {
                    printf ("\tERROR expected = %llu", 
                            block_offset [j*nblocks_per_step*size + i]);
                    nerrors++;
                }
                printf ("\n");
                blockid++;
            }
        }
    }

    adios_free_varinfo (v);
    free(data);
}
Esempio n. 4
0
File: map.c Progetto: Dumbear/ADIOS
int main (int argc, char ** argv) 
{
    int         i, j, k,l;
    MPI_Comm    comm_dummy = 0;  /* MPI_Comm is defined through adios_read.h */

    if (argc < 2) {
        printf("Usage: %s <BP-file>\n", argv[0]);
        return 1;
    }

    adios_read_init_method (ADIOS_READ_METHOD_BP, comm_dummy, "show_hidden_attrs");
    ADIOS_FILE * f;
    f = adios_read_open_file (argv[1], ADIOS_READ_METHOD_BP, comm_dummy);
    if (f == NULL) {
        printf ("%s\n", adios_errmsg());
        return -1;
    }

    /* For all variables */
    printf("  Variables=%d:\n", f->nvars);
    for (i = 0; i < f->nvars; i++) {
        ADIOS_VARINFO * v = adios_inq_var_byid (f, i);
        adios_inq_var_stat (f, v, 0, 1);
        adios_inq_var_blockinfo (f, v);

        uint64_t total_size = adios_type_size (v->type, v->value);
        for (j = 0; j < v->ndim; j++)
            total_size *= v->dims[j];

        printf("    %-9s  %s", adios_type_to_string(v->type), f->var_namelist[i]);
        if (v->ndim == 0) {
            /* Scalars do not need to be read in, we get it from the metadata
               when using adios_inq_var */
            printf(" = %s\n", value_to_string(v->type, v->value, 0));
        } else {
            /* Arrays, print min/max statistics*/
            printf("[%lld",v->dims[0]);
            for (j = 1; j < v->ndim; j++)
                printf(", %lld",v->dims[j]);
            //printf("] = \n");

            if (v->type == adios_integer)
                printf("] : min=%d  max=%d\n", 
                        (*(int*)v->statistics->min), (*(int*)v->statistics->max));
            else if (v->type == adios_double)
                printf("] : min=%lg  max=%lg\n", 
                        (*(double*)v->statistics->min), (*(double*)v->statistics->max));

            /* Print block info */
            for (l=0; l<v->nsteps; l++) {
                printf("        step %3d: \n", l);
                for (j=0; j<v->nblocks[l]; j++) {
                    printf("          block %3d: [", j);
                    for (k=0; k<v->ndim; k++) {
                        printf("%3lld:%3lld", v->blockinfo[j].start[k],
                                v->blockinfo[j].start[k]+v->blockinfo[j].count[k]-1);
                        if (k<v->ndim-1)
                            printf(", ");
                    }
                    printf("]\n");
                }
            }

        }

        adios_free_varinfo (v);
    } /* variables */

    /* For all attributes */
    printf("  Attributes=%d:\n", f->nattrs);
    for (i = 0; i < f->nattrs; i++) {
        enum ADIOS_DATATYPES atype;
        int  asize;
        void *adata;
        adios_get_attr_byid (f, i, &atype, &asize, &adata);
        printf("    %-9s  %s = %s\n", adios_type_to_string(atype), 
                f->attr_namelist[i], value_to_string(atype, adata, 0));
        free(adata);
    } /* attributes */

    adios_read_close (f);

    return 0;
}
Esempio n. 5
0
int main (int argc, char ** argv) 
{
    int         i, j, k, l, t;
    MPI_Comm    comm_dummy = 0;  /* MPI_Comm is defined through adios_read.h */
    void      * data = NULL;
    uint64_t    start[] = {0,0,0,0,0,0,0,0,0,0};
    uint64_t    count[10];
    ADIOS_SELECTION *sel;

    if (argc < 2) {
        printf("Usage: %s <BP-file>\n", argv[0]);
        return 1;
    }

    ADIOS_FILE * f;
    //int step;
    //for (step=0; step < 2; step++) {
        f = adios_read_open_file (argv[1], ADIOS_READ_METHOD_BP, comm_dummy);
        if (f == NULL) {
            printf ("%s\n", adios_errmsg());
            return -1;
        }

        /* For all variables */
        printf("  Variables=%d:\n", f->nvars);
        for (i = 0; i < f->nvars; i++) {
            ADIOS_VARINFO * v = adios_inq_var_byid (f, i);
            adios_inq_var_stat (f, v, 0, 0);

            uint64_t total_size = adios_type_size (v->type, v->value);
            for (j = 0; j < v->ndim; j++)
                total_size *= v->dims[j];

            printf("    %-9s  %s", adios_type_to_string(v->type), f->var_namelist[i]);
            if (v->ndim == 0) {
                /* Scalars do not need to be read in, we get it from the metadata
                   when using adios_inq_var */
                printf(" = %s\n", value_to_string(v->type, v->value, 0));
            } else {
                /* Arrays have to be read in from the file */
                if (v->nsteps > 1) {
                    printf(" %d*",v->nsteps);
                }
                printf("[%" PRIu64,v->dims[0]);
                for (j = 1; j < v->ndim; j++)
                    printf(", %" PRIu64,v->dims[j]);
                //printf("] = \n");
                
                if (v->type == adios_integer)
                    printf("] = min=%d  max=%d\n", (*(int*)v->statistics->min), (*(int*)v->statistics->max));
                else if (v->type == adios_double)
                    printf("] = min=%lg  max=%lg\n", (*(double*)v->statistics->min), (*(double*)v->statistics->max));
                
                if (total_size > 1024*1024*1024) {
                    printf("        // too big, do not read in\n");
                } else {
                    data = malloc (total_size);
                    if (data == NULL) {
                        fprintf (stderr, "malloc failed.\n");
                        return -1;
                    }

                    for (j = 0; j < v->ndim; j++) 
                        count[j] = v->dims[j];   

                    for (t=0; t<v->nsteps; t++) {
                        sel = adios_selection_boundingbox (v->ndim, start, count);
                        adios_schedule_read_byid (f, sel, i, t, 1, data);
                        adios_perform_reads (f, 1);

                        printf("      Step %d:\n", t);
                        if (adios_errno) {
                            printf ("%s\n", adios_errmsg());
                        } else if (total_size > 1024*1024) {
                            printf ("Too big to print\n");
                        } else if (v->ndim == 1) {
                            printf ("        [");
                            for (j = 0; j < v->dims[0]; j++) 
                                printf("%s ", value_to_string(v->type, data, j));
                            printf ("]\n");
                        } else if (v->ndim == 2) {
                            for (j = 0; j < v->dims[0]; j++) {
                                printf ("        row %d: [", j);
                                for (k = 0; k < v->dims[1]; k++) 
                                    printf("%s ", value_to_string(v->type, data, j*v->dims[1] + k));
                                printf ("]\n");
                            }
                        } else if (v->ndim == 3) {
                            for (j = 0; j < v->dims[0]; j++) {
                                printf ("      block %d: \n", j);
                                for (k = 0; k < v->dims[1]; k++) {
                                    printf ("        row %d: [", k);
                                    for (l = 0; l < v->dims[2]; l++) {
                                        // NCSU ALACRITY-ADIOS - Fixed bug, k*v->dims[1] changed to  k*v->dims[2]
                                        printf("%s ", value_to_string(v->type, data, j*v->dims[1]*v->dims[2] + k*v->dims[2] + l));
                                    }
                                    printf ("]\n");
                                }
                                printf ("\n");
                            }
                        } else {
                            printf ("    cannot print arrays with >3 dimensions\n");
                        }
                    }
                    free (data);
                }
            }

            adios_free_varinfo (v);
        } /* variables */

        /* For all attributes */
        printf("  Attributes=%d:\n", f->nattrs);
        for (i = 0; i < f->nattrs; i++) {
            enum ADIOS_DATATYPES atype;
            int  asize;
            void *adata;
            adios_get_attr_byid (f, i, &atype, &asize, &adata);
            int type_size = adios_type_size (atype, adata);
            int nelems = asize / type_size;
            printf("    %-9s  %s = ", adios_type_to_string(atype), f->attr_namelist[i]);
            char *p = (char*)adata;
            if (nelems>1) printf("{");
            for (j=0; j<nelems; j++) {
                if (j>0) printf(", ");
                printf ("%s", value_to_string(atype, p, 0));
                p += type_size;
            }
            if (nelems>1) printf("}");
            printf("\n");
            free(adata);
        } /* attributes */

        adios_read_close (f);

    //} /* loop 'step' */
    return 0;
}