Advice
This list is similar to the Advice sections for each chapter in The C++ Programming Language, Fourth Edition by Bjarne Stroustrup The goal is to provide specific advice and good practices about the use of ADIOS2 in other projects.
Use
MPI_COMM_SELFto run MPI compiled versions of ADIOS 2 in “serial” modeUse a runtime configuration file in the
ADIOSconstructor oradios2_initwhen targeting multiple enginesCheck object validity when developing (similar to
fstream):C++: operator bool
if(var) engine.Put(var, data);
C: NULL pointer
if(var) adios2_put(engine, var, data, adios2_mode_deferred);
- Python: v2
__nonzero__v3__bool__. Note: do not check for None object if(var) engine.Put(var, data);
- Python: v2
Fortran:
type%validif( adios%valid .eqv. .true. ) then adios2_declare_io(adios, io, "foo") end if
C++11 and Python: use
try-catch(try-exceptin Python) blocks to handle exceptions from ADIOS 2C++11: use fixed-width types (
int8_t,uint32_t) for portabilityDefine your data structure: set of variables and attributes before developing. Data hierarchies/models can be built on top of ADIOS 2.
Read the documentation for Supported Engines before targeting development for a particular engine
MPI development: many Engine functions are collective MPI operations. See MPI Collective Behavior by Engine for details.
Use Remove functions carefully. They create dangling objects/pointers.
Thread-safety: treat ADIOS 2 as NOT thread-safe. Either use a mutex or only handle I/O from a master thread. ADIOS 2 is about performance, adding I/O serial algorithm operations into a parallel execution block may reduce parallel portions from Amdahl’s Law.
Prefer the high-level Python and C++ APIs for simple tasks that do not require performance. The more familiar Write/Read overloads for File I/O return native data constructs (
std::vectorandnumpy arrays) immediately for a requested selection.openonly explores the metadata index.C++: prefer templates to
void*to increase compile-time safety. UseIO::InquireVariableType("variableName")andadios2::GetType<T>()to cast upfront to aVariable<T>. C++17 hasstd::anyas an alternative tovoid*. ADIOS 2 follows closely the STL model.Understand
PutandGetmemory contracts from EnginePrefer Put/Get
Deferredmode, treatSyncas a special modePut Span: create all spans in a step before populating them. Spans follow the same iterator invalidation rules asstd::vector, so usespan.data()to always keep the span pointer up-to-dateAlways populate data before calling
Putin deferred mode, and do not change it betweenPutandEndStep, orCloseNever call
PerformPutsright beforeEndStep. This was a code pattern that had no adverse effects with the BP3/4 file engines and is present in some older code, but was never beneficial.Use
BeginStepandEndStepto write code that is portable across all ADIOS 2 Engine types: file and streaming.Always use
Closefor every call toOpen.C, Fortran: always call
adios2_finalizefor every call toadios2_initto avoid memory leaks.Reminder: C++, C, Python: Row-Major, while Fortran: Column-Major. ADIOS 2 will handle interoperability between ordering. Remember that bpls : Inspecting Data is always a Row-Major reader so Fortran reader need to swap dimensions seen in bpls. bpls: (slow, …., fast) -> Fortran(fast,…,slow).
Fortran API: use the type members (
var%valid,var%name, etc.) to get extra type information.Fortran C interoperability: Fortran bindings support the majority of applications using Fortran 90. We currently don’t support the
ISO_C_BINDINGinteroperability module in Fortran 2003.Always keep the
IOobject self-contained keeping its own set ofVariables,AttributesandEngines. Do not combine Variables with multiple Engines or multiple modes, unless it’s 100% guaranteed to be safe in your program avoiding Variable access conflicts.Developers: explore the testing infrastructure
ADIOS2/testingin ADIOS 2 as a starting point for using ADIOS 2 in your own testing environment.Become a super-user of bpls : Inspecting Data to analyze datasets generated by ADIOS 2.