eavlField * eavlXGCImporter::GetField(const string &name, const string &mesh, int chunk) { map<string, ADIOS_VARINFO*>::const_iterator it = variables.find(name); if (it == variables.end()) THROW(eavlException, string("Variable not found: ")+name); uint64_t s[3], c[3]; ADIOS_SELECTION *sel = MakeSelection(it->second, s, c); int nt = 1; for (int i = 0; i < it->second->ndim; i++) nt *= c[i]; double *buff = new double[nt]; adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff); int retval = adios_perform_reads(fp, 1); adios_selection_delete(sel); eavlFloatArray *arr = new eavlFloatArray(name, 1); arr->SetNumberOfTuples(nt); for (int i = 0; i < nt; i++) arr->SetComponentFromDouble(i, 0, buff[i]); delete [] buff; eavlField *field = new eavlField(1, arr, eavlField::ASSOC_POINTS); //field->PrintSummary(cout); return field; }
int read_write(int step) { int retval = 0; int i; uint64_t total_size; // open output file adios_open (&fh, group_namelist[0], outfilename, (step==1 ? "w" : "a"), comm); adios_group_size (fh, write_total, &total_size); for (i=0; i<f->nvars; i++) { if (varinfo[i].writesize != 0) { // read variable subset print ("rank %d: Read variable %d: %s\n", rank, i, f->var_namelist[i]); ADIOS_SELECTION *sel = adios_selection_boundingbox (varinfo[i].v->ndim, varinfo[i].start, varinfo[i].count); adios_schedule_read_byid (f, sel, i, 1, 1, readbuf); adios_perform_reads (f, 1); // write (buffer) variable print ("rank %d: Write variable %d: %s\n", rank, i, f->var_namelist[i]); adios_write(fh, f->var_namelist[i], readbuf); } } adios_release_step (f); // this step is no longer needed to be locked in staging area adios_close (fh); // write out output buffer to file return retval; }
// k is numbered from 1 to sum_nblocks void verifyData(ADIOS_FILE* f, ADIOS_VARINFO* v, int k, int timestep) { uint64_t blockBytes = adios_type_size (v->type, v->value); int j=0; if (v->ndim <= 0) { return; } //printf("verify block[%d]: ", k); for (j=0; j<v->ndim; j++) { blockBytes *= v->blockinfo[k].count[j]; //printf("%" PRIu64 ":%" PRIu64 " ", v->blockinfo[k].start[j], v->blockinfo[k].count[j]); } void* data = NULL; data = malloc(blockBytes); ADIOS_SELECTION* sel = adios_selection_boundingbox (v->ndim, v->blockinfo[k].start, v->blockinfo[k].count); int err = adios_schedule_read_byid(f, sel, v->varid, timestep, 1, data); if (!err) { err = adios_perform_reads(f, 1); } //fastbit_adios_util_printData(data, v->type, blockBytes/adios_type_size(v->type, v->value)); adios_selection_delete(sel); free(data); data = NULL; }
void onBox(int rank, ADIOS_FILE* f, ADIOS_VARINFO* v, int timestep, uint64_t* start, uint64_t* count, FastBitDataType ft) { int i=0; char selName[100]; sprintf(selName, "box-%lu", start[0]); uint64_t totalCount = 1; for (i = 0; i<v->ndim; i++) { totalCount *= count[i]; } double* data = (double *) calloc (totalCount, sizeof (double)); uint64_t currStart = 0; ADIOS_SELECTION* boxSel = adios_selection_boundingbox(v->ndim, start, count); int err = adios_schedule_read_byid(f, boxSel, v->varid, timestep, 1, data); if (!err) { err = adios_perform_reads(f, 1); } processData(data, totalCount, rank, timestep, selName, ft, v); } // on box
/// Read a sub-array. /// /// @Note The length of the buffer is assumed to be sufficiently large /// if the argument bufLen is less or equal to 0. The caller is /// responsible for allocating the buffer (@c buf) of the currect size. int64_t ADIOS_Var::readData(void* buf, int64_t bufLen, const uint64_t* start, const uint64_t* count) { uint64_t total_elm = 1; for (int i=0; i<getNumDimension(); i++) { total_elm *= count[i]; #ifdef DEBUG LOGGER(ibis::gVerbose > 5) << "ADIOS_Var::readData: [" << i << "] start=" << start[i] << ", count=" << count[i]; #endif } { uint64_t total_bytes = total_elm * adios_type_size(getType(), readValue()); if (bufLen > 0 && (uint64_t)bufLen < total_bytes) { LOGGER(ibis::gVerbose > 0) << "Warning -- ADIOS_Var::readData: bufLen (" << bufLen << ") < total_bytes (" << total_bytes << ")"; return -1; } } ADIOS_SELECTION *sel = adios_selection_boundingbox (m_handle->ndim, start, count); if (sel == 0) { LOGGER(ibis::gVerbose > 1) << "Warning -- ADIOS_Var::readData failed to create a selection"; return -2; } IBIS_BLOCK_GUARD(adios_selection_delete, sel); int ierr = adios_schedule_read_byid (getFile(), sel, index(), getFile()->current_step, 1, buf); if (ierr != 0) { LOGGER(ibis::gVerbose > 0) << "Warning -- ADIOS_Var::readData call to " "adios_schedule_read_byid failed due to " << adios_errmsg(); return -3; } ierr = adios_perform_reads(getFile(), 1); // 1 == blocking if (ierr != 0) { LOGGER(ibis::gVerbose > 0) << "Warning -- ADIOS_Var::readData call to adios_perform_reads on " << getFileName() << " failed due to " << adios_errmsg(); return -4; } LOGGER(ibis::gVerbose > 5) << "ADIOS_Var::readData: competeled reading " << total_elm << " element" << (total_elm>1?"s":"") << " for " << getName() << " from " << getFileName(); return total_elm; } // ADIOS_Var::readData
void onBlock(int rank, ADIOS_FILE* f, ADIOS_VARINFO* v, int i, int j, int blockCounter, FastBitDataType ft) { char bmsVarName[100]; char keyVarName[100]; char offsetName[100]; int64_t var_ids_bms[v->nblocks[i]]; int64_t var_ids_key[v->nblocks[i]]; int64_t var_ids_offset[v->nblocks[i]]; sprintf(bmsVarName, "bms-%d-%d-%d", v->varid, i, j); sprintf(keyVarName, "key-%d-%d-%d", v->varid, i, j); sprintf(offsetName, "offset-%d-%d-%d", v->varid, i, j); uint64_t blockSize = fastbit_adios_util_getBlockSize(v, i, j); uint64_t blockDataByteSize = adios_type_size (v->type, v->value) * blockSize; char notes[100]; logTime(NULL); logTimeMillis(NULL); sprintf(notes, " reading data from adios on varid=%d, time=%d, block: %d, size=%ld bytes=%ld", v->varid, i, j, blockSize, blockDataByteSize); logTime(notes); logTimeMillis(notes); localtime(&indexRefresh); //printf(" %d th block / (%d), size= %" PRIu64 " bytes=%" PRIu64, j, blockSize, blockCounter, blockDataByteSize); void* data = malloc (blockDataByteSize); ADIOS_SELECTION* blockSel = adios_selection_writeblock(j); //adios_selcton_writeblock(num), 0 <= num < nblocks[timestep] //ADIOS_SELECTION* blockSel = adios_selection_writeblock(blockCounter); int err = adios_schedule_read_byid(f, blockSel, v->varid, i, 1, data); if (!err) { err = adios_perform_reads(f, 1); } else { printf("Unable to read block %d at timestep: %d \n", j, i); return; //break; } //fastbit_adios_util_printData(data, v->type, blockSize); char selName[20]; sprintf(selName, "block-%d", j); processData(data, blockSize, rank, i, selName, ft, v); //processData(void* data, uint64_t dataCount, int rank, int timestep, char* selName, FastBitDataType ft, ADIOS_VARINFO* v) adios_selection_delete(blockSel); verifyData(f, v, blockCounter, i); } // onblock
void onMultiBlock(int rank, ADIOS_FILE* f, ADIOS_VARINFO* v, int timestep, int blockStart, int blockEnd, FastBitDataType ft) { int i=0; char selName[100]; sprintf(selName, "block-%d", blockStart, blockEnd); uint64_t blockSizeArray[blockEnd-blockStart]; uint64_t totalCount = 0; for (i = blockStart; i< blockEnd; i++) { blockSizeArray[i-blockStart] = fastbit_adios_util_getBlockSize(v, timestep, i); //totalBytes += blockSizeArray[i-blockStart] * adios_type_size (v->type, v->value); totalCount += blockSizeArray[i-blockStart]; } //void* data = malloc (totalBytes); double* data = (double *) calloc (totalCount, sizeof (double)); uint64_t currStart = 0; for (i = blockStart; i < blockEnd; i++) { ADIOS_SELECTION* blockSel = adios_selection_writeblock(i); int err = adios_schedule_read_byid(f, blockSel, v->varid, timestep, 1, &data[currStart]); currStart += blockSizeArray[i-blockStart]; if (!err) { err = adios_perform_reads(f, 1); } else { printf("Unable to read block %d at timestep: %d \n", i, timestep); return; //break; } } processData(data, totalCount, rank, timestep, selName, ft, v); //processData(void* data, uint64_t dataCount, int rank, int timestep, char* selName, FastBitDataType ft, ADIOS_VARINFO* v) } // on multi block
eavlField * eavlXGCParticleImporter::GetField(const string &name, const string &mesh, int chunk) { int idx = 0; eavlField *field; uint64_t s[3], c[3]; map<string, ADIOS_VARINFO*>::const_iterator it; if(name.compare("ephase") == 0 && ephaseAvail) { eavlFloatArray *arr = new eavlFloatArray(name, 1); arr->SetNumberOfTuples(totalEParticles*9); for(it = ephase.begin(); it != ephase.end(); it++) { int nt = 1; ADIOS_SELECTION *sel; if(readingRestartFile) sel = MakeSelection(it->second, s, c); else sel = MakeLimitedSelection(it->second, s, c, 0); for(int i = 0; i < it->second->ndim; i++) nt *= c[i]; double *buff = new double[nt]; adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff); int retval = adios_perform_reads(fp, 1); adios_selection_delete(sel); for(int i = 0; i < nt; i++) { arr->SetComponentFromDouble(idx, 0, buff[i]); idx++; } delete [] buff; } field = new eavlField(1, arr, eavlField::ASSOC_POINTS); } else if(name.compare("iphase") == 0 && iphaseAvail) { eavlFloatArray *arr = new eavlFloatArray(name, 1); arr->SetNumberOfTuples(totalIParticles*9); for(it = iphase.begin(); it != iphase.end(); it++) { int nt = 1; ADIOS_SELECTION *sel; if(readingRestartFile) sel = MakeSelection(it->second, s, c); else sel = MakeLimitedSelection(it->second, s, c, 1); for (int i = 0; i < it->second->ndim; i++) nt *= c[i]; double *buff = new double[nt]; adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff); int retval = adios_perform_reads(fp, 1); adios_selection_delete(sel); for(int i = 0; i < nt; i++) { arr->SetComponentFromDouble(idx, 0, buff[i]); idx++; } delete [] buff; } field = new eavlField(1, arr, eavlField::ASSOC_POINTS); } else if(name.compare("igid") == 0 && iphaseAvail) { eavlIntArray *arr = new eavlIntArray(name, 1); arr->SetNumberOfTuples(totalIParticles); for(it = igid.begin(); it != igid.end(); it++) { int nt = 1; ADIOS_SELECTION *sel; if(readingRestartFile) sel = MakeSelection(it->second, s, c); else sel = MakeLimitedSelection(it->second, s, c, 1); for(int i = 0; i < it->second->ndim; i++) nt *= c[i]; long long *buff = new long long[nt]; adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff); int retval = adios_perform_reads(fp, 1); adios_selection_delete(sel); for(int i = 0; i < nt; i++) { arr->SetValue(idx, (int)buff[i]); idx++; } delete [] buff; } field = new eavlField(1, arr, eavlField::ASSOC_POINTS); } else if((name.compare("egid") == 0) && ephaseAvail ) { eavlIntArray *arr = new eavlIntArray(name, 1); arr->SetNumberOfTuples(totalEParticles); for (it = egid.begin(); it != egid.end(); it++) { int nt = 1; ADIOS_SELECTION *sel; if(readingRestartFile) sel = MakeSelection(it->second, s, c); else sel = MakeLimitedSelection(it->second, s, c, 0); for(int i = 0; i < it->second->ndim; i++) nt *= c[i]; long long *buff = new long long[nt]; adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff); int retval = adios_perform_reads(fp, 1); adios_selection_delete(sel); for(int i = 0; i < nt; i++) { arr->SetValue(idx, (int)buff[i]); idx++; } delete [] buff; } field = new eavlField(1, arr, eavlField::ASSOC_POINTS); } else { THROW(eavlException, string("Variable not found: ")+name); } return field; }
eavlDataSet * eavlXGCParticleImporter::GetMesh(const string &name, int chunk) { eavlDataSet *ds = new eavlDataSet; if(name == "iMesh" && iphaseAvail) { ds->SetNumPoints(totalIParticles); eavlCoordinatesCartesian *coords = new eavlCoordinatesCartesian(NULL, eavlCoordinatesCartesian::X, eavlCoordinatesCartesian::Y, eavlCoordinatesCartesian::Z); ds->AddCoordinateSystem(coords); coords->SetAxis(0, new eavlCoordinateAxisField("xcoords", 0)); coords->SetAxis(1, new eavlCoordinateAxisField("ycoords", 0)); coords->SetAxis(2, new eavlCoordinateAxisField("zcoords", 0)); eavlArray *axisValues[3] = { new eavlFloatArray("xcoords", 1), new eavlFloatArray("ycoords", 1), new eavlFloatArray("zcoords", 1) }; axisValues[0]->SetNumberOfTuples(totalIParticles); axisValues[1]->SetNumberOfTuples(totalIParticles); axisValues[2]->SetNumberOfTuples(totalIParticles); //Set all of the axis values to the x, y, z coordinates of the //iphase particles; set computational node origin eavlIntArray *originNode; if(getOriginNode && readingRestartFile) originNode = new eavlIntArray("originNode", 1, totalIParticles); eavlFloatArray *r; if(getR) r = new eavlFloatArray("R", 1, totalIParticles); eavlFloatArray *z; if(getZ) z = new eavlFloatArray("Z", 1, totalIParticles); eavlFloatArray *phi; if(getPhi) phi = new eavlFloatArray("phi", 1, totalIParticles); eavlFloatArray *rho; if(getRho) rho = new eavlFloatArray("rho", 1, totalIParticles); eavlFloatArray *w1; if(getW1) w1 = new eavlFloatArray("w1", 1, totalIParticles); eavlFloatArray *w2; if(getW2) w2 = new eavlFloatArray("w2", 1, totalIParticles); eavlFloatArray *mu; if(getMu) mu = new eavlFloatArray("mu", 1, totalIParticles); eavlFloatArray *w0; if(getW0) w0 = new eavlFloatArray("w0", 1, totalIParticles); eavlFloatArray *f0; if(getF0) f0 = new eavlFloatArray("f0", 1, totalIParticles); uint64_t s[3], c[3]; double *buff; int nt = 1, idx = 0; map<string, ADIOS_VARINFO*>::const_iterator it; for(it = iphase.begin(); it != iphase.end(); it++) { ADIOS_SELECTION *sel; if(readingRestartFile) sel = MakeSelection(it->second, s, c); else sel = MakeLimitedSelection(it->second, s, c, 1); nt = 1; for (int i = 0; i < it->second->ndim; i++) nt *= c[i]; buff = new double[nt]; adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff); adios_perform_reads(fp, 1); adios_selection_delete(sel); string nodeNum; if(getOriginNode && readingRestartFile) nodeNum = it->first.substr(it->first.find("_",1,1)+1, 5); for(int i = 0; i < nt; i+=9) { if(getR) r->SetValue(idx, buff[i]); if(getZ) z->SetValue(idx, buff[i+1]); if(getPhi) phi->SetValue(idx, buff[i+2]); if(getRho) rho->SetValue(idx, buff[i+3]); if(getW1) w1->SetValue(idx, buff[i+4]); if(getW2) w2->SetValue(idx, buff[i+5]); if(getMu) mu->SetValue(idx, buff[i+6]); if(getW0) w0->SetValue(idx, buff[i+7]); if(getF0) f0->SetValue(idx, buff[i+8]); axisValues[0]->SetComponentFromDouble(idx, 0, r->GetValue(idx)*cos(phi->GetValue(idx))); axisValues[1]->SetComponentFromDouble(idx, 0, r->GetValue(idx)*sin(phi->GetValue(idx))); axisValues[2]->SetComponentFromDouble(idx, 0, z->GetValue(idx)); if(getOriginNode && readingRestartFile) originNode->SetValue(idx, atoi(nodeNum.c_str())); idx++; } delete [] buff; } ds->AddField(new eavlField(1, axisValues[0], eavlField::ASSOC_POINTS)); ds->AddField(new eavlField(1, axisValues[1], eavlField::ASSOC_POINTS)); ds->AddField(new eavlField(1, axisValues[2], eavlField::ASSOC_POINTS)); if(getOriginNode && readingRestartFile) ds->AddField(new eavlField(1, originNode, eavlField::ASSOC_POINTS)); if(getR) ds->AddField(new eavlField(1, r, eavlField::ASSOC_POINTS)); if(getZ) ds->AddField(new eavlField(1, z, eavlField::ASSOC_POINTS)); if(getPhi) ds->AddField(new eavlField(1, phi, eavlField::ASSOC_POINTS)); if(getRho) ds->AddField(new eavlField(1, rho, eavlField::ASSOC_POINTS)); if(getW1) ds->AddField(new eavlField(1, w1, eavlField::ASSOC_POINTS)); if(getW2) ds->AddField(new eavlField(1, w2, eavlField::ASSOC_POINTS)); if(getMu) ds->AddField(new eavlField(1, mu, eavlField::ASSOC_POINTS)); if(getW0) ds->AddField(new eavlField(1, w0, eavlField::ASSOC_POINTS)); if(getF0) ds->AddField(new eavlField(1, f0, eavlField::ASSOC_POINTS)); eavlCellSet *cellSet = new eavlCellSetAllPoints(name + "_cells", totalIParticles); ds->AddCellSet(cellSet); //-- END set axis values //----Set the ids of all axis values idx = 0; long long *idBuff; eavlIntArray *axisIds = new eavlIntArray("id", 1, totalIParticles); for(it = igid.begin(); it != igid.end(); it++) { ADIOS_SELECTION *sel; if(readingRestartFile) sel = MakeSelection(it->second, s, c); else sel = MakeLimitedSelection(it->second, s, c, 1); nt = 1; for (int i = 0; i < it->second->ndim; i++) nt *= c[i]; idBuff = new long long[nt]; adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, idBuff); adios_perform_reads(fp, 1); adios_selection_delete(sel); for(int i = 0; i < nt; i++) { axisIds->SetValue(idx, (int)idBuff[i]); idx++; } delete [] idBuff; } ds->AddField(new eavlField(1, axisIds, eavlField::ASSOC_POINTS)); //-- END set ids } else if(name == "eMesh" && ephaseAvail) { ds->SetNumPoints(totalEParticles); eavlCoordinatesCartesian *coords = new eavlCoordinatesCartesian(NULL, eavlCoordinatesCartesian::X, eavlCoordinatesCartesian::Y, eavlCoordinatesCartesian::Z); ds->AddCoordinateSystem(coords); coords->SetAxis(0, new eavlCoordinateAxisField("xcoords", 0)); coords->SetAxis(1, new eavlCoordinateAxisField("ycoords", 0)); coords->SetAxis(2, new eavlCoordinateAxisField("zcoords", 0)); eavlArray *axisValues[3] = { new eavlFloatArray("xcoords", 1), new eavlFloatArray("ycoords", 1), new eavlFloatArray("zcoords", 1) }; axisValues[0]->SetNumberOfTuples(totalEParticles); axisValues[1]->SetNumberOfTuples(totalEParticles); axisValues[2]->SetNumberOfTuples(totalEParticles); //Set all of the axis values to the x, y, z coordinates of the //ephase particles; set computational node origin eavlIntArray *originNode; if(getOriginNode && readingRestartFile) originNode = new eavlIntArray("originNode", 1, totalIParticles); eavlFloatArray *r; if(getR) r = new eavlFloatArray("R", 1, totalIParticles); eavlFloatArray *z; if(getZ) z = new eavlFloatArray("Z", 1, totalIParticles); eavlFloatArray *phi; if(getPhi) phi = new eavlFloatArray("phi", 1, totalIParticles); eavlFloatArray *rho; if(getRho) rho = new eavlFloatArray("rho", 1, totalIParticles); eavlFloatArray *w1; if(getW1) w1 = new eavlFloatArray("w1", 1, totalIParticles); eavlFloatArray *w2; if(getW2) w2 = new eavlFloatArray("w2", 1, totalIParticles); eavlFloatArray *mu; if(getMu) mu = new eavlFloatArray("mu", 1, totalIParticles); eavlFloatArray *w0; if(getW0) w0 = new eavlFloatArray("w0", 1, totalIParticles); eavlFloatArray *f0; if(getF0) f0 = new eavlFloatArray("f0", 1, totalIParticles); uint64_t s[3], c[3]; int nt = 1, idx = 0; double *buff; map<string, ADIOS_VARINFO*>::const_iterator it; for(it = ephase.begin(); it != ephase.end(); it++) { ADIOS_SELECTION *sel; if(readingRestartFile) sel = MakeSelection(it->second, s, c); else sel = MakeLimitedSelection(it->second, s, c, 0); nt = 1; for(int i = 0; i < it->second->ndim; i++) nt *= c[i]; buff = new double[nt]; adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff); adios_perform_reads(fp, 1); adios_selection_delete(sel); string nodeNum; if(getOriginNode && readingRestartFile) nodeNum = it->first.substr(it->first.find("_",1,1)+1, 5); for(int i = 0; i < nt; i+=9) { if(getR) r->SetValue(idx, buff[i]); if(getZ) z->SetValue(idx, buff[i+1]); if(getPhi) phi->SetValue(idx, buff[i+2]); if(getRho) rho->SetValue(idx, buff[i+3]); if(getW1) w1->SetValue(idx, buff[i+4]); if(getW2) w2->SetValue(idx, buff[i+5]); if(getMu) mu->SetValue(idx, buff[i+6]); if(getW0) w0->SetValue(idx, buff[i+7]); if(getF0) f0->SetValue(idx, buff[i+8]); axisValues[0]->SetComponentFromDouble(idx, 0, r->GetValue(idx)*cos(phi->GetValue(idx))); axisValues[1]->SetComponentFromDouble(idx, 0, r->GetValue(idx)*sin(phi->GetValue(idx))); axisValues[2]->SetComponentFromDouble(idx, 0, z->GetValue(idx)); if(getOriginNode && readingRestartFile) originNode->SetValue(idx, atoi(nodeNum.c_str())); idx++; } delete [] buff; } ds->AddField(new eavlField(1, axisValues[0], eavlField::ASSOC_POINTS)); ds->AddField(new eavlField(1, axisValues[1], eavlField::ASSOC_POINTS)); ds->AddField(new eavlField(1, axisValues[2], eavlField::ASSOC_POINTS)); if(getOriginNode && readingRestartFile) ds->AddField(new eavlField(1, originNode, eavlField::ASSOC_POINTS)); if(getR) ds->AddField(new eavlField(1, r, eavlField::ASSOC_POINTS)); if(getZ) ds->AddField(new eavlField(1, z, eavlField::ASSOC_POINTS)); if(getPhi) ds->AddField(new eavlField(1, phi, eavlField::ASSOC_POINTS)); if(getRho) ds->AddField(new eavlField(1, rho, eavlField::ASSOC_POINTS)); if(getW1) ds->AddField(new eavlField(1, w1, eavlField::ASSOC_POINTS)); if(getW2) ds->AddField(new eavlField(1, w2, eavlField::ASSOC_POINTS)); if(getMu) ds->AddField(new eavlField(1, mu, eavlField::ASSOC_POINTS)); if(getW0) ds->AddField(new eavlField(1, w0, eavlField::ASSOC_POINTS)); if(getF0) ds->AddField(new eavlField(1, f0, eavlField::ASSOC_POINTS)); eavlCellSet *cellSet = new eavlCellSetAllPoints(name + "_cells", totalEParticles); ds->AddCellSet(cellSet); //-- END set axis values //----Set the ids of all axis values idx = 0; long long *idBuff; eavlIntArray *axisIds = new eavlIntArray("id", 1, totalEParticles); for(it = egid.begin(); it != egid.end(); it++) { ADIOS_SELECTION *sel; if(readingRestartFile) sel = MakeSelection(it->second, s, c); else sel = MakeLimitedSelection(it->second, s, c, 0); nt = 1; for (int i = 0; i < it->second->ndim; i++) nt *= c[i]; idBuff = new long long[nt]; adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, idBuff); adios_perform_reads(fp, 1); adios_selection_delete(sel); for(int i = 0; i < nt; i++) { axisIds->SetValue(idx, (int)idBuff[i]); idx++; } delete [] idBuff; } ds->AddField(new eavlField(1, axisIds, eavlField::ASSOC_POINTS)); } return ds; }
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); }
eavlDataSet *ReadPsiMesh(const string &filename) { MPI_Comm comm_dummy = 0; ADIOS_FILE *fp = adios_read_open_file(filename.c_str(), ADIOS_READ_METHOD_BP, comm_dummy); int nNodes = 0, nElems = 0, ptID = -1, elemID = -1; ADIOS_VARINFO *points = NULL, *cells = NULL, *psi; for (int i = 0; i < fp->nvars; i++) { ADIOS_VARINFO *avi = adios_inq_var_byid(fp, i); string varNm(&fp->var_namelist[i][1]); if (varNm == "n_t") { nElems = (int)(*(int *)avi->value); adios_free_varinfo(avi); } else if (varNm == "n_n") { nNodes = (int)(*(int *)avi->value); adios_free_varinfo(avi); } else if (varNm == "coordinates/values") points = avi; else if (varNm == "cell_set[0]/node_connect_list") cells = avi; else if (varNm == "psi") psi = avi; else adios_free_varinfo(avi); } cout<<"nNodes= "<<nNodes<<" nTri= "<<nElems<<endl; eavlDataSet *out = new eavlDataSet; out->SetNumPoints(nNodes); eavlCoordinatesCartesian *coords = new eavlCoordinatesCartesian(NULL, eavlCoordinatesCartesian::X, eavlCoordinatesCartesian::Y); out->AddCoordinateSystem(coords); coords->SetAxis(0, new eavlCoordinateAxisField("xcoords", 0)); coords->SetAxis(1, new eavlCoordinateAxisField("ycoords", 0)); eavlArray *axisValues[2] = {new eavlFloatArray("xcoords", 1), new eavlFloatArray("ycoords", 1)}; axisValues[0]->SetNumberOfTuples(nNodes); axisValues[1]->SetNumberOfTuples(nNodes); //read points. double *buff = new double[2*nNodes]; uint64_t s[3], c[3]; ADIOS_SELECTION *sel = MakeSelection(points, s, c); adios_schedule_read_byid(fp, sel, points->varid, 0, 1, buff); int retval = adios_perform_reads(fp, 1); adios_selection_delete(sel); adios_free_varinfo(points); for (int i = 0; i < nNodes; i++) { axisValues[0]->SetComponentFromDouble(i, 0, buff[i*2 +0]); axisValues[1]->SetComponentFromDouble(i, 0, buff[i*2 +1]); } out->AddField(new eavlField(1, axisValues[0], eavlField::ASSOC_POINTS)); out->AddField(new eavlField(1, axisValues[1], eavlField::ASSOC_POINTS)); delete [] buff; eavlCellSetExplicit *cellSet = new eavlCellSetExplicit("2D_cells", 2); eavlExplicitConnectivity conn; //read cells int *nodeList = new int[nElems*3]; sel = MakeSelection(cells, s, c); adios_schedule_read_byid(fp, sel, cells->varid, 0, 1, nodeList); retval = adios_perform_reads(fp, 1); adios_selection_delete(sel); int nodes[3]; for (int i = 0; i < nElems; i++) { nodes[0] = nodeList[i*3+0]; nodes[1] = nodeList[i*3+1]; nodes[2] = nodeList[i*3+2]; conn.AddElement(EAVL_TRI, 3, nodes); } delete [] nodeList; cellSet->SetCellNodeConnectivity(conn); out->AddCellSet(cellSet); //read psi. buff = new double[nNodes]; sel = MakeSelection(psi, s, c); adios_schedule_read_byid(fp, sel, psi->varid, 0, 1, buff); retval = adios_perform_reads(fp, 1); adios_selection_delete(sel); adios_free_varinfo(psi); eavlArray *psiValues = new eavlFloatArray("psi", 1); psiValues->SetNumberOfTuples(nNodes); for (int i = 0; i < nNodes; i++) psiValues->SetComponentFromDouble(i, 0, buff[i]); out->AddField(new eavlField(1, psiValues, eavlField::ASSOC_POINTS)); delete [] buff; return out; }
eavlDataSet * eavlXGCImporter::GetMesh(const string &name, int chunk) { eavlDataSet *ds = new eavlDataSet; if (name == "mesh2D") { ds->SetNumPoints(nNodes); eavlCoordinatesCartesian *coords = new eavlCoordinatesCartesian(NULL, eavlCoordinatesCartesian::X, eavlCoordinatesCartesian::Y); ds->AddCoordinateSystem(coords); coords->SetAxis(0, new eavlCoordinateAxisField("xcoords", 0)); coords->SetAxis(1, new eavlCoordinateAxisField("ycoords", 0)); eavlArray *axisValues[2] = {new eavlFloatArray("xcoords", 1), new eavlFloatArray("ycoords", 1)}; axisValues[0]->SetNumberOfTuples(nNodes); axisValues[1]->SetNumberOfTuples(nNodes); //read points double *buff = new double[2*nNodes]; uint64_t s[3], c[3]; ADIOS_SELECTION *sel = MakeSelection(points, s, c); adios_schedule_read_byid(mesh_fp, sel, points->varid, 0, 1, buff); int retval = adios_perform_reads(mesh_fp, 1); adios_selection_delete(sel); for (int i = 0; i < nNodes; i++) { axisValues[0]->SetComponentFromDouble(i, 0, buff[i*2 +0]); axisValues[1]->SetComponentFromDouble(i, 0, buff[i*2 +1]); } ds->AddField(new eavlField(1, axisValues[0], eavlField::ASSOC_POINTS)); ds->AddField(new eavlField(1, axisValues[1], eavlField::ASSOC_POINTS)); delete [] buff; eavlCellSetExplicit *cellSet = new eavlCellSetExplicit(name + "_Cells", 2); eavlExplicitConnectivity conn; //read cells int *nodeList = new int[nElems*3]; sel = MakeSelection(cells, s, c); adios_schedule_read_byid(mesh_fp, sel, cells->varid, 0, 1, nodeList); retval = adios_perform_reads(mesh_fp, 1); adios_selection_delete(sel); int nodes[3]; for (int i = 0; i < nElems; i++) { nodes[0] = nodeList[i*3+0]; nodes[1] = nodeList[i*3+1]; nodes[2] = nodeList[i*3+2]; conn.AddElement(EAVL_TRI, 3, nodes); } delete [] nodeList; cellSet->SetCellNodeConnectivity(conn); ds->AddCellSet(cellSet); } else if (name == "mesh3D") { int nPts = nNodes*nPlanes; ds->SetNumPoints(nPts); eavlCoordinatesCartesian *coords = new eavlCoordinatesCartesian(NULL, eavlCoordinatesCartesian::X, eavlCoordinatesCartesian::Y, eavlCoordinatesCartesian::Z); ds->AddCoordinateSystem(coords); coords->SetAxis(0, new eavlCoordinateAxisField("xcoords", 0)); coords->SetAxis(1, new eavlCoordinateAxisField("ycoords", 0)); coords->SetAxis(2, new eavlCoordinateAxisField("zcoords", 0)); eavlArray *axisValues[3] = {new eavlFloatArray("xcoords", 1), new eavlFloatArray("ycoords", 1), new eavlFloatArray("zcoords", 1)}; axisValues[0]->SetNumberOfTuples(nPts); axisValues[1]->SetNumberOfTuples(nPts); axisValues[2]->SetNumberOfTuples(nPts); //read points double *buff = new double[2*nNodes]; uint64_t s[3], c[3]; ADIOS_SELECTION *sel = MakeSelection(points, s, c); adios_schedule_read_byid(mesh_fp, sel, points->varid, 0, 1, buff); int retval = adios_perform_reads(mesh_fp, 1); adios_selection_delete(sel); int idx = 0; double dPhi = 2.0*M_PI/(double)nPlanes; //double dPhi = 2.0*M_PI/(double)32; for (int i = 0; i < nPlanes; i++) { double phi = (double)i * dPhi; for (int j = 0; j < nNodes; j++) { double R = buff[j*2 +0]; double Z = buff[j*2 +1]; axisValues[0]->SetComponentFromDouble(idx, 0, R*cos(phi)); axisValues[1]->SetComponentFromDouble(idx, 0, R*sin(phi)); axisValues[2]->SetComponentFromDouble(idx, 0, Z); idx++; } } ds->AddField(new eavlField(1, axisValues[0], eavlField::ASSOC_POINTS)); ds->AddField(new eavlField(1, axisValues[1], eavlField::ASSOC_POINTS)); ds->AddField(new eavlField(1, axisValues[2], eavlField::ASSOC_POINTS)); delete [] buff; eavlCellSetExplicit *cellSet = new eavlCellSetExplicit(name + "_Cells", 3); eavlExplicitConnectivity conn; //read cells int *nodeList = new int[nElems*3]; sel = MakeSelection(cells, s, c); adios_schedule_read_byid(mesh_fp, sel, cells->varid, 0, 1, nodeList); retval = adios_perform_reads(mesh_fp, 1); adios_selection_delete(sel); int nodes[6]; for (int i = 0; i < nPlanes; i++) { int cellCnt = 0; for (int j = 0; j < nElems*3; j+=3) { int off = i*nNodes; nodes[0] = nodeList[j+0] + off; nodes[1] = nodeList[j+1] + off; nodes[2] = nodeList[j+2] + off; off = ((i==nPlanes-1) ? 0 : (i+1)*nNodes); nodes[3] = nodeList[j+0] + off; nodes[4] = nodeList[j+1] + off; nodes[5] = nodeList[j+2] + off; conn.AddElement(EAVL_WEDGE, 6, nodes); } } delete [] nodeList; cellSet->SetCellNodeConnectivity(conn); ds->AddCellSet(cellSet); } //ds->PrintSummary(cout); return ds; }
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; }