Commit 2f0dd534 authored by William F Godoy's avatar William F Godoy
Browse files

Tests Fortran 2D and 3D memory selection

parent 0d36bc2e
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -107,6 +107,37 @@ adios2_error adios2_set_selection(adios2_variable *variable, const size_t ndims,
    }
}

adios2_error adios2_set_memory_selection(adios2_variable *variable,
                                         const size_t ndims,
                                         const size_t *memory_start,
                                         const size_t *memory_count)
{
    try
    {
        adios2::helper::CheckForNullptr(variable,
                                        "for adios2_variable, in call to "
                                        "adios2_set_memory_selection");
        adios2::helper::CheckForNullptr(memory_start,
                                        "for start, in call to "
                                        "adios2_set_memory_selection");
        adios2::helper::CheckForNullptr(memory_count,
                                        "for count, in call to "
                                        "adios2_set_memory_selection");
        adios2::core::VariableBase *variableBase =
            reinterpret_cast<adios2::core::VariableBase *>(variable);

        const adios2::Dims memoryStartV(memory_start, memory_start + ndims);
        const adios2::Dims memoryCountV(memory_count, memory_count + ndims);
        variableBase->SetMemorySelection({memoryStartV, memoryCountV});
        return adios2_error_none;
    }
    catch (...)
    {
        return static_cast<adios2_error>(
            adios2::helper::ExceptionToError("adios2_set_memory_selection"));
    }
}

adios2_error adios2_set_step_selection(adios2_variable *variable,
                                       const size_t step_start,
                                       const size_t step_count)
+21 −0
Original line number Diff line number Diff line
@@ -30,6 +30,27 @@ extern "C" {
adios2_error adios2_set_selection(adios2_variable *variable, const size_t ndims,
                                  const size_t *start, const size_t *count);

/**
 * Set the local start (offset) point to the memory pointer passed at Put
 * and the memory local dimensions (count). Used for non-contiguous memory
 * writes and reads (e.g. multidimensional ghost-cells).
 * Currently not working for calls to Get.
 * @param variable handler for which new memory selection will be applied to
 * @param ndims number of dimensions for memory_start and memory_count
 * @param memory_start relative local offset of variable.start to the
 * contiguous memory pointer passed at Put from which data starts. e.g. if
 * variable start = {rank*Ny,0} and there is 1 ghost cell per dimension,
 * then memory_start = {1,1}
 * @param memory_count local dimensions for the contiguous memory pointer
 * passed at adios2_put, e.g. if there is 1 ghost cell per dimension and
 * variable count = {Ny,Nx}, then memory_count = {Ny+2,Nx+2}
 * @return adios2_error 0: success, see enum adios2_error for errors
 */
adios2_error adios2_set_memory_selection(adios2_variable *variable,
                                         const size_t ndims,
                                         const size_t *memory_start,
                                         const size_t *memory_count);

/**
 * Set new step selection using step_start and step_count. Used mostly for
 * reading from file-based engines (e.g. bpfile, hdf5)
+42 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ void FC_GLOBAL(adios2_set_selection_f2c,

        output.resize(size);

        for (unsigned int d = 0; d < size; ++d)
        for (auto d = 0; d < size; ++d)
        {
            output[d] = dimensions[d];
        }
@@ -135,6 +135,47 @@ void FC_GLOBAL(adios2_set_selection_f2c,
    }
}

void FC_GLOBAL(adios2_set_memory_selection_f2c,
               ADIOS2_SET_MEMORY_SELECTION_F2C)(adios2_variable **variable,
                                                const int *ndims,
                                                const int64_t *memory_start,
                                                const int64_t *memory_count,
                                                int *ierr)
{
    auto lf_IntToSizeT = [](const int64_t *dimensions, const int size,
                            std::vector<std::size_t> &output) {

        output.resize(size);

        for (auto d = 0; d < size; ++d)
        {
            output[d] = dimensions[d];
        }

    };

    try
    {
        if (memory_start == nullptr || memory_count == nullptr ||
            ndims == nullptr)
        {
            throw std::invalid_argument("ERROR: either start_dims, count_dims "
                                        "or ndims is a null pointer, in call "
                                        "to adios2_set_memory_selection\n");
        }
        std::vector<std::size_t> memoryStartV, memoryCountV;
        lf_IntToSizeT(memory_start, *ndims, memoryStartV);
        lf_IntToSizeT(memory_count, *ndims, memoryCountV);
        *ierr = static_cast<int>(adios2_set_memory_selection(
            *variable, *ndims, memoryStartV.data(), memoryCountV.data()));
    }
    catch (...)
    {
        *ierr = static_cast<int>(
            adios2::helper::ExceptionToError("adios2_set_memory_selection"));
    }
}

void FC_GLOBAL(adios2_set_step_selection_f2c,
               ADIOS2_SET_STEP_SELECTION_F2C)(adios2_variable **variable,
                                              const int64_t *step_start,
+15 −0
Original line number Diff line number Diff line
@@ -81,6 +81,21 @@ contains
                                      count_dims, ierr)
    end subroutine

    subroutine adios2_set_memory_selection(variable, ndims, &
                                           memory_start_dims, &
                                           memory_count_dims, &
                                           ierr)
        type(adios2_variable), intent(in) :: variable
        integer, intent(in) :: ndims
        integer(kind=8), dimension(:), intent(in) :: memory_start_dims
        integer(kind=8), dimension(:), intent(in) :: memory_count_dims
        integer, intent(out) :: ierr

        call adios2_set_memory_selection_f2c(variable%f2c, ndims, &
                                             memory_start_dims, &
                                             memory_count_dims, ierr)
    end subroutine

    subroutine adios2_set_step_selection(variable, step_start, step_count, ierr)
        type(adios2_variable), intent(in) :: variable
        integer(kind=8), intent(in) :: step_start
+14 −0
Original line number Diff line number Diff line
@@ -65,6 +65,12 @@ if(ADIOS2_HAVE_MPI)
  add_executable(TestBPReadGlobalsByName_f TestBPReadGlobalsByName.f90)
  target_link_libraries(TestBPReadGlobalsByName_f adios2_f MPI::MPI_Fortran)
  
  add_executable(TestBPMemorySelection2D_f TestBPWriteMemorySelectionRead2D.f90)
  target_link_libraries(TestBPMemorySelection2D_f adios2_f MPI::MPI_Fortran)
  
  add_executable(TestBPMemorySelection3D_f TestBPWriteMemorySelectionRead3D.f90)
  target_link_libraries(TestBPMemorySelection3D_f adios2_f MPI::MPI_Fortran)
  
  # F2C 
  add_executable(TestBPReadFBlocks_f2c TestF2C_BPReadFBlocks.cpp)
  target_link_libraries(TestBPReadFBlocks_f2c adios2 gtest MPI::MPI_C)
@@ -162,6 +168,14 @@ if(ADIOS2_HAVE_MPI)
    )
  endif()
  
  add_test(NAME BPMemorySelection2D_f
    COMMAND ${test_parameters} $<TARGET_FILE:TestBPMemorySelection2D_f>
  )
  
  add_test(NAME BPMemorySelection3D_f
    COMMAND ${test_parameters} $<TARGET_FILE:TestBPMemorySelection3D_f>
  )
  
else()
  
  target_sources(TestBPWriteReadTypes_f PRIVATE TestBPWriteTypes_nompi.f90)
Loading