Skip to content

Commit

Permalink
Williamfgc refactor (#4)
Browse files Browse the repository at this point in the history
* fix more example code

* make Open explicit in ADIOS1 toolkit. Fix handling open mode

* fix OpenModeToString() to serve adios 1 API's needs as well
  • Loading branch information
pnorbert authored and williamfgc committed Jun 6, 2017
1 parent 735faa2 commit e8a8967
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
4 changes: 2 additions & 2 deletions source/adios2/engine/adios1/ADIOS1Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace adios
ADIOS1Writer::ADIOS1Writer(IO &io, const std::string &name,
const OpenMode openMode, MPI_Comm mpiComm)
: Engine("ADIOS1Writer", io, name, openMode, mpiComm),
m_ADIOS1(io.m_Name, name, openMode, mpiComm, io.m_DebugMode)
m_ADIOS1(io.m_Name, name, mpiComm, io.m_DebugMode)
{
m_EndMessage = " in call to ADIOS1Writer " + m_Name + " Open\n";
Init();
Expand All @@ -35,7 +35,7 @@ void ADIOS1Writer::Init()
{
InitParameters();
InitTransports();
m_ADIOS1.Open();
m_ADIOS1.Open(m_OpenMode);
}

#define declare_type(T) \
Expand Down
32 changes: 27 additions & 5 deletions source/adios2/helper/adiosType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,43 @@ size_t BytesFactor(const std::string units, const bool debugMode)
return factor;
}

std::string OpenModeToString(const OpenMode openMode) noexcept
std::string OpenModeToString(const OpenMode openMode,
const bool oneLetter) noexcept
{

std::string openModeString;

if (openMode == OpenMode::Write)
{
openModeString = "Write";
if (oneLetter)
{
openModeString = "w";
}
else
{
openModeString = "Write";
}
}
else if (openMode == OpenMode::Append)
{
openModeString = "Append";
if (oneLetter)
{
openModeString = "a";
}
else
{
openModeString = "Append";
}
}
else if (openMode == OpenMode::Read)
{
openModeString = "Read";
if (oneLetter)
{
openModeString = "r";
}
else
{
openModeString = "Read";
}
}
return openModeString;
}
Expand Down
6 changes: 4 additions & 2 deletions source/adios2/helper/adiosType.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ size_t BytesFactor(const std::string units, const bool debugMode);
/**
* Returns open mode as a string
* @param openMode from ADIOSTypes.h
* @return
* @param oneLetter if true returns a one letter version ("w", "a" or "r")
* @return string with open mode
*/
std::string OpenModeToString(const OpenMode openMode) noexcept;
std::string OpenModeToString(const OpenMode openMode,
const bool oneLetter = false) noexcept;
}

#include "adiosType.inl"
Expand Down
11 changes: 5 additions & 6 deletions source/adios2/toolkit/interop/adios1/ADIOS1Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ namespace interop
{

ADIOS1Common::ADIOS1Common(const std::string &groupName,
const std::string &fileName, const OpenMode openMode,
MPI_Comm mpiComm, const bool debugMode)
: m_GroupName(groupName), m_FileName(fileName),
m_OpenModeString(OpenModeToString(openMode)), m_MPIComm(mpiComm),
const std::string &fileName, MPI_Comm mpiComm,
const bool debugMode)
: m_GroupName(groupName), m_FileName(fileName), m_MPIComm(mpiComm),
m_DebugMode(debugMode)
{
Init();
Expand Down Expand Up @@ -126,10 +125,10 @@ void ADIOS1Common::InitTransports(
}
}

bool ADIOS1Common::Open()
bool ADIOS1Common::Open(const OpenMode openMode)
{
adios_open(&m_ADIOSFile, m_GroupName.c_str(), m_FileName.c_str(),
m_OpenModeString.c_str(), m_MPIComm);
OpenModeToString(openMode, true).c_str(), m_MPIComm);
if (adios_errno == err_no_error)
{
m_IsFileOpen = true;
Expand Down
5 changes: 2 additions & 3 deletions source/adios2/toolkit/interop/adios1/ADIOS1Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ class ADIOS1Common
ADIOS_ERRCODES m_ErrorNumber = static_cast<ADIOS_ERRCODES>(-1);

ADIOS1Common(const std::string &groupName, const std::string &fileName,
const OpenMode openMode, MPI_Comm mpiComm,
const bool debugMode);
MPI_Comm mpiComm, const bool debugMode);

~ADIOS1Common();

void InitParameters(const Params &parameters);
void InitTransports(const std::vector<Params> &transportsParameters);
bool Open(); // return true if file is opened
bool Open(const OpenMode openMode); // return true if file is opened
bool ReOpenAsNeeded(); // return true if file is open or reopened

template <class T>
Expand Down

0 comments on commit e8a8967

Please sign in to comment.