Skip to content

Commit

Permalink
Merge pull request #1003 from williamfgc/mem_sel
Browse files Browse the repository at this point in the history
Memory Selection, aka removing ghost cells at write, support
  • Loading branch information
williamfgc committed Nov 15, 2018
2 parents 7a33e0c + b7d0a98 commit 48e7e4e
Show file tree
Hide file tree
Showing 51 changed files with 2,769 additions and 139 deletions.
31 changes: 31 additions & 0 deletions bindings/C/c/adios2_c_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions bindings/C/c/adios2_c_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions bindings/CXX11/cxx11/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ namespace adios2
} \
\
template <> \
void Variable<T>::SetMemorySelection(const Box<Dims> &memorySelection) \
{ \
helper::CheckForNullptr(m_Variable, \
"in call to Variable<T>::SetMemorySelection"); \
m_Variable->SetMemorySelection(memorySelection); \
} \
\
template <> \
void Variable<T>::SetStepSelection(const Box<size_t> &stepSelection) \
{ \
helper::CheckForNullptr(m_Variable, \
Expand Down
18 changes: 18 additions & 0 deletions bindings/CXX11/cxx11/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ class Variable
*/
void SetSelection(const adios2::Box<adios2::Dims> &selection);

/**
* 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 memorySelection {memoryStart, memoryCount}
* <pre>
* memoryStart: 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 memoryStart = {1,1}
* memoryCount: local dimensions for the contiguous memory pointer
* passed at Put, e.g. if there is 1 ghost cell per dimension and
* variable.Count() = {Ny,Nx}, then memoryCount = {Ny+2,Nx+2}
* </pre>
*/
void SetMemorySelection(const adios2::Box<adios2::Dims> &memorySelection);

/**
* Sets a step selection modifying current startStep, countStep
* countStep is the number of steps from startStep point
Expand Down
4 changes: 3 additions & 1 deletion bindings/Fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ set(MODULES
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_io_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_io_define_variable_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_io_define_attribute_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_variable_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_engine_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_engine_begin_step_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_engine_put_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_engine_get_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_file_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_fwrite_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_fread_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_variable_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_variable_min_mod.f90
${CMAKE_CURRENT_SOURCE_DIR}/modules/adios2_variable_max_mod.f90
)

add_library(adios2_f ${MODULES} ${F2C})
Expand Down
30 changes: 16 additions & 14 deletions bindings/Fortran/f2c/adios2_f2c_FILE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ void FC_GLOBAL(adios2_fwrite_value_f2c,
const int *type, const void *data,
const int *end_step, int *ierr)
{
*ierr = adios2_fwrite(*fh, name, static_cast<adios2_type>(*type), data, 0,
nullptr, nullptr, nullptr,
static_cast<adios2_bool>(*end_step));
*ierr = static_cast<int>(adios2_fwrite(
*fh, name, static_cast<adios2_type>(*type), data, 0, nullptr, nullptr,
nullptr, static_cast<adios2_bool>(*end_step)));
}

void FC_GLOBAL(adios2_fwrite_f2c,
Expand Down Expand Up @@ -181,8 +181,9 @@ void FC_GLOBAL(adios2_fread_value_f2c,
"adios2_advance_no(0), in call to adios2_fread");
}

*ierr = adios2_fread(*fh, name, static_cast<adios2_type>(*type), data,
0, nullptr, nullptr);
*ierr = static_cast<int>(adios2_fread(*fh, name,
static_cast<adios2_type>(*type),
data, 0, nullptr, nullptr));
if (*end_step == 1)
{
if (adios2_fgets(*fh, *fh) == nullptr)
Expand Down Expand Up @@ -224,9 +225,10 @@ void FC_GLOBAL(adios2_fread_f2c,
const std::vector<std::size_t> countV =
adios2_Int64ToSizeTVector(count, *ndims);

*ierr = adios2_fread(*fh, name, static_cast<adios2_type>(*type), data,
static_cast<size_t>(*ndims), startV.data(),
countV.data());
*ierr = static_cast<int>(adios2_fread(
*fh, name, static_cast<adios2_type>(*type), data,
static_cast<size_t>(*ndims), startV.data(), countV.data()));

if (*end_step == 1)
{
if (adios2_fgets(*fh, *fh) == nullptr)
Expand Down Expand Up @@ -255,11 +257,11 @@ void FC_GLOBAL(adios2_fread_steps_f2c, adios2_FREAD_STEPS_F2C)(
const std::vector<std::size_t> countV =
adios2_Int64ToSizeTVector(count, *ndims);

*ierr = adios2_fread_steps(*fh, name, static_cast<adios2_type>(*type),
data, static_cast<std::size_t>(*ndims),
startV.data(), countV.data(),
static_cast<std::size_t>(*step_start),
static_cast<std::size_t>(*step_count));
*ierr = static_cast<int>(adios2_fread_steps(
*fh, name, static_cast<adios2_type>(*type), data,
static_cast<std::size_t>(*ndims), startV.data(), countV.data(),
static_cast<std::size_t>(*step_start),
static_cast<std::size_t>(*step_count)));
}
catch (std::exception &e)
{
Expand All @@ -272,7 +274,7 @@ void FC_GLOBAL(adios2_fread_steps_f2c, adios2_FREAD_STEPS_F2C)(
void FC_GLOBAL(adios2_fclose_f2c, adios2_FCLOSE_F2C)(adios2_FILE **fh,
int *ierr)
{
*ierr = adios2_fclose(*fh);
*ierr = static_cast<int>(adios2_fclose(*fh));
}

#ifdef __cplusplus
Expand Down
59 changes: 58 additions & 1 deletion bindings/Fortran/f2c/adios2_f2c_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -215,6 +256,22 @@ void FC_GLOBAL(adios2_set_operation_parameter_f2c,
}
}

void FC_GLOBAL(adios2_variable_min_f2c,
adios2_variable_MIN_F2C)(void *min,
const adios2_variable **variable,
int *ierr)
{
*ierr = static_cast<int>(adios2_variable_min(min, *variable));
}

void FC_GLOBAL(adios2_variable_max_f2c,
adios2_variable_MAX_F2C)(void *max,
const adios2_variable **variable,
int *ierr)
{
*ierr = static_cast<int>(adios2_variable_max(max, *variable));
}

#ifdef __cplusplus
}
#endif
2 changes: 2 additions & 0 deletions bindings/Fortran/modules/adios2_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module adios2
use adios2_adios_mod
use adios2_io_mod
use adios2_variable_mod
use adios2_variable_min_mod
use adios2_variable_max_mod
use adios2_engine_mod
use adios2_file_mod

Expand Down

0 comments on commit 48e7e4e

Please sign in to comment.