Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous IO in BP5: Guided and Naive implementations. Guided uses… #2982

Merged
merged 3 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions bindings/C/adios2/c/adios2_c_adios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,44 @@ adios2_error adios2_finalize(adios2_adios *adios)
}
}

/** Inform ADIOS about entering communication-free computation block
* in main thread. Useful when using Async IO */
adios2_error adios2_enter_computation_block(adios2_adios *adios)
{
try
{
adios2::helper::CheckForNullptr(
adios,
"for adios2_adios, in call to adios2_enter_computation_block");
reinterpret_cast<adios2::core::ADIOS *>(adios)->EnterComputationBlock();
return adios2_error_none;
}
catch (...)
{
return static_cast<adios2_error>(
adios2::helper::ExceptionToError("adios2_enter_computation_block"));
}
}

/** Inform ADIOS about exiting communication-free computation block
* in main thread. Useful when using Async IO */
adios2_error adios2_exit_computation_block(adios2_adios *adios)
{
try
{
adios2::helper::CheckForNullptr(
adios,
"for adios2_adios, in call to adios2_exit_computation_block");
reinterpret_cast<adios2::core::ADIOS *>(adios)->ExitComputationBlock();
return adios2_error_none;
}
catch (...)
{
return static_cast<adios2_error>(
adios2::helper::ExceptionToError("adios2_exit_computation_block"));
}
}

#ifdef __cplusplus
}
// end extern C
Expand Down
8 changes: 8 additions & 0 deletions bindings/C/adios2/c/adios2_c_adios.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ adios2_error adios2_remove_io(adios2_bool *result, adios2_adios *adios,
*/
adios2_error adios2_remove_all_ios(adios2_adios *adios);

/** Inform ADIOS about entering communication-free computation block
* in main thread. Useful when using Async IO */
adios2_error adios2_enter_computation_block(adios2_adios *adios);

/** Inform ADIOS about exiting communication-free computation block
* in main thread. Useful when using Async IO */
adios2_error adios2_exit_computation_block(adios2_adios *adios);

#ifdef __cplusplus
} // end extern C
#endif
Expand Down
12 changes: 12 additions & 0 deletions bindings/CXX11/adios2/cxx11/ADIOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ void ADIOS::FlushAll()
m_ADIOS->FlushAll();
}

void ADIOS::EnterComputationBlock() noexcept
{
CheckPointer("in call to ADIOS::EnterComputationBlock()");
m_ADIOS->EnterComputationBlock();
}

void ADIOS::ExitComputationBlock() noexcept
{
CheckPointer("in call to ADIOS::ExitComputationBlock()");
m_ADIOS->ExitComputationBlock();
}

Operator ADIOS::DefineOperator(const std::string name, const std::string type,
const Params &parameters)
{
Expand Down
8 changes: 8 additions & 0 deletions bindings/CXX11/adios2/cxx11/ADIOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ class ADIOS
*/
void RemoveAllIOs() noexcept;

/** Inform ADIOS about entering communication-free computation block
* in main thread. Useful when using Async IO */
void EnterComputationBlock() noexcept;

/** Inform ADIOS about exiting communication-free computation block
* in main thread. Useful when using Async IO */
void ExitComputationBlock() noexcept;

protected:
std::shared_ptr<core::ADIOS> m_ADIOS;

Expand Down
14 changes: 14 additions & 0 deletions bindings/Fortran/f2c/adios2_f2c_adios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ void FC_GLOBAL(adios2_finalize_f2c, ADIOS2_FINALIZE_F2C)(adios2_adios **adios,
*ierr = static_cast<int>(adios2_finalize(*adios));
}

void FC_GLOBAL(adios2_enter_computation_block_f2c,
ADIOS2_ENTER_COMPUTATION_BLOCK_F2C)(adios2_adios **adios,
int *ierr)
{
*ierr = static_cast<int>(adios2_enter_computation_block(*adios));
}

void FC_GLOBAL(adios2_exit_computation_block_f2c,
ADIOS2_EXIT_COMPUTATION_BLOCK_F2C)(adios2_adios **adios,
int *ierr)
{
*ierr = static_cast<int>(adios2_exit_computation_block(*adios));
}

#ifdef __cplusplus
}
#endif
16 changes: 16 additions & 0 deletions bindings/Fortran/modules/adios2_adios_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module adios2_adios_mod
external adios2_remove_io_f2c
external adios2_remove_all_ios_f2c
external adios2_finalize_f2c
external adios2_enter_computation_block_f2c
external adios2_exit_computation_block_f2c
contains

subroutine adios2_declare_io(io, adios, io_name, ierr)
Expand Down Expand Up @@ -154,4 +156,18 @@ subroutine adios2_finalize(adios, ierr)

end subroutine


subroutine adios2_enter_computation_block(adios, ierr)
type(adios2_adios), intent(in) :: adios
integer, intent(out) :: ierr
call adios2_enter_computation_block_f2c(adios, ierr)
end subroutine

subroutine adios2_exit_computation_block(adios, ierr)
type(adios2_adios), intent(in) :: adios
integer, intent(out) :: ierr
call adios2_exit_computation_block_f2c(adios, ierr)
end subroutine


end module
8 changes: 8 additions & 0 deletions examples/basics/globalArray/globalArray_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
* Author: pnorbert
*/

#include <chrono>
#include <iostream>
#include <thread>
#include <vector>

#include <adios2.h>
Expand Down Expand Up @@ -64,7 +66,10 @@ int main(int argc, char *argv[])
// create one with default settings here
adios2::IO io = adios.DeclareIO("Output");
io.SetEngine("BP5");
io.SetParameter("AggregationType", "TwoLevelShm");
io.SetParameter("NumAggregators", "1");
io.SetParameter("NumSubFiles", "1");
io.SetParameter("AsyncWrite", "Guided");

/*
* Define global array: type, name, global dimensions
Expand Down Expand Up @@ -98,6 +103,9 @@ int main(int argc, char *argv[])
// Disk I/O will be performed during this call unless
// time aggregation postpones all of that to some later step
writer.EndStep();
adios.EnterComputationBlock();
std::this_thread::sleep_for(std::chrono::duration<double>(1.0));
adios.ExitComputationBlock();
}

// Called once: indicate that we are done with this output for the run
Expand Down
6 changes: 5 additions & 1 deletion source/adios2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ add_library(adios2_core

toolkit/transportman/TransportMan.cpp

toolkit/shm/Spinlock.cpp
toolkit/shm/SerializeProcesses.cpp
toolkit/shm/TokenChain.h

toolkit/aggregator/mpi/MPIAggregator.cpp
toolkit/aggregator/mpi/MPIChain.cpp
toolkit/aggregator/mpi/MPIShmChain.cpp
Expand Down Expand Up @@ -125,7 +129,7 @@ if (ADIOS2_HAVE_BP5)
target_sources(adios2_core PRIVATE
engine/bp5/BP5Engine.cpp
engine/bp5/BP5Reader.cpp engine/bp5/BP5Reader.tcc
engine/bp5/BP5Writer.cpp engine/bp5/BP5Writer.tcc engine/bp5/BP5Writer_TwoLevelShm.cpp
engine/bp5/BP5Writer.cpp engine/bp5/BP5Writer.tcc engine/bp5/BP5Writer_TwoLevelShm.cpp engine/bp5/BP5Writer_TwoLevelShm_Async.cpp engine/bp5/BP5Writer_EveryoneWrites_Async.cpp
)
endif()

Expand Down
4 changes: 2 additions & 2 deletions source/adios2/common/ADIOSTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ constexpr size_t DefaultMinDeferredSize = 4 * 1024 * 1024;
constexpr size_t DefaultMaxFileBatchSize = 2147381248;

/** default maximum shared memory segment size
* 128Mb */
constexpr uint64_t DefaultMaxShmSize = 128 * 1024 * 1024;
* 2 blocks of MaxFileBatchSize */
constexpr uint64_t DefaultMaxShmSize = 2 * DefaultMaxFileBatchSize;

constexpr char PathSeparator =
#ifdef _WIN32
Expand Down
21 changes: 21 additions & 0 deletions source/adios2/core/ADIOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ void ADIOS::FlushAll()
}
}

void ADIOS::EnterComputationBlock() noexcept
{
enteredComputationBlock = true;
for (auto &ioPair : m_IOs)
{
ioPair.second.EnterComputationBlock();
}
}

void ADIOS::ExitComputationBlock() noexcept
{
if (enteredComputationBlock)
{
enteredComputationBlock = false;
for (auto &ioPair : m_IOs)
{
ioPair.second.ExitComputationBlock();
}
}
}

std::pair<std::string, Params> &ADIOS::DefineOperator(const std::string &name,
const std::string type,
const Params &parameters)
Expand Down
12 changes: 12 additions & 0 deletions source/adios2/core/ADIOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "adios2/common/ADIOSConfig.h"
#include "adios2/common/ADIOSTypes.h"
#include "adios2/core/CoreTypes.h"
#include "adios2/core/Operator.h"
#include "adios2/helper/adiosComm.h"

Expand Down Expand Up @@ -145,6 +146,14 @@ class ADIOS
*/
void RemoveAllIOs() noexcept;

/** Inform ADIOS about entering communication-free computation block
* in main thread. Useful when using Async IO */
void EnterComputationBlock() noexcept;

/** Inform ADIOS about exiting communication-free computation block
* in main thread. Useful when using Async IO */
void ExitComputationBlock() noexcept;

private:
/** Communicator given to parallel constructor. */
helper::Comm m_Comm;
Expand All @@ -166,6 +175,9 @@ class ADIOS
/** operators created with DefineOperator */
std::unordered_map<std::string, std::pair<std::string, Params>> m_Operators;

/** Flag for Enter/ExitComputationBlock */
bool enteredComputationBlock = false;

void CheckOperator(const std::string name) const;

void XMLInit(const std::string &configFileXML);
Expand Down
3 changes: 3 additions & 0 deletions source/adios2/core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ size_t Engine::DebugGetDataBufferSize() const
return 0;
}

void Engine::EnterComputationBlock() noexcept {}
void Engine::ExitComputationBlock() noexcept {}

// PROTECTED
void Engine::Init() {}
void Engine::InitParameters() {}
Expand Down
5 changes: 5 additions & 0 deletions source/adios2/core/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,11 @@ class Engine
virtual void NotifyEngineAttribute(std::string name,
DataType type) noexcept;

/** Inform about computation block through User->ADIOS->IO */
virtual void EnterComputationBlock() noexcept;
/** Inform about computation block through User->ADIOS->IO */
virtual void ExitComputationBlock() noexcept;

protected:
/** from ADIOS class passed to Engine created with Open
* if no communicator is passed */
Expand Down
24 changes: 24 additions & 0 deletions source/adios2/core/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,30 @@ void IO::RemoveEngine(const std::string &name)
}
}

void IO::EnterComputationBlock() noexcept
{
for (auto &enginePair : m_Engines)
{
auto &engine = enginePair.second;
if (engine->OpenMode() != Mode::Read)
{
enginePair.second->EnterComputationBlock();
}
}
}

void IO::ExitComputationBlock() noexcept
{
for (auto &enginePair : m_Engines)
{
auto &engine = enginePair.second;
if (engine->OpenMode() != Mode::Read)
{
enginePair.second->ExitComputationBlock();
}
}
}

void IO::FlushAll()
{
PERFSTUBS_SCOPED_TIMER("IO::FlushAll");
Expand Down
6 changes: 6 additions & 0 deletions source/adios2/core/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "adios2/common/ADIOSTypes.h"
#include "adios2/core/ADIOS.h"
#include "adios2/core/Attribute.h"
#include "adios2/core/CoreTypes.h"
#include "adios2/core/Group.h"
#include "adios2/core/Variable.h"
#include "adios2/core/VariableCompound.h"
Expand Down Expand Up @@ -487,6 +488,11 @@ class IO
return m_Engines;
}

/** Inform about computation block through User->ADIOS */
void EnterComputationBlock() noexcept;
/** Inform about computation block through User->ADIOS */
void ExitComputationBlock() noexcept;

private:
/** true: exist in config file (XML) */
const bool m_InConfigFile = false;
Expand Down
4 changes: 2 additions & 2 deletions source/adios2/engine/bp3/BP3Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ void BP3Writer::InitTransports()

if (m_BP3Serializer.m_Aggregator.m_IsAggregator)
{
if (m_BP3Serializer.m_Parameters.AsyncTasks)
if (m_BP3Serializer.m_Parameters.AsyncOpen)
{
for (size_t i = 0; i < m_IO.m_TransportsParameters.size(); ++i)
{
m_IO.m_TransportsParameters[i]["asynctasks"] = "true";
m_IO.m_TransportsParameters[i]["asyncopen"] = "true";
}
}
m_FileDataManager.OpenFiles(bpSubStreamNames, m_OpenMode,
Expand Down
4 changes: 2 additions & 2 deletions source/adios2/engine/bp4/BP4Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ void BP4Writer::InitTransports()

if (m_BP4Serializer.m_Aggregator.m_IsAggregator)
{
if (m_BP4Serializer.m_Parameters.AsyncTasks)
if (m_BP4Serializer.m_Parameters.AsyncOpen)
{
for (size_t i = 0; i < m_IO.m_TransportsParameters.size(); ++i)
{
m_IO.m_TransportsParameters[i]["asynctasks"] = "true";
m_IO.m_TransportsParameters[i]["asyncopen"] = "true";
}
}
for (size_t i = 0; i < m_IO.m_TransportsParameters.size(); ++i)
Expand Down
Loading