From b3066761c7fcbcfa5e90a500c29a559072888b66 Mon Sep 17 00:00:00 2001 From: William F Godoy Date: Tue, 17 Apr 2018 15:26:24 -0400 Subject: [PATCH] Added steps inspection subroutines in Fortran Added tests VariableBase StepsStart is 0 by default --- bindings/C/adios2/adios2_c_variable.h | 11 +++ bindings/fortran/f2c/adios2_f2c_variable.cpp | 36 +++++++ bindings/fortran/f2c/adios2_f2c_variable.h | 8 ++ .../fortran/modules/adios2_variable_mod.f90 | 31 ++++-- source/adios2/core/VariableBase.h | 2 +- .../bindings/fortran/TestBPWriteStep.f90 | 25 +++++ .../fortran/TestBPWriteTypesLocal.f90 | 96 ++++++++++++++++--- 7 files changed, 189 insertions(+), 20 deletions(-) diff --git a/bindings/C/adios2/adios2_c_variable.h b/bindings/C/adios2/adios2_c_variable.h index 84b2fbf4ae..3af57cad12 100644 --- a/bindings/C/adios2/adios2_c_variable.h +++ b/bindings/C/adios2/adios2_c_variable.h @@ -70,8 +70,19 @@ const size_t *adios2_variable_start(const adios2_variable *variable); */ const size_t *adios2_variable_count(const adios2_variable *variable); +/** + * Read API, get available steps start (e.g. in a file for a variable) + * @param variable + * @return available steps start + */ size_t adios2_variable_available_steps_start(const adios2_variable *variable); +/** + * Read API, get available steps count from available steps count + * (e.g. in a file for a variable). Not necessarily contiguous. + * @param variable + * @return available steps count + */ size_t adios2_variable_available_steps_count(const adios2_variable *variable); /** diff --git a/bindings/fortran/f2c/adios2_f2c_variable.cpp b/bindings/fortran/f2c/adios2_f2c_variable.cpp index 399235df2d..cdde738c29 100644 --- a/bindings/fortran/f2c/adios2_f2c_variable.cpp +++ b/bindings/fortran/f2c/adios2_f2c_variable.cpp @@ -99,6 +99,42 @@ void FC_GLOBAL(adios2_variable_shape_f2c, } } +void FC_GLOBAL(adios2_variable_available_steps_start_f2c, + adios2_variable_AVAILABLE_STEPS_START_F2C)( + const adios2_variable **variable, int64_t *steps_start, int *ierr) +{ + *ierr = 0; + try + { + *steps_start = static_cast( + adios2_variable_available_steps_start(*variable)); + } + catch (std::exception &e) + { + std::cerr << "ADIOS2 variable_available_steps_start: " << e.what() + << "\n"; + *ierr = -1; + } +} + +void FC_GLOBAL(adios2_variable_available_steps_count_f2c, + adios2_variable_AVAILABLE_STEPS_COUNT_F2C)( + const adios2_variable **variable, int64_t *steps_count, int *ierr) +{ + *ierr = 0; + try + { + *steps_count = static_cast( + adios2_variable_available_steps_count(*variable)); + } + catch (std::exception &e) + { + std::cerr << "ADIOS2 variable_available_steps_count: " << e.what() + << "\n"; + *ierr = -1; + } +} + void FC_GLOBAL(adios2_set_shape_f2c, ADIOS2_SET_SHAPE_F2C)(adios2_variable **variable, const int *ndims, const int64_t *shape, diff --git a/bindings/fortran/f2c/adios2_f2c_variable.h b/bindings/fortran/f2c/adios2_f2c_variable.h index fb49fe59f0..6396bbbc6c 100644 --- a/bindings/fortran/f2c/adios2_f2c_variable.h +++ b/bindings/fortran/f2c/adios2_f2c_variable.h @@ -38,6 +38,14 @@ void FC_GLOBAL(adios2_variable_shape_f2c, adios2_variable_SHAPE_F2C)(const adios2_variable **variable, int64_t *shape, int *ierr); +void FC_GLOBAL(adios2_variable_available_steps_start_f2c, + adios2_variable_AVAILABLE_STEPS_START_F2C)( + const adios2_variable **variable, int64_t *steps_start, int *ierr); + +void FC_GLOBAL(adios2_variable_available_steps_count_f2c, + adios2_variable_AVAILABLE_STEPS_COUNT_F2C)( + const adios2_variable **variable, int64_t *steps_count, int *ierr); + void FC_GLOBAL(adios2_set_shape_f2c, ADIOS2_SET_SHAPE_F2C)(adios2_variable **variable, const int *ndims, const int64_t *shape, diff --git a/bindings/fortran/modules/adios2_variable_mod.f90 b/bindings/fortran/modules/adios2_variable_mod.f90 index 3c78d08a83..2816773fb0 100644 --- a/bindings/fortran/modules/adios2_variable_mod.f90 +++ b/bindings/fortran/modules/adios2_variable_mod.f90 @@ -17,7 +17,7 @@ module adios2_variable !!< !! @param variable subroutine adios2_variable_name(variable, name, ierr) - integer(kind=8), intent(out) :: variable + integer(kind=8), intent(in) :: variable character(len=:), allocatable, intent(out) :: name integer, intent(out) :: ierr @@ -30,7 +30,7 @@ subroutine adios2_variable_name(variable, name, ierr) end subroutine subroutine adios2_variable_type(variable, type, ierr) - integer(kind=8), intent(out) :: variable + integer(kind=8), intent(in) :: variable integer, intent(out) :: type integer, intent(out) :: ierr @@ -42,7 +42,7 @@ subroutine adios2_variable_type(variable, type, ierr) end subroutine subroutine adios2_variable_ndims(variable, ndims, ierr) - integer(kind=8), intent(out) :: variable + integer(kind=8), intent(in) :: variable integer, intent(out) :: ndims integer, intent(out) :: ierr @@ -50,7 +50,7 @@ subroutine adios2_variable_ndims(variable, ndims, ierr) end subroutine subroutine adios2_variable_shape(variable, ndims, shape_dims, ierr) - integer(kind=8), intent(out) :: variable + integer(kind=8), intent(in) :: variable integer, intent(out) :: ndims integer(kind=8), dimension(:), allocatable, intent(out) :: shape_dims integer, intent(out) :: ierr @@ -61,8 +61,24 @@ subroutine adios2_variable_shape(variable, ndims, shape_dims, ierr) end subroutine + subroutine adios2_variable_available_steps_start(variable, steps_start, ierr) + integer(kind=8), intent(in) :: variable + integer(kind=8), intent(out) :: steps_start + integer, intent(out) :: ierr + + call adios2_variable_available_steps_start_f2c(variable, steps_start, ierr) + end subroutine + + subroutine adios2_variable_available_steps_count(variable, steps_count, ierr) + integer(kind=8), intent(in) :: variable + integer(kind=8), intent(out) :: steps_count + integer, intent(out) :: ierr + + call adios2_variable_available_steps_count_f2c(variable, steps_count, ierr) + end subroutine + subroutine adios2_set_shape(variable, ndims, shape_dims, ierr) - integer(kind=8), intent(out) :: variable + integer(kind=8), intent(in) :: variable integer, intent(in) :: ndims integer(kind=8), dimension(:), intent(in) :: shape_dims integer, intent(out) :: ierr @@ -72,7 +88,7 @@ subroutine adios2_set_shape(variable, ndims, shape_dims, ierr) subroutine adios2_set_selection(variable, ndims, start_dims, count_dims, & & ierr) - integer(kind=8), intent(out) :: variable + integer(kind=8), intent(in) :: variable integer, intent(in) :: ndims integer(kind=8), dimension(:), intent(in) :: start_dims integer(kind=8), dimension(:), intent(in) :: count_dims @@ -80,11 +96,10 @@ subroutine adios2_set_selection(variable, ndims, start_dims, count_dims, & call adios2_set_selection_f2c(variable, ndims, start_dims, count_dims, & ierr) - end subroutine subroutine adios2_set_step_selection(variable, step_start, step_count, ierr) - integer(kind=8), intent(out) :: variable + integer(kind=8), intent(in) :: variable integer(kind=8), intent(in) :: step_start integer(kind=8), intent(in) :: step_count integer, intent(out) :: ierr diff --git a/source/adios2/core/VariableBase.h b/source/adios2/core/VariableBase.h index 162c0008a1..f0a8c992af 100644 --- a/source/adios2/core/VariableBase.h +++ b/source/adios2/core/VariableBase.h @@ -65,7 +65,7 @@ class VariableBase /** Registered transforms */ std::vector m_OperatorsInfo; - size_t m_AvailableStepsStart = 1; + size_t m_AvailableStepsStart = 0; size_t m_AvailableStepsCount = 0; size_t m_StepsStart = 0; diff --git a/testing/adios2/bindings/fortran/TestBPWriteStep.f90 b/testing/adios2/bindings/fortran/TestBPWriteStep.f90 index 80c08c396f..66bf123bfc 100644 --- a/testing/adios2/bindings/fortran/TestBPWriteStep.f90 +++ b/testing/adios2/bindings/fortran/TestBPWriteStep.f90 @@ -13,6 +13,7 @@ program TestBPWriteTypes character(len=:), allocatable :: variable_name integer :: variable_type, ndims integer(kind=8), dimension(:), allocatable :: shape_in + integer(kind=8) :: steps_start, steps_count ! Launch MPI call MPI_Init(ierr) @@ -112,6 +113,10 @@ program TestBPWriteTypes call adios2_variable_shape(variables(1), ndims, shape_in, ierr) if (ndims /= 1) stop 'var_I8 ndims is not 1' if (shape_in(1) /= isize*inx) stop 'var_I8 shape_in read failed' + call adios2_variable_available_steps_start(variables(1), steps_start, ierr) + if (steps_start /= 0) stop 'var_I8 steps_start is not 0' + call adios2_variable_available_steps_count(variables(1), steps_count, ierr) + if (steps_count /= 3) stop 'var_I8 steps_count is not 3' call adios2_inquire_variable(variables(2), ioRead, "var_I16", ierr) call adios2_variable_name(variables(2), variable_name, ierr) @@ -121,6 +126,10 @@ program TestBPWriteTypes call adios2_variable_shape(variables(2), ndims, shape_in, ierr) if (ndims /= 1) stop 'var_I16 ndims is not 1' if (shape_in(1) /= isize*inx) stop 'var_I16 shape_in read failed' + call adios2_variable_available_steps_start(variables(2), steps_start, ierr) + if (steps_start /= 0) stop 'var_I16 steps_start is not 0' + call adios2_variable_available_steps_count(variables(2), steps_count, ierr) + if (steps_count /= 3) stop 'var_I16 steps_count is not 3' call adios2_inquire_variable(variables(3), ioRead, "var_I32", ierr) call adios2_variable_name(variables(3), variable_name, ierr) @@ -130,6 +139,10 @@ program TestBPWriteTypes call adios2_variable_shape(variables(3), ndims, shape_in, ierr) if (ndims /= 1) stop 'var_I32 ndims is not 1' if (shape_in(1) /= isize*inx) stop 'var_I32 shape_in read failed' + call adios2_variable_available_steps_start(variables(3), steps_start, ierr) + if (steps_start /= 0) stop 'var_I32 steps_start is not 0' + call adios2_variable_available_steps_count(variables(3), steps_count, ierr) + if (steps_count /= 3) stop 'var_I32 steps_count is not 3' call adios2_inquire_variable(variables(4), ioRead, "var_I64", ierr) call adios2_variable_name(variables(4), variable_name, ierr) @@ -139,6 +152,10 @@ program TestBPWriteTypes call adios2_variable_shape(variables(4), ndims, shape_in, ierr) if (ndims /= 1) stop 'var_I64 ndims is not 1' if (shape_in(1) /= isize*inx) stop 'var_I64 shape_in read failed' + call adios2_variable_available_steps_start(variables(4), steps_start, ierr) + if (steps_start /= 0) stop 'var_I64 steps_start is not 0' + call adios2_variable_available_steps_count(variables(4), steps_count, ierr) + if (steps_count /= 3) stop 'var_I64 steps_count is not 3' call adios2_inquire_variable(variables(5), ioRead, "var_R32", ierr) call adios2_variable_name(variables(5), variable_name, ierr) @@ -148,6 +165,10 @@ program TestBPWriteTypes call adios2_variable_shape(variables(5), ndims, shape_in, ierr) if (ndims /= 1) stop 'var_R32 ndims is not 1' if (shape_in(1) /= isize*inx) stop 'var_R32 shape_in read failed' + call adios2_variable_available_steps_start(variables(5), steps_start, ierr) + if (steps_start /= 0) stop 'var_R32 steps_start is not 0' + call adios2_variable_available_steps_count(variables(5), steps_count, ierr) + if (steps_count /= 3) stop 'var_R32 steps_count is not 3' call adios2_inquire_variable(variables(6), ioRead, "var_R64", ierr) call adios2_variable_name(variables(6), variable_name, ierr) @@ -157,6 +178,10 @@ program TestBPWriteTypes call adios2_variable_shape(variables(6), ndims, shape_in, ierr) if (ndims /= 1) stop 'var_R64 ndims is not 1' if (shape_in(1) /= isize*inx) stop 'var_R64 shape_in read failed' + call adios2_variable_available_steps_start(variables(6), steps_start, ierr) + if (steps_start /= 0) stop 'var_R64 steps_start is not 0' + call adios2_variable_available_steps_count(variables(6), steps_count, ierr) + if (steps_count /= 3) stop 'var_R64 steps_count is not 3' call adios2_close(bpReader, ierr) diff --git a/testing/adios2/bindings/fortran/TestBPWriteTypesLocal.f90 b/testing/adios2/bindings/fortran/TestBPWriteTypesLocal.f90 index 2959ef683a..88892643bc 100644 --- a/testing/adios2/bindings/fortran/TestBPWriteTypesLocal.f90 +++ b/testing/adios2/bindings/fortran/TestBPWriteTypesLocal.f90 @@ -13,6 +13,7 @@ program TestBPWriteTypes character(len=:), allocatable :: variable_name integer :: variable_type, ndims integer(kind=8), dimension(:), allocatable :: count_in + integer(kind=8) steps_start, steps_count ! Launch MPI call MPI_Init(ierr) @@ -79,18 +80,18 @@ program TestBPWriteTypes ! Open myVector_f.bp in write mode, this launches an engine call adios2_open(bpWriter, ioWrite, "ftypes_local.bp", adios2_mode_write, ierr) - ! Put array contents to bp buffer, based on var1 metadata - if (irank == 0) then - call adios2_put_deferred(bpWriter, variables(7), data_I8(1), ierr) - call adios2_put_deferred(bpWriter, variables(8), data_I16(1), ierr) - call adios2_put_deferred(bpWriter, variables(9), data_I32(1), ierr) - call adios2_put_deferred(bpWriter, variables(10), data_I64(1), ierr) - call adios2_put_deferred(bpWriter, variables(11), data_R32(1), ierr) - call adios2_put_deferred(bpWriter, variables(12), data_R64(1), ierr) - end if - do i = 1, 3 call adios2_begin_step(bpWriter, adios2_step_mode_append, 0.0, ierr) + + if (irank == 0 .and. i == 1) then + call adios2_put_deferred(bpWriter, variables(7), data_I8(1), ierr) + call adios2_put_deferred(bpWriter, variables(8), data_I16(1), ierr) + call adios2_put_deferred(bpWriter, variables(9), data_I32(1), ierr) + call adios2_put_deferred(bpWriter, variables(10), data_I64(1), ierr) + call adios2_put_deferred(bpWriter, variables(11), data_R32(1), ierr) + call adios2_put_deferred(bpWriter, variables(12), data_R64(1), ierr) + end if + call adios2_put_deferred(bpWriter, variables(1), data_I8, ierr) call adios2_put_deferred(bpWriter, variables(2), data_I16, ierr) call adios2_put_deferred(bpWriter, variables(3), data_I32, ierr) @@ -114,37 +115,110 @@ program TestBPWriteTypes if (variable_name /= 'var_I8') stop 'var_I8 not recognized' call adios2_variable_type(variables(1), variable_type, ierr) if (variable_type /= adios2_type_integer1) stop 'var_I8 type not recognized' + call adios2_variable_available_steps_start(variables(1), steps_start, ierr) + if (steps_start /= 0) stop 'var_I8 steps_start is not 0' + call adios2_variable_available_steps_count(variables(1), steps_count, ierr) + if (steps_count /= 3) stop 'var_I8 steps_count is not 3' + call adios2_inquire_variable(variables(2), ioRead, "var_I16", ierr) call adios2_variable_name(variables(2), variable_name, ierr) if (variable_name /= 'var_I16') stop 'var_I16 not recognized' call adios2_variable_type(variables(2), variable_type, ierr) if (variable_type /= adios2_type_integer2) stop 'var_I16 type not recognized' + call adios2_variable_available_steps_start(variables(2), steps_start, ierr) + if (steps_start /= 0) stop 'var_I16 steps_start is not 0' + call adios2_variable_available_steps_count(variables(2), steps_count, ierr) + if (steps_count /= 3) stop 'var_I16 steps_count is not 3' + call adios2_inquire_variable(variables(3), ioRead, "var_I32", ierr) call adios2_variable_name(variables(3), variable_name, ierr) if (variable_name /= 'var_I32') stop 'var_I32 not recognized' call adios2_variable_type(variables(3), variable_type, ierr) if (variable_type /= adios2_type_integer4) stop 'var_I32 type not recognized' + call adios2_variable_available_steps_start(variables(3), steps_start, ierr) + if (steps_start /= 0) stop 'var_I32 steps_start is not 0' + call adios2_variable_available_steps_count(variables(3), steps_count, ierr) + if (steps_count /= 3) stop 'var_I32 steps_count is not 3' call adios2_inquire_variable(variables(4), ioRead, "var_I64", ierr) call adios2_variable_name(variables(4), variable_name, ierr) if (variable_name /= 'var_I64') stop 'var_I64 not recognized' call adios2_variable_type(variables(4), variable_type, ierr) if (variable_type /= adios2_type_integer8) stop 'var_I64 type not recognized' + call adios2_variable_available_steps_start(variables(4), steps_start, ierr) + if (steps_start /= 0) stop 'var_I64 steps_start is not 0' + call adios2_variable_available_steps_count(variables(4), steps_count, ierr) + if (steps_count /= 3) stop 'var_I64 steps_count is not 3' call adios2_inquire_variable(variables(5), ioRead, "var_R32", ierr) call adios2_variable_name(variables(5), variable_name, ierr) if (variable_name /= 'var_R32') stop 'var_R32 not recognized' call adios2_variable_type(variables(5), variable_type, ierr) if (variable_type /= adios2_type_real) stop 'var_R32 type not recognized' - + call adios2_variable_available_steps_start(variables(5), steps_start, ierr) + if (steps_start /= 0) stop 'var_R32 steps_start is not 0' + call adios2_variable_available_steps_count(variables(5), steps_count, ierr) + if (steps_count /= 3) stop 'var_R32 steps_count is not 3' call adios2_inquire_variable(variables(6), ioRead, "var_R64", ierr) call adios2_variable_name(variables(6), variable_name, ierr) if (variable_name /= 'var_R64') stop 'var_R64 not recognized' call adios2_variable_type(variables(6), variable_type, ierr) if (variable_type /= adios2_type_dp) stop 'var_R64 type not recognized' + call adios2_variable_available_steps_start(variables(6), steps_start, ierr) + if (steps_start /= 0) stop 'var_R64 steps_start is not 0' + call adios2_variable_available_steps_count(variables(6), steps_count, ierr) + if (steps_count /= 3) stop 'var_R64 steps_count is not 3' + + call adios2_inquire_variable(variables(7), ioRead, "gvar_I8", ierr) + call adios2_variable_name(variables(7), variable_name, ierr) + if (variable_name /= 'gvar_I8') stop 'gvar_I8 not recognized' + call adios2_variable_available_steps_start(variables(7), steps_start, ierr) + if (steps_start /= 0) stop 'gvar_I8 steps_start is not 0' + call adios2_variable_available_steps_count(variables(7), steps_count, ierr) + if (steps_count /= 1) stop 'gvar_I8 steps_count is not 1' + + call adios2_inquire_variable(variables(8), ioRead, "gvar_I16", ierr) + call adios2_variable_name(variables(8), variable_name, ierr) + if (variable_name /= 'gvar_I16') stop 'gvar_I16 not recognized' + call adios2_variable_available_steps_start(variables(8), steps_start, ierr) + if (steps_start /= 0) stop 'gvar_I16 steps_start is not 0' + call adios2_variable_available_steps_count(variables(8), steps_count, ierr) + if (steps_count /= 1) stop 'gvar_I16 steps_count is not 1' + + call adios2_inquire_variable(variables(9), ioRead, "gvar_I32", ierr) + call adios2_variable_name(variables(9), variable_name, ierr) + if (variable_name /= 'gvar_I32') stop 'gvar_I32 not recognized' + call adios2_variable_available_steps_start(variables(9), steps_start, ierr) + if (steps_start /= 0) stop 'gvar_I32 steps_start is not 0' + call adios2_variable_available_steps_count(variables(9), steps_count, ierr) + if (steps_count /= 1) stop 'gvar_I32 steps_count is not 1' + + call adios2_inquire_variable(variables(10), ioRead, "gvar_I64", ierr) + call adios2_variable_name(variables(10), variable_name, ierr) + if (variable_name /= 'gvar_I64') stop 'gvar_I32 not recognized' + call adios2_variable_available_steps_start(variables(10), steps_start, ierr) + if (steps_start /= 0) stop 'gvar_I64 steps_start is not 0' + call adios2_variable_available_steps_count(variables(10), steps_count, ierr) + if (steps_count /= 1) stop 'gvar_I64 steps_count is not 1' + + call adios2_inquire_variable(variables(11), ioRead, "gvar_R32", ierr) + call adios2_variable_name(variables(11), variable_name, ierr) + if (variable_name /= 'gvar_R32') stop 'gvar_R32 not recognized' + call adios2_variable_available_steps_start(variables(11), steps_start, ierr) + if (steps_start /= 0) stop 'gvar_R32 steps_start is not 0' + call adios2_variable_available_steps_count(variables(11), steps_count, ierr) + if (steps_count /= 1) stop 'gvar_R32 steps_count is not 1' + + call adios2_inquire_variable(variables(12), ioRead, "gvar_R64", ierr) + call adios2_variable_name(variables(12), variable_name, ierr) + if (variable_name /= 'gvar_R64') stop 'gvar_R64 not recognized' + call adios2_variable_available_steps_start(variables(12), steps_start, ierr) + if (steps_start /= 0) stop 'gvar_R64 steps_start is not 0' + call adios2_variable_available_steps_count(variables(12), steps_count, ierr) + if (steps_count /= 1) stop 'gvar_R64 steps_count is not 1' call adios2_close(bpReader, ierr)