bool ADIOSFileObject::Open() { if (IsOpen()) return true; #ifdef PARALLEL fp = adios_fopen(fileName.c_str(), (MPI_Comm)VISIT_MPI_COMM); #else fp = adios_fopen(fileName.c_str(), 0); #endif char errmsg[1024]; if (fp == NULL) { sprintf(errmsg, "Error opening bp file %s:\n%s", fileName.c_str(), adios_errmsg()); EXCEPTION1(InvalidDBTypeException, errmsg); } ADIOS_VARINFO *avi; gps = (ADIOS_GROUP **) malloc(fp->groups_count * sizeof(ADIOS_GROUP *)); if (gps == NULL) EXCEPTION1(InvalidDBTypeException, "The file could not be opened. Not enough memory"); debug5 << "ADIOS BP file: " << fileName << endl; debug5 << "# of groups: " << fp->groups_count << endl; debug5 << "# of variables: " << fp->vars_count << endl; debug5 << "# of attributes:" << fp->attrs_count << endl; debug5 << "time steps: " << fp->ntimesteps << " from " << fp->tidx_start << endl; //Read in variables/scalars. variables.clear(); scalars.clear(); for (int gr=0; gr<fp->groups_count; gr++) { debug5 << " group " << fp->group_namelist[gr] << ":" << endl; gps[gr] = adios_gopen_byid(fp, gr); if (gps[gr] == NULL) { sprintf(errmsg, "Error opening group %s in bp file %s:\n%s", fp->group_namelist[gr], fileName.c_str(), adios_errmsg()); EXCEPTION1(InvalidDBTypeException, errmsg); } for (int vr=0; vr<gps[gr]->vars_count; vr++) { avi = adios_inq_var_byid(gps[gr], vr); if (avi == NULL) { sprintf(errmsg, "Error opening inquiring variable %s in group %s of bp file %s:\n%s", gps[gr]->var_namelist[vr], fp->group_namelist[gr], fileName.c_str(), adios_errmsg()); EXCEPTION1(InvalidDBTypeException, errmsg); } if (SupportedVariable(avi)) { //Scalar if (avi->ndim == 0) { ADIOSScalar s(gps[gr]->var_namelist[vr], avi); scalars[s.Name()] = s; debug5<<" added scalar "<<s<<endl; } //Variable else { // add variable to map, map id = variable path without the '/' in the beginning ADIOSVar v(gps[gr]->var_namelist[vr], gr, avi); variables[v.name] = v; debug5<<" added variable "<< v.name<<endl; } } else debug5<<"Skipping variable: "<<gps[gr]->var_namelist[vr]<<" dim= "<<avi->ndim <<" timedim= "<<avi->timedim <<" type= "<<adios_type_to_string(avi->type)<<endl; adios_free_varinfo(avi); } //Read in attributes. for (int a = 0; a < gps[gr]->attrs_count; a++) { int sz; void *data = NULL; ADIOS_DATATYPES attrType; if (adios_get_attr_byid(gps[gr], a, &attrType, &sz, &data) != 0) { debug5<<"Failed to get attr: "<<gps[gr]->attr_namelist[a]<<endl; continue; } ADIOSAttr attr(gps[gr]->attr_namelist[a], attrType, data); attributes[attr.Name()] = attr; free(data); } adios_gclose(gps[gr]); gps[gr] = NULL; } return true; }
int main (int argc, char ** argv) { int gidx, i, j, k,l; 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]; int64_t bytes_read = 0; 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_fopen (argv[1], comm_dummy); if (f == NULL) { printf ("%s\n", adios_errmsg()); return -1; } /* For all groups */ for (gidx = 0; gidx < f->groups_count; gidx++) { printf("Group %s:\n", f->group_namelist[gidx]); ADIOS_GROUP * g = adios_gopen (f, f->group_namelist[gidx]); if (g == NULL) { printf ("%s\n", adios_errmsg()); return -1; } /* For all variables */ printf(" Variables=%d:\n", g->vars_count); for (i = 0; i < g->vars_count; i++) { ADIOS_VARINFO * v = adios_inq_var_byid (g, i); 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), g->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 */ 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 timedim=%d\n", (*(int*)v->gmin), (*(int*)v->gmax), v->timedim); else if (v->type == adios_double) printf("] = min=%lg max=%lg timedim=%d\n", (*(double*)v->gmin), (*(double*)v->gmax), v->timedim); 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]; bytes_read = adios_read_var_byid (g, i, start, count, data); if (bytes_read < 0) { printf ("%s\n", adios_errmsg()); } else if (bytes_read > 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++) { printf("%s ", value_to_string(v->type, data, j*v->dims[1]*v->dims[2] + k*v->dims[1] + 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", g->attrs_count); for (i = 0; i < g->attrs_count; i++) { enum ADIOS_DATATYPES atype; int asize; void *adata; adios_get_attr_byid (g, i, &atype, &asize, &adata); printf(" %-9s %s = %s\n", adios_type_to_string(atype), g->attr_namelist[i], value_to_string(atype, adata, 0)); free(adata); } /* attributes */ adios_gclose (g); } /* groups */ adios_fclose (f); //} /* loop 'step' */ return 0; }
int main (int argc, char ** argv) { int rank, size, i; MPI_Comm comm = MPI_COMM_WORLD; enum ADIOS_DATATYPES attr_type; enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP; int attr_size; void * data = NULL; MPI_Init (&argc, &argv); MPI_Comm_rank (comm, &rank); MPI_Comm_size (comm, &size); adios_read_init_method (method, comm, "verbose=3"); adios_logger_open ("log_read_C", rank); ADIOS_FILE * f = adios_read_open ("attributes_C.bp", method, comm, ADIOS_LOCKMODE_NONE, 0.0); if (f == NULL) { log_error ("%s\n", adios_errmsg()); return -1; } for (i = 0; i < f->nattrs; i++) { adios_get_attr (f, f->attr_namelist[i], &attr_type, &attr_size, &data); log_test("rank %d: attr: %s %s = ", rank, adios_type_to_string(attr_type), f->attr_namelist[i]); int type_size = adios_type_size (attr_type, data); int nelems = attr_size / type_size; int k; char *p = (char*)data; for (k=0; k<nelems; k++) { if (k>0) log_test(", "); switch (attr_type) { case adios_integer: log_test ("%d", *(int *)p); break; case adios_double: log_test ("%e", *(double *)p); break; case adios_string: log_test ("\"%s\"", (char *)p); break; case adios_string_array: log_test ("\"%s\"", *(char **)p); break; default: log_test ("??????\n"); } p=p+type_size; } log_test("\n"); free (data); data = 0; } adios_read_close (f); MPI_Barrier (comm); adios_read_finalize_method (ADIOS_READ_METHOD_BP); adios_logger_close(); MPI_Finalize (); return 0; }
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; }
int process_metadata(int step) { int retval = 0; int i, j; char gdims[256], ldims[256], offs[256]; uint64_t sum_count; ADIOS_VARINFO *v; // shortcut pointer if (step > 1) { // right now, nothing to prepare in later steps print("Step %d. return immediately\n",step); return 0; } /* First step processing */ // get groupname of stream, then declare for output adios_get_grouplist(f, &group_namelist); print0("Group name is %s\n", group_namelist[0]); adios_declare_group(&gh,group_namelist[0],"",adios_flag_yes); varinfo = (VarInfo *) malloc (sizeof(VarInfo) * f->nvars); if (!varinfo) { print("ERROR: rank %d cannot allocate %lu bytes\n", rank, sizeof(VarInfo)*f->nvars); return 1; } write_total = 0; largest_block = 0; // Decompose each variable and calculate output buffer size for (i=0; i<f->nvars; i++) { print0 ("Get info on variable %d: %s\n", i, f->var_namelist[i]); varinfo[i].v = adios_inq_var_byid (f, i); v = varinfo[i].v; // just a shortcut if (v == NULL) { print ("rank %d: ERROR: Variable %s inquiry failed: %s\n", rank, f->var_namelist[i], adios_errmsg()); return 1; } // print variable type and dimensions print0(" %-9s %s", adios_type_to_string(v->type), f->var_namelist[i]); if (v->ndim > 0) { print0("[%llu", v->dims[0]); for (j = 1; j < v->ndim; j++) print0(", %llu", v->dims[j]); print0("] :\n"); } else { print0("\tscalar\n"); } // determine subset we will write decompose (numproc, rank, v->ndim, v->dims, decomp_values, varinfo[i].count, varinfo[i].start, &sum_count); varinfo[i].writesize = sum_count * adios_type_size(v->type, v->value); if (varinfo[i].writesize != 0) { write_total += varinfo[i].writesize; if (largest_block < varinfo[i].writesize) largest_block = varinfo[i].writesize; } } // determine output buffer size and allocate it uint64_t bufsize = write_total + f->nvars*128 + f->nattrs*32 + 1024; if (bufsize > max_write_buffer_size) { print ("ERROR: rank %d: write buffer size needs to hold about %llu bytes, " "but max is set to %d\n", rank, bufsize, max_write_buffer_size); return 1; } print0 ("Rank %d: allocate %llu MB for output buffer\n", rank, bufsize/1048576+1); adios_allocate_buffer (ADIOS_BUFFER_ALLOC_NOW, bufsize/1048576+1); // allocate read buffer bufsize = largest_block + 128; if (bufsize > max_read_buffer_size) { print ("ERROR: rank %d: read buffer size needs to hold at least %llu bytes, " "but max is set to %d\n", rank, bufsize, max_read_buffer_size); return 1; } print0 ("Rank %d: allocate %g MB for input buffer\n", rank, (double)bufsize/1048576.0); readbuf = (char *) malloc ((size_t)bufsize); if (!readbuf) { print ("ERROR: rank %d: cannot allocate %llu bytes for read buffer\n", rank, bufsize); return 1; } // Select output method adios_select_method (gh, wmethodname, wmethodparams, ""); // Define variables for output based on decomposition char *vpath, *vname; for (i=0; i<f->nvars; i++) { v = varinfo[i].v; if (varinfo[i].writesize != 0) { // define variable for ADIOS writes getbasename (f->var_namelist[i], &vpath, &vname); if (v->ndim > 0) { int64s_to_str (v->ndim, v->dims, gdims); int64s_to_str (v->ndim, varinfo[i].count, ldims); int64s_to_str (v->ndim, varinfo[i].start, offs); print ("rank %d: Define variable path=\"%s\" name=\"%s\" " "gdims=%s ldims=%s offs=%s\n", rank, vpath, vname, gdims, ldims, offs); adios_define_var (gh, vname, vpath, v->type, ldims, gdims, offs); } else { print ("rank %d: Define scalar path=\"%s\" name=\"%s\"\n", rank, vpath, vname); adios_define_var (gh, vname, vpath, v->type, "", "", ""); } free(vpath); free(vname); } } if (rank == 0) { // get and define attributes enum ADIOS_DATATYPES attr_type; void * attr_value; char * attr_value_str; int attr_size; for (i=0; i<f->nattrs; i++) { adios_get_attr_byid (f, i, &attr_type, &attr_size, &attr_value); attr_value_str = (char *)value_to_string (attr_type, attr_value, 0); getbasename (f->attr_namelist[i], &vpath, &vname); if (vpath && !strcmp(vpath,"/__adios__")) { // skip on /__adios/... attributes print ("rank %d: Ignore this attribute path=\"%s\" name=\"%s\" value=\"%s\"\n", rank, vpath, vname, attr_value_str); } else { adios_define_attribute (gh, vname, vpath, attr_type, attr_value_str, ""); print ("rank %d: Define attribute path=\"%s\" name=\"%s\" value=\"%s\"\n", rank, vpath, vname, attr_value_str); free (attr_value); } } } return retval; }
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; }
int main (int argc, char ** argv) { char filename [256]; int rank, size, gidx, i, j, k,l; MPI_Comm comm_dummy = MPI_COMM_WORLD; /* MPI_Comm is defined through adios_read.h */ enum ADIOS_DATATYPES attr_type; void * data = NULL; uint64_t start[] = {0,0,0,0,0,0,0,0,0,0}; uint64_t count[MAX_DIMS], hcount[MAX_DIMS], bytes_read = 0; herr_t h5_err; char h5name[256],aname[256],fname[256]; int dims [MAX_DIMS]; int h5rank[MAX_DIMS]; int h5i, level; hid_t grp_id [GMAX+1], space_id, dataset_id; hid_t memspace_id, dataspace_id, att_id; char ** grp_name; hid_t type_id; hid_t h5_type_id; hsize_t adims; if (argc < 2) { printf("Usage: %s <BP-file> <HDF5-file>\n", argv[0]); return 1; } MPI_Init(&argc, &argv); h5_err = H5Eset_auto(NULL, NULL ); ADIOS_FILE * f = adios_fopen (argv[1], comm_dummy); HDF5_FILE = H5Fcreate(argv[2],H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* create the complex types for HDF5 */ complex_real_id = H5Tcreate (H5T_COMPOUND, sizeof (complex_real_t)); H5Tinsert (complex_real_id, "real", HOFFSET(complex_real_t,re), H5T_NATIVE_FLOAT); H5Tinsert (complex_real_id, "imaginary", HOFFSET(complex_real_t,im), H5T_NATIVE_FLOAT); complex_double_id = H5Tcreate (H5T_COMPOUND, sizeof (complex_double_t)); H5Tinsert (complex_double_id, "real", HOFFSET(complex_double_t,re), H5T_NATIVE_DOUBLE); H5Tinsert (complex_double_id, "imaginary", HOFFSET(complex_double_t,im), H5T_NATIVE_DOUBLE); if (f == NULL) { if (DEBUG) printf ("%s\n", adios_errmsg()); return -1; } /* For all groups */ for (gidx = 0; gidx < f->groups_count; gidx++) { if (DEBUG) printf("Group %s:\n", f->group_namelist[gidx]); ADIOS_GROUP * g = adios_gopen (f, f->group_namelist[gidx]); if (g == NULL) { if (DEBUG) printf ("%s\n", adios_errmsg()); return -1; } /* First create all of the groups */ grp_id [0] = HDF5_FILE; for (i = 0; i < g->vars_count; i++) { ADIOS_VARINFO * v = adios_inq_var_byid (g, i); strcpy(h5name,g->var_namelist[i]); grp_name = bp_dirparser (h5name, &level); for (j = 0; j < level-1; j++) { grp_id [j + 1] = H5Gopen (grp_id [j], grp_name [j]); if (grp_id [j + 1] < 0) { grp_id [j + 1] = H5Gcreate (grp_id [j], grp_name [j], 0); } } for (j=1; j<level; j++) { H5Gclose(grp_id[j]); } } /* Now we can write data into these scalars */ /* For all variables */ if (DEBUG) printf(" Variables=%d:\n", g->vars_count); for (i = 0; i < g->vars_count; i++) { ADIOS_VARINFO * v = adios_inq_var_byid (g, i); uint64_t total_size = adios_type_size (v->type, v->value); for (j = 0; j < v->ndim; j++) total_size *= v->dims[j]; strcpy(h5name,g->var_namelist[i]); if (DEBUG) printf(" %-9s %s", adios_type_to_string(v->type), g->var_namelist[i]); h5_err = bp_getH5TypeId (v->type, &h5_type_id); if (v->type==adios_string) H5Tset_size(h5_type_id,strlen(v->value)); if (v->ndim == 0) { /* Scalars do not need to be read in, we get it from the metadata when using adios_inq_var */ if (DEBUG) printf(" = %s\n", value_to_string(v->type, v->value, 0)); // add the hdf5 dataset, these are scalars for (h5i = 0;h5i<MAX_DIMS;h5i++) count[0] = 0; count[0] = 1; // we are writing just 1 element, RANK=1 h5_err = bp_getH5TypeId (v->type, &h5_type_id); H5LTmake_dataset(HDF5_FILE,h5name,1,count,h5_type_id,v->value); } else { h5_err = readVar(g, v, h5name); } adios_free_varinfo (v); } /* variables */ /* For all attributes */ if (DEBUG) printf(" Attributes=%d:\n", g->attrs_count); for (i = 0; i < g->attrs_count; i++) { enum ADIOS_DATATYPES atype; int asize; void *adata; adios_get_attr_byid (g, i, &atype, &asize, &adata); grp_name = bp_dirparser (g->attr_namelist[i], &level); strcpy(aname,grp_name[level-1]); // the name of the attribute is the last in the array // we then need to concat the rest together strcpy(fname,"/"); for (j=0;j<level-1;j++) { strcat(fname,grp_name[j]); } h5_err = bp_getH5TypeId (atype, &h5_type_id); // let's create the attribute adims = 1; if (atype==adios_string) H5Tset_size(h5_type_id,strlen(adata)); space_id = H5Screate(H5S_SCALAR); // just a scalar att_id = H5Acreate(HDF5_FILE, g->attr_namelist[i], h5_type_id, space_id,H5P_DEFAULT); h5_err = H5Awrite(att_id, h5_type_id, adata); h5_err = H5Aclose(att_id); h5_err = H5Sclose(space_id); if (DEBUG) printf(" %-9s %s = %s\n", adios_type_to_string(atype), g->attr_namelist[i], value_to_string(atype, adata, 0)); free(adata); } /* attributes */ adios_gclose (g); } /* groups */ adios_fclose (f); h5_err = H5Fclose(HDF5_FILE); MPI_Finalize(); return 0; }
int readVar(ADIOS_GROUP *gp, ADIOS_VARINFO *vi, const char * name) { int i,j; uint64_t start_t[MAX_DIMS], count_t[MAX_DIMS]; // processed <0 values in start/count uint64_t s[MAX_DIMS], c[MAX_DIMS]; // for block reading of smaller chunks hsize_t h5_start[MAX_DIMS], h5_count[MAX_DIMS], h5_stride[MAX_DIMS]; hsize_t h5_dims[MAX_DIMS]; uint64_t nelems; // number of elements to read int elemsize; // size in bytes of one element uint64_t st, ct; void *data; uint64_t sum; // working var to sum up things int maxreadn; // max number of elements to read once up to a limit (10MB of data) int actualreadn; // our decision how much to read at once int readn[MAX_DIMS]; // how big chunk to read in in each dimension? int64_t bytes_read; // retval from adios_get_var() int incdim; // used in incremental reading in hid_t grp_id, space_id, dataset, global_memspace, dataspace; hid_t local_memspace, h5_ndim ; hid_t h5_err; hid_t h5_type_id; if (getTypeInfo(vi->type, &elemsize)) { fprintf(stderr, "Adios type %d (%s) not supported in bpls. var=%s\n", vi->type, adios_type_to_string(vi->type), name); return 10; } h5_err = bp_getH5TypeId (vi->type, &h5_type_id); h5_ndim = (hsize_t) vi->ndim; for (j=0;j<h5_ndim;j++) h5_dims[j] = vi->dims[j]; // create the hdf5 dataspace. // create the counter arrays with the appropriate lengths // transfer start and count arrays to format dependent arrays for (j=0; j<vi->ndim; j++) { icount[j]=-1; h5_stride[j]= (hsize_t) 1; } nelems = 1; for (j=0; j<vi->ndim; j++) { if (istart[j] < 0) // negative index means last-|index| st = vi->dims[j]+istart[j]; else st = istart[j]; if (icount[j] < 0) // negative index means last-|index|+1-start ct = vi->dims[j]+icount[j]+1-st; else ct = icount[j]; if (verbose>2) printf(" j=%d, st=%llu ct=%llu\n", j, st, ct); start_t[j] = st; count_t[j] = ct; nelems *= ct; if (verbose>1) printf(" s[%d]=%llu, c[%d]=%llu, n=%llu\n", j, start_t[j], j, count_t[j], nelems); } if (verbose>1) { printf(" total size of data to read = %llu\n", nelems*elemsize); } maxreadn = MAX_BUFFERSIZE/elemsize; if (nelems < maxreadn) maxreadn = nelems; // special case: string. Need to use different elemsize if (vi->type == adios_string) { if (vi->value) elemsize = strlen(vi->value)+1; maxreadn = elemsize; } // allocate data array data = (void *) malloc (maxreadn*elemsize); // SAK: don't want the +8.... //+8 for just to be sure // determine strategy how to read in: // - at once // - loop over 1st dimension // - loop over 1st & 2nd dimension // - etc if (verbose>1) printf("Read size strategy:\n"); sum = (uint64_t) 1; actualreadn = (uint64_t) 1; for (i=vi->ndim-1; i>=0; i--) { if (sum >= (uint64_t) maxreadn) { readn[i] = 1; } else { readn[i] = maxreadn / (int)sum; // sum is small for 4 bytes here // this may be over the max count for this dimension if (readn[i] > count_t[i]) readn[i] = count_t[i]; } if (verbose>1) printf(" dim %d: read %d elements\n", i, readn[i]); sum = sum * (uint64_t) count_t[i]; actualreadn = actualreadn * readn[i]; } if (verbose>1) printf(" read %d elements at once, %lld in total (nelems=%lld)\n", actualreadn, sum, nelems); // init s and c for (j=0; j<vi->ndim; j++) { s[j]=start_t[j]; c[j]=readn[j]; h5_count[j] = (hsize_t) c[j]; h5_start[j] = (hsize_t) s[j]; } // read until read all 'nelems' elements sum = 0; while (sum < nelems) { // how many elements do we read in next? actualreadn = 1; for (j=0; j<vi->ndim; j++) actualreadn *= c[j]; if (verbose>2) { printf("adios_read_var name=%s ", name); //PRINT_DIMS(" start", s, vi->ndim, j); //PRINT_DIMS(" count", c, vi->ndim, j); printf(" read %d elems\n", actualreadn); } // read a slice finally bytes_read = adios_read_var_byid (gp, vi->varid, s, c, data); if (bytes_read < 0) { fprintf(stderr, "Error when reading variable %s. errno=%d : %s \n", name, adios_errno, adios_errmsg()); free(data); return 11; } // now we must place this inside the hdf5 file... we know the offset (s) // we know the count, c // we know the global rank v->ndim // we know the global dimensions v->dims // get the hdf5 calls for writing the hyperslab..... dataset = H5Dopen(HDF5_FILE,name); if (dataset> 0) { global_memspace = H5Dget_space(dataset); hid_t rank_old = H5Sget_simple_extent_ndims(global_memspace); hsize_t *maxdims = (hsize_t *) malloc (h5_ndim * sizeof (hsize_t)); h5_err = H5Sget_simple_extent_dims(global_memspace,maxdims,NULL); free(maxdims); } else { global_memspace = H5Screate_simple (h5_ndim, h5_dims, NULL); hid_t cparms = H5Pcreate(H5P_DATASET_CREATE); h5_err = H5Pset_chunk(cparms,h5_ndim,h5_count); dataset = H5Dcreate(HDF5_FILE,name,h5_type_id, global_memspace,cparms); H5Pclose(cparms); } local_memspace = H5Screate_simple (h5_ndim, h5_count, NULL); for (j=0;j<vi->ndim;j++) h5_err = H5Sselect_hyperslab (global_memspace, H5S_SELECT_SET ,h5_start, h5_stride, h5_count, NULL); h5_err = H5Dwrite(dataset,h5_type_id,local_memspace,global_memspace,H5P_DEFAULT, data); H5Sclose(local_memspace); H5Dclose(dataset); //H5Tclose(h5_type_id); if (verbose>2) printf(" read %lld bytes\n", bytes_read); // print slice // prepare for next read sum += actualreadn; incdim=1; // largest dim should be increased for (j=vi->ndim-1; j>=0; j--) { if (incdim==1) { if (s[j]+c[j] == start_t[j]+count_t[j]) { // reached the end of this dimension s[j] = start_t[j]; c[j] = readn[j]; h5_count[j] = (hsize_t) c[j]; h5_start[j] = (hsize_t) s[j]; incdim = 1; // next smaller dim can increase too } else { // move up in this dimension up to total count s[j] += readn[j]; h5_start[j] = (hsize_t) s[j]; if (s[j]+c[j] > start_t[j]+count_t[j]) { // do not reach over the limit c[j] = start_t[j]+count_t[j]-s[j]; h5_count[j] = (hsize_t) c[j]; } incdim = 0; } } } } // end while sum < nelems H5Sclose(global_memspace); free(data); return 0; }