From 30aa4e6640b6633d4c8474de31466c21206baa20 Mon Sep 17 00:00:00 2001 From: Norbert Podhorszki Date: Fri, 15 Jul 2022 16:20:31 -0400 Subject: [PATCH 1/2] fix bpls: if minblockinfo is available, don't just still use allstepsblockinfo. Fixes listing e3sm bp5 file content. --- source/utils/bpls/bpls.cpp | 139 ++++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 64 deletions(-) diff --git a/source/utils/bpls/bpls.cpp b/source/utils/bpls/bpls.cpp index 5d1d187372..71d649ca17 100644 --- a/source/utils/bpls/bpls.cpp +++ b/source/utils/bpls/bpls.cpp @@ -3058,10 +3058,12 @@ Dims get_global_array_signature(core::Engine *fp, core::IO *io, if (minBlocks) { - delete minBlocks; for (size_t step = 0; step < nsteps; step++) { - minBlocks = fp->MinBlocksInfo(*variable, step); + if (step > 0) + { + minBlocks = fp->MinBlocksInfo(*variable, step); + } if (minBlocks->Shape) { for (size_t k = 0; k < ndim; k++) @@ -3083,34 +3085,36 @@ Dims get_global_array_signature(core::Engine *fp, core::IO *io, } delete minBlocks; } - return dims; } - const std::map> &indices = - variable->m_AvailableStepBlockIndexOffsets; - auto itStep = indices.begin(); - - for (size_t step = 0; step < nsteps; step++) + else { - const size_t absstep = itStep->first; - Dims d = variable->Shape(absstep - 1); - if (d.empty()) - { - continue; - } + const std::map> &indices = + variable->m_AvailableStepBlockIndexOffsets; + auto itStep = indices.begin(); - for (size_t k = 0; k < ndim; k++) + for (size_t step = 0; step < nsteps; step++) { - if (firstStep) + const size_t absstep = itStep->first; + Dims d = variable->Shape(absstep - 1); + if (d.empty()) { - dims[k] = d[k]; + continue; } - else if (dims[k] != d[k]) + + for (size_t k = 0; k < ndim; k++) { - dims[k] = 0; + if (firstStep) + { + dims[k] = d[k]; + } + else if (dims[k] != d[k]) + { + dims[k] = 0; + } } + firstStep = false; + ++itStep; } - firstStep = false; - ++itStep; } } return dims; @@ -3149,26 +3153,29 @@ std::pair get_local_array_signature(core::Engine *fp, firstBlock = false; } } - std::vector::BPInfo> blocks = - fp->BlocksInfo(*variable, fp->CurrentStep()); - if (!blocks.empty()) + else { - nblocks = blocks.size(); - bool firstBlock = true; - for (size_t j = 0; j < nblocks; j++) + std::vector::BPInfo> blocks = + fp->BlocksInfo(*variable, fp->CurrentStep()); + if (!blocks.empty()) { - for (size_t k = 0; k < ndim; k++) + nblocks = blocks.size(); + bool firstBlock = true; + for (size_t j = 0; j < nblocks; j++) { - if (firstBlock) - { - dims[k] = blocks[j].Count[k]; - } - else if (dims[k] != blocks[j].Count[k]) + for (size_t k = 0; k < ndim; k++) { - dims[k] = 0; + if (firstBlock) + { + dims[k] = blocks[j].Count[k]; + } + else if (dims[k] != blocks[j].Count[k]) + { + dims[k] = 0; + } } + firstBlock = false; } - firstBlock = false; } } } @@ -3184,14 +3191,16 @@ std::pair get_local_array_signature(core::Engine *fp, if (minBlocksInfo) { dims.resize(minBlocksInfo->Dims); - delete minBlocksInfo; size_t RelStep = 0; for (RelStep = 0; RelStep < variable->m_AvailableStepsCount; RelStep++) { - minBlocksInfo = fp->MinBlocksInfo(*variable, RelStep); + if (RelStep > 0) + { + minBlocksInfo = fp->MinBlocksInfo(*variable, RelStep); + } - auto coreBlocksInfo = minBlocksInfo->BlocksInfo; + auto &coreBlocksInfo = minBlocksInfo->BlocksInfo; if (firstStep) { nblocks = coreBlocksInfo.size(); @@ -3224,40 +3233,42 @@ std::pair get_local_array_signature(core::Engine *fp, firstStep = false; } } - - std::map::BPInfo>> - allblocks = fp->AllStepsBlocksInfo(*variable); - - for (auto &blockpair : allblocks) + else { - std::vector::BPInfo> &blocks = - blockpair.second; - const size_t blocksSize = blocks.size(); - if (firstStep) - { - nblocks = blocksSize; - } - else if (nblocks != blocksSize) - { - nblocks = 0; - } + std::map::BPInfo>> + allblocks = fp->AllStepsBlocksInfo(*variable); - for (size_t j = 0; j < blocksSize; j++) + for (auto &blockpair : allblocks) { - for (size_t k = 0; k < ndim; k++) + std::vector::BPInfo> + &blocks = blockpair.second; + const size_t blocksSize = blocks.size(); + if (firstStep) { - if (firstBlock) - { - dims[k] = blocks[j].Count[k]; - } - else if (dims[k] != blocks[j].Count[k]) + nblocks = blocksSize; + } + else if (nblocks != blocksSize) + { + nblocks = 0; + } + + for (size_t j = 0; j < blocksSize; j++) + { + for (size_t k = 0; k < ndim; k++) { - dims[k] = 0; + if (firstBlock) + { + dims[k] = blocks[j].Count[k]; + } + else if (dims[k] != blocks[j].Count[k]) + { + dims[k] = 0; + } } + firstBlock = false; } - firstBlock = false; + firstStep = false; } - firstStep = false; } } return std::make_pair(nblocks, dims); From e1762c3551268b73063e22691f5a34dc88ee7af4 Mon Sep 17 00:00:00 2001 From: Podhorszki Norbert Date: Mon, 18 Jul 2022 10:32:35 -0400 Subject: [PATCH 2/2] Fix bpls dumping local arrays from BP5 files. Also renamed WasLocalVar to WasLocalValue in source to better match its meaning. --- bindings/C/adios2/c/adios2_c_engine.cpp | 4 +- bindings/CXX11/adios2/cxx11/Variable.tcc | 2 +- .../basics/localArray/localArray_read.cpp | 1 - .../basics/localArray/localArray_write.cpp | 2 +- examples/basics/values/values_write.cpp | 3 +- source/adios2/common/ADIOSTypes.h | 2 +- .../toolkit/format/bp5/BP5Deserializer.cpp | 2 +- source/utils/bpls/bpls.cpp | 40 +++++++++++-------- 8 files changed, 32 insertions(+), 24 deletions(-) diff --git a/bindings/C/adios2/c/adios2_c_engine.cpp b/bindings/C/adios2/c/adios2_c_engine.cpp index d3be30149a..4dfc158dbb 100644 --- a/bindings/C/adios2/c/adios2_c_engine.cpp +++ b/bindings/C/adios2/c/adios2_c_engine.cpp @@ -649,7 +649,7 @@ adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine, auto *b = varinfo->BlocksInfo; varinfo->Dims = minBlocksInfo->Dims; - if (minBlocksInfo->WasLocalVar) + if (minBlocksInfo->WasLocalValue) { varinfo->Shape = (size_t *)malloc(sizeof(size_t)); varinfo->Shape[0] = (intptr_t)minBlocksInfo->Shape; @@ -670,7 +670,7 @@ adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine, { b[i].WriterID = minBlocksInfo->BlocksInfo[i].WriterID; b[i].BlockID = minBlocksInfo->BlocksInfo[i].BlockID; - if (minBlocksInfo->WasLocalVar) + if (minBlocksInfo->WasLocalValue) { b[i].Start = (size_t *)malloc(sizeof(size_t)); b[i].Start[0] = diff --git a/bindings/CXX11/adios2/cxx11/Variable.tcc b/bindings/CXX11/adios2/cxx11/Variable.tcc index c269d91c3b..e0cfd41e30 100644 --- a/bindings/CXX11/adios2/cxx11/Variable.tcc +++ b/bindings/CXX11/adios2/cxx11/Variable.tcc @@ -167,7 +167,7 @@ Variable::ToBlocksInfoMin(const MinVarInfo *coreVarInfo) const { blockInfo.Start.reserve(coreVarInfo->Dims); blockInfo.Count.reserve(coreVarInfo->Dims); - if (coreVarInfo->WasLocalVar) + if (coreVarInfo->WasLocalValue) { /* Start and count are really values, not pointers */ blockInfo.Start.push_back((size_t)coreBlockInfo.Start); diff --git a/examples/basics/localArray/localArray_read.cpp b/examples/basics/localArray/localArray_read.cpp index 93dc76b98f..c3c37cb108 100644 --- a/examples/basics/localArray/localArray_read.cpp +++ b/examples/basics/localArray/localArray_read.cpp @@ -119,7 +119,6 @@ int main(int argc, char *argv[]) * Inline uses single IO for write/read */ adios2::IO io = adios.DeclareIO("Input"); - io.SetEngine("BP3"); io.SetParameters({{"verbose", "4"}}); adios2::Engine reader = io.Open("localArray.bp", adios2::Mode::Read); diff --git a/examples/basics/localArray/localArray_write.cpp b/examples/basics/localArray/localArray_write.cpp index 257491908b..20c24077ef 100644 --- a/examples/basics/localArray/localArray_write.cpp +++ b/examples/basics/localArray/localArray_write.cpp @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) // Get io settings from the config file or // create one with default settings here adios2::IO io = adios.DeclareIO("Output"); - io.SetEngine("BP3"); + io.SetEngine("BP5"); io.SetParameters({{"verbose", "4"}}); /* diff --git a/examples/basics/values/values_write.cpp b/examples/basics/values/values_write.cpp index 99f27bb226..c8589520c3 100644 --- a/examples/basics/values/values_write.cpp +++ b/examples/basics/values/values_write.cpp @@ -65,7 +65,8 @@ int main(int argc, char *argv[]) // Get io settings from the config file or // create one with default settings here adios2::IO io = adios.DeclareIO("Output"); - + io.SetEngine("BP5"); + io.SetParameters({{"verbose", "4"}}); /* * Define variables */ diff --git a/source/adios2/common/ADIOSTypes.h b/source/adios2/common/ADIOSTypes.h index d3f3308e7e..3ef618865e 100644 --- a/source/adios2/common/ADIOSTypes.h +++ b/source/adios2/common/ADIOSTypes.h @@ -215,7 +215,7 @@ struct MinBlockInfo struct MinVarInfo { size_t Step; - bool WasLocalVar; + bool WasLocalValue; // writer: localValue -> reader: 1D global array int Dims; size_t *Shape; bool IsValue = false; diff --git a/source/adios2/toolkit/format/bp5/BP5Deserializer.cpp b/source/adios2/toolkit/format/bp5/BP5Deserializer.cpp index 5290e67081..c579759a69 100644 --- a/source/adios2/toolkit/format/bp5/BP5Deserializer.cpp +++ b/source/adios2/toolkit/format/bp5/BP5Deserializer.cpp @@ -1461,7 +1461,7 @@ MinVarInfo *BP5Deserializer::MinBlocksInfo(const VariableBase &Var, size_t Step) MV->IsReverseDims = ((MV->Dims > 1) && (m_WriterIsRowMajor != m_ReaderIsRowMajor)); - MV->WasLocalVar = (VarRec->OrigShapeID == ShapeID::LocalValue); + MV->WasLocalValue = (VarRec->OrigShapeID == ShapeID::LocalValue); if ((VarRec->OrigShapeID == ShapeID::LocalValue) || (VarRec->OrigShapeID == ShapeID::GlobalValue)) { diff --git a/source/utils/bpls/bpls.cpp b/source/utils/bpls/bpls.cpp index 71d649ca17..ae0fceb49c 100644 --- a/source/utils/bpls/bpls.cpp +++ b/source/utils/bpls/bpls.cpp @@ -3069,7 +3069,7 @@ Dims get_global_array_signature(core::Engine *fp, core::IO *io, for (size_t k = 0; k < ndim; k++) { size_t n = - (minBlocks->WasLocalVar + (minBlocks->WasLocalValue ? reinterpret_cast(minBlocks->Shape) : minBlocks->Shape[k]); if (firstStep) @@ -3291,8 +3291,8 @@ void print_decomp(core::Engine *fp, core::IO *io, core::Variable *variable) // first step if (minBlocksInfo) { - delete minBlocksInfo; size_t laststep = minBlocksInfo->Step; // used relative last step above + delete minBlocksInfo; int ndigits_nsteps = ndigits(laststep); if (variable->m_ShapeID == ShapeID::GlobalValue || variable->m_ShapeID == ShapeID::LocalValue) @@ -3381,18 +3381,18 @@ void print_decomp(core::Engine *fp, core::IO *io, core::Variable *variable) for (size_t k = 0; k < ndim; k++) { size_t c = - (minBlocksInfo->WasLocalVar + (minBlocksInfo->WasLocalValue ? reinterpret_cast(blocks[j].Count) : blocks[j].Count[k]); if (c) { - size_t s = - (minBlocksInfo->WasLocalVar - ? reinterpret_cast(blocks[j].Start) - : blocks[j].Start[k]); if (variable->m_ShapeID == ShapeID::GlobalArray) { + size_t s = (minBlocksInfo->WasLocalValue + ? reinterpret_cast( + blocks[j].Start) + : blocks[j].Start[k]); fprintf(outf, "%*zu:%*zu", ndigits_dims[k], s, ndigits_dims[k], s + c - 1); } @@ -3433,20 +3433,28 @@ void print_decomp(core::Engine *fp, core::IO *io, core::Variable *variable) fprintf(outf, "\n"); if (dump) { - if (minBlocksInfo->WasLocalVar) + Dims s, c; + if (variable->m_ShapeID == ShapeID::GlobalArray) { - readVarBlock( - fp, io, variable, RelStep, j, - {reinterpret_cast(blocks[j].Count)}, - {reinterpret_cast(blocks[j].Start)}); + if (minBlocksInfo->WasLocalValue) + { + c = {reinterpret_cast(blocks[j].Count)}; + s = {reinterpret_cast(blocks[j].Start)}; + } + else + { + c = Dims(blocks[j].Count, + blocks[j].Count + ndim); + s = Dims(blocks[j].Start, + blocks[j].Start + ndim); + } } else { - readVarBlock( - fp, io, variable, RelStep, j, - Dims(blocks[j].Count, blocks[j].Count + ndim), - Dims(blocks[j].Start, blocks[j].Start + ndim)); + c = Dims(blocks[j].Count, blocks[j].Count + ndim); + s = Dims(0, ndim); } + readVarBlock(fp, io, variable, RelStep, j, c, s); } } }