Skip to content

Commit

Permalink
Merge pull request #556 from williamfgc/f90_avail_steps
Browse files Browse the repository at this point in the history
Added steps inspection subroutines in Fortran
  • Loading branch information
pnorbert authored Apr 17, 2018
2 parents 1bcbfb2 + b306676 commit 6377b31
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 20 deletions.
11 changes: 11 additions & 0 deletions bindings/C/adios2/adios2_c_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
36 changes: 36 additions & 0 deletions bindings/fortran/f2c/adios2_f2c_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>(
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<int64_t>(
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,
Expand Down
8 changes: 8 additions & 0 deletions bindings/fortran/f2c/adios2_f2c_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 23 additions & 8 deletions bindings/fortran/modules/adios2_variable_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -42,15 +42,15 @@ 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

call adios2_variable_ndims_f2c(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
Expand All @@ -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
Expand All @@ -72,19 +88,18 @@ 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
integer, intent(out) :: ierr

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
Expand Down
2 changes: 1 addition & 1 deletion source/adios2/core/VariableBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class VariableBase
/** Registered transforms */
std::vector<OperatorInfo> m_OperatorsInfo;

size_t m_AvailableStepsStart = 1;
size_t m_AvailableStepsStart = 0;
size_t m_AvailableStepsCount = 0;

size_t m_StepsStart = 0;
Expand Down
25 changes: 25 additions & 0 deletions testing/adios2/bindings/fortran/TestBPWriteStep.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand Down
96 changes: 85 additions & 11 deletions testing/adios2/bindings/fortran/TestBPWriteTypesLocal.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 6377b31

Please sign in to comment.