Skip to content
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
3 changes: 3 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ CheckOptions:

- key: readability-qualified-auto.AllowedTypes
value: 'MPI_Comm'

- key: misc-include-cleaner.IgnoreHeaders
value: 'adios2/.*;bits/.*'
---

Disabled checks and reasons:
Expand Down
61 changes: 55 additions & 6 deletions include/bout/adios_object.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#if BOUT_HAS_ADIOS2

#include "bout/boutexception.hxx"

#include <adios2.h>
#include <memory>
#include <mpi.h>
Expand All @@ -36,14 +38,12 @@ IOPtr GetIOPtr(const std::string IOName);
class ADIOSStream {
public:
adios2::IO io;
adios2::Engine engine;
adios2::Variable<double> vTime;
adios2::Variable<int> vStep;
int adiosStep = 0;
bool isInStep = false; // true if BeginStep was called and EndStep was not yet called

/** create or return the ADIOSStream based on the target file name */
static ADIOSStream& ADIOSGetStream(const std::string& fname);
static ADIOSStream& ADIOSGetStream(const std::string& fname, adios2::Mode mode);

~ADIOSStream();

Expand Down Expand Up @@ -74,14 +74,63 @@ public:
return v;
}

auto engine() -> adios2::Engine& {
if (not engine_) {
engine_ = io.Open(fname, file_mode);
if (not engine_) {
throw BoutException("Could not open ADIOS file '{:s}' for writing", fname);
}
}
return engine_;
}

void beginStep() {
if (not isInStep) {
engine().BeginStep();
isInStep = true;
adiosStep = static_cast<int>(engine().CurrentStep());
}
}

void endStep() {
if (isInStep) {
engine().EndStep();
isInStep = false;
}
}

void finish() {
if (engine_) {
engine().EndStep();
engine().Close();
}
}

private:
ADIOSStream(const std::string fname) : fname(fname){};
ADIOSStream(const std::string& fname, adios2::Mode mode)
: fname(fname), file_mode(mode) {

ADIOSPtr adiosp = GetADIOSPtr();
std::string ioname = "write_" + fname;
try {
io = adiosp->AtIO(ioname);
} catch (const std::invalid_argument& e) {
io = adiosp->DeclareIO(ioname);
io.SetEngine("BP5");
}
};

std::string fname;
adios2::Mode file_mode;
adios2::Engine engine_;

/// true if BeginStep was called and EndStep was not yet called
bool isInStep = false;
};

/** Set user parameters for an IO group */
void ADIOSSetParameters(const std::string& input, const char delimKeyValue,
const char delimItem, adios2::IO& io);
void ADIOSSetParameters(const std::string& input, char delimKeyValue, char delimItem,
adios2::IO& io);

} // namespace bout

Expand Down
20 changes: 10 additions & 10 deletions src/sys/adios_object.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "bout/adios_object.hxx"
#include "bout/boutexception.hxx"

#include <exception>
#include <iostream>
#include <adios2.h>

#include <unordered_map>

namespace bout {
Expand Down Expand Up @@ -48,25 +48,25 @@ IOPtr GetIOPtr(const std::string IOName) {
}

ADIOSStream::~ADIOSStream() {
if (engine) {
if (engine_) {
if (isInStep) {
engine.EndStep();
engine_.EndStep();
isInStep = false;
}
engine.Close();
engine_.Close();
}
}

ADIOSStream& ADIOSStream::ADIOSGetStream(const std::string& fname) {
ADIOSStream& ADIOSStream::ADIOSGetStream(const std::string& fname, adios2::Mode mode) {
auto it = adiosStreams.find(fname);
if (it == adiosStreams.end()) {
it = adiosStreams.emplace(fname, ADIOSStream(fname)).first;
it = adiosStreams.emplace(fname, ADIOSStream(fname, mode)).first;
}
return it->second;
}

void ADIOSSetParameters(const std::string& input, const char delimKeyValue,
const char delimItem, adios2::IO& io) {
void ADIOSSetParameters(const std::string& input, char delimKeyValue, char delimItem,
adios2::IO& io) {
auto lf_Trim = [](std::string& input) {
input.erase(0, input.find_first_not_of(" \n\r\t")); // prefixing spaces
input.erase(input.find_last_not_of(" \n\r\t") + 1); // suffixing spaces
Expand All @@ -76,7 +76,7 @@ void ADIOSSetParameters(const std::string& input, const char delimKeyValue,
std::string parameter;
while (std::getline(inputSS, parameter, delimItem)) {
const size_t position = parameter.find(delimKeyValue);
if (position == parameter.npos) {
if (position == std::string::npos) {
throw BoutException("ADIOSSetParameters(): wrong format for IO parameter "
+ parameter + ", format must be key" + delimKeyValue
+ "value for each entry");
Expand Down
Loading
Loading