diff --git a/source/adios2/core/IO.cpp b/source/adios2/core/IO.cpp index 345ffae954..ea0c223be9 100644 --- a/source/adios2/core/IO.cpp +++ b/source/adios2/core/IO.cpp @@ -251,7 +251,7 @@ std::map IO::GetAvailableVariables() noexcept Variable &variable = *InquireVariable(name); \ variablesInfo[name]["AvailableStepsCount"] = \ helper::ValueToString(variable.m_AvailableStepsCount); \ - variablesInfo[name]["Shape"] = helper::VectorToCSV(variable.m_Shape); \ + variablesInfo[name]["Shape"] = helper::VectorToCSV(variable.Shape()); \ if (variable.m_SingleValue) \ { \ variablesInfo[name]["SingleValue"] = "true"; \ @@ -262,9 +262,9 @@ std::map IO::GetAvailableVariables() noexcept { \ variablesInfo[name]["SingleValue"] = "false"; \ variablesInfo[name]["Min"] = \ - helper::ValueToString(variable.m_Min); \ + helper::ValueToString(variable.Min()); \ variablesInfo[name]["Max"] = \ - helper::ValueToString(variable.m_Max); \ + helper::ValueToString(variable.Max()); \ } \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) diff --git a/source/adios2/core/Stream.tcc b/source/adios2/core/Stream.tcc index 63c0670f15..34a97d2abb 100644 --- a/source/adios2/core/Stream.tcc +++ b/source/adios2/core/Stream.tcc @@ -73,12 +73,9 @@ void Stream::Write(const std::string &name, const T *data, const Dims &shape, } else { - if (!shape.empty()) + if (!shape.empty() && !variable->m_SingleValue) { - if (!(shape.size() == 1 && shape.front() == adios2::LocalValueDim)) - { - variable->SetShape(shape); - } + variable->SetShape(shape); } if (!start.empty() && !count.empty()) diff --git a/source/adios2/core/Variable.h b/source/adios2/core/Variable.h index 1bdfbc03c6..5abbe7a68f 100644 --- a/source/adios2/core/Variable.h +++ b/source/adios2/core/Variable.h @@ -130,17 +130,17 @@ class Variable : public VariableBase size_t SubStreamsInfoSize(); - Dims Shape(const size_t step) const; + Dims Shape(const size_t step = adios2::EngineCurrentStep) const; Dims Count() const; size_t SelectionSize() const; - std::pair MinMax(const size_t step) const; + std::pair MinMax(const size_t step = adios2::DefaultSizeT) const; - T Min(const size_t step) const; + T Min(const size_t step = adios2::DefaultSizeT) const; - T Max(const size_t step) const; + T Max(const size_t step = adios2::DefaultSizeT) const; std::vector::Info>> AllStepsBlocksInfo() const; diff --git a/testing/adios2/bindings/python/CMakeLists.txt b/testing/adios2/bindings/python/CMakeLists.txt index 5992c14f6d..9c5cfd85f4 100644 --- a/testing/adios2/bindings/python/CMakeLists.txt +++ b/testing/adios2/bindings/python/CMakeLists.txt @@ -19,6 +19,8 @@ if(ADIOS2_HAVE_MPI) SCRIPT TestBPReadMultisteps.py) python_add_test(NAME PythonBPWriteRead2D ${test_parameters} SCRIPT TestBPWriteRead2D.py) + python_add_test(NAME PythonBPChangingShapeHighLevelAPI ${test_parameters} + SCRIPT TestBPChangingShapeHighLevelAPI.py) if (ADIOS2_HAVE_HDF5) python_add_test(NAME PythonBPWriteReadHighLevelAPI_HDF5 SCRIPT TestBPWriteTypesHighLevelAPI_HDF5.py) diff --git a/testing/adios2/bindings/python/TestBPChangingShapeHighLevelAPI.py b/testing/adios2/bindings/python/TestBPChangingShapeHighLevelAPI.py new file mode 100644 index 0000000000..3d6431bf24 --- /dev/null +++ b/testing/adios2/bindings/python/TestBPChangingShapeHighLevelAPI.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +# +# TestChangingShape.py +# +# Created on: April 2nd, 2019 +# Author: Jeremy Logan + +import numpy as np +from mpi4py import MPI +import adios2 + +comm = MPI.COMM_WORLD +rank = comm.Get_rank() +size = comm.Get_size() + +# Test data +nx = [10, 15] +data = [np.zeros(nx[0]), np.ones(nx[1])] +shape = [[size * nx[0]], [size * nx[1]]] +start = [[rank * nx[0]], [rank * nx[1]]] +count = [[nx[0]], [nx[1]]] + +# Write different sized arrays as separate steps +with adios2.open('out.bp', 'w', comm) as f: + f.write('z', data[0], shape[0], start[0], count[0], end_step=True) + f.write('z', data[1], shape[1], start[1], count[1], end_step=True) + +# Read back arrays +with adios2.open('out.bp', 'r', comm) as f: + for f_step in f: + shape_z = int(f_step.available_variables()['z']['Shape']) + print(shape_z) + assert(shape_z == int(shape[f_step.current_step()][0]))