Skip to content

Commit

Permalink
Replace macro hack with CRT pattern
Browse files Browse the repository at this point in the history
IDEs don't understand the macro thing and it keeps annoying me.
  • Loading branch information
franzpoeschel committed Sep 6, 2021
1 parent 78ac3f1 commit dda356b
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 151 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,13 @@ set(IO_ADIOS1_SEQUENTIAL_SOURCE
src/Error.cpp
src/auxiliary/Filesystem.cpp
src/ChunkInfo.cpp
src/IO/ADIOS/CommonADIOS1IOHandler.cpp
src/IO/ADIOS/ADIOS1IOHandler.cpp)
set(IO_ADIOS1_SOURCE
src/Error.cpp
src/auxiliary/Filesystem.cpp
src/ChunkInfo.cpp
src/IO/ADIOS/CommonADIOS1IOHandler.cpp
src/IO/ADIOS/ParallelADIOS1IOHandler.cpp)

# library
Expand Down
47 changes: 5 additions & 42 deletions include/openPMD/IO/ADIOS/ADIOS1IOHandlerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
#include "openPMD/IO/AbstractIOHandler.hpp"

#if openPMD_HAVE_ADIOS1
# include "openPMD/IO/AbstractIOHandlerImpl.hpp"
# include <adios_read.h>
# include "openPMD/IO/ADIOS/CommonADIOS1IOHandler.hpp"
#endif

#include <future>
Expand All @@ -41,8 +40,11 @@
namespace openPMD
{
#if openPMD_HAVE_ADIOS1
class OPENPMDAPI_EXPORT ADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
class OPENPMDAPI_EXPORT ADIOS1IOHandlerImpl
: public CommonADIOS1IOHandlerImpl< ADIOS1IOHandlerImpl >
{
private:
using Base_t = CommonADIOS1IOHandlerImpl< ADIOS1IOHandlerImpl >;
public:
ADIOS1IOHandlerImpl(AbstractIOHandler*);
virtual ~ADIOS1IOHandlerImpl();
Expand All @@ -51,48 +53,9 @@ namespace openPMD

std::future< void > flush() override;

void createFile(Writable*, Parameter< Operation::CREATE_FILE > const&) override;
void createPath(Writable*, Parameter< Operation::CREATE_PATH > const&) override;
void createDataset(Writable*, Parameter< Operation::CREATE_DATASET > const&) override;
void extendDataset(Writable*, Parameter< Operation::EXTEND_DATASET > const&) override;
void openFile(Writable*, Parameter< Operation::OPEN_FILE > const&) override;
void closeFile(Writable*, Parameter< Operation::CLOSE_FILE > const&) override;
void availableChunks(Writable*, Parameter< Operation::AVAILABLE_CHUNKS > &) override;
void openPath(Writable*, Parameter< Operation::OPEN_PATH > const&) override;
void openDataset(Writable*, Parameter< Operation::OPEN_DATASET > &) override;
void deleteFile(Writable*, Parameter< Operation::DELETE_FILE > const&) override;
void deletePath(Writable*, Parameter< Operation::DELETE_PATH > const&) override;
void deleteDataset(Writable*, Parameter< Operation::DELETE_DATASET > const&) override;
void deleteAttribute(Writable*, Parameter< Operation::DELETE_ATT > const&) override;
void writeDataset(Writable*, Parameter< Operation::WRITE_DATASET > const&) override;
void writeAttribute(Writable*, Parameter< Operation::WRITE_ATT > const&) override;
void readDataset(Writable*, Parameter< Operation::READ_DATASET > &) override;
void readAttribute(Writable*, Parameter< Operation::READ_ATT > &) override;
void listPaths(Writable*, Parameter< Operation::LIST_PATHS > &) override;
void listDatasets(Writable*, Parameter< Operation::LIST_DATASETS > &) override;
void listAttributes(Writable*, Parameter< Operation::LIST_ATTS > &) override;

virtual int64_t open_write(Writable *);
virtual ADIOS_FILE* open_read(std::string const & name);
void close(int64_t);
void close(ADIOS_FILE*);
int64_t initialize_group(std::string const& name);
void flush_attribute(int64_t group, std::string const& name, Attribute const&);

protected:
ADIOS_READ_METHOD m_readMethod;
std::unordered_map< Writable*, std::shared_ptr< std::string > > m_filePaths;
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_groups;
std::unordered_map< std::shared_ptr< std::string >, bool > m_existsOnDisk;
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_openWriteFileHandles;
std::unordered_map< std::shared_ptr< std::string >, ADIOS_FILE* > m_openReadFileHandles;
std::unordered_map< ADIOS_FILE*, std::vector< ADIOS_SELECTION* > > m_scheduledReads;
std::unordered_map< int64_t, std::unordered_map< std::string, Attribute > > m_attributeWrites;
/**
* Call this function to get adios file id for a Writable. Will create one if does not exist
* @return returns an adios file id.
*/
int64_t GetFileHandle(Writable*);
}; // ADIOS1IOHandlerImpl
#else
class OPENPMDAPI_EXPORT ADIOS1IOHandlerImpl
Expand Down
100 changes: 100 additions & 0 deletions include/openPMD/IO/ADIOS/CommonADIOS1IOHandler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* Copyright 2017-2021 Fabian Koller and Franz Poeschel
*
* This file is part of openPMD-api.
*
* openPMD-api is free software: you can redistribute it and/or modify
* it under the terms of of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* openPMD-api is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with openPMD-api.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include "openPMD/config.hpp"

#if openPMD_HAVE_ADIOS1

#include "openPMD/IO/AbstractIOHandler.hpp"
#include "openPMD/auxiliary/Filesystem.hpp"
#include "openPMD/auxiliary/DerefDynamicCast.hpp"
#include "openPMD/auxiliary/Memory.hpp"
#include "openPMD/auxiliary/StringManip.hpp"
#include "openPMD/IO/AbstractIOHandlerImpl.hpp"
#include "openPMD/IO/ADIOS/ADIOS1Auxiliary.hpp"
#include "openPMD/IO/ADIOS/ADIOS1FilePosition.hpp"

#include <adios.h>
#include <adios_read.h>

#include <future>
#include <memory>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>

namespace openPMD
{
template< typename ChildClass > // CRT pattern
class CommonADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
{
public:

void createFile(Writable*, Parameter< Operation::CREATE_FILE > const&) override;
void createPath(Writable*, Parameter< Operation::CREATE_PATH > const&) override;
void createDataset(Writable*, Parameter< Operation::CREATE_DATASET > const&) override;
void extendDataset(Writable*, Parameter< Operation::EXTEND_DATASET > const&) override;
void openFile(Writable*, Parameter< Operation::OPEN_FILE > const&) override;
void closeFile(Writable*, Parameter< Operation::CLOSE_FILE > const&) override;
void availableChunks(Writable*, Parameter< Operation::AVAILABLE_CHUNKS > &) override;
void openPath(Writable*, Parameter< Operation::OPEN_PATH > const&) override;
void openDataset(Writable*, Parameter< Operation::OPEN_DATASET > &) override;
void deleteFile(Writable*, Parameter< Operation::DELETE_FILE > const&) override;
void deletePath(Writable*, Parameter< Operation::DELETE_PATH > const&) override;
void deleteDataset(Writable*, Parameter< Operation::DELETE_DATASET > const&) override;
void deleteAttribute(Writable*, Parameter< Operation::DELETE_ATT > const&) override;
void writeDataset(Writable*, Parameter< Operation::WRITE_DATASET > const&) override;
void writeAttribute(Writable*, Parameter< Operation::WRITE_ATT > const&) override;
void readDataset(Writable*, Parameter< Operation::READ_DATASET > &) override;
void readAttribute(Writable*, Parameter< Operation::READ_ATT > &) override;
void listPaths(Writable*, Parameter< Operation::LIST_PATHS > &) override;
void listDatasets(Writable*, Parameter< Operation::LIST_DATASETS > &) override;
void listAttributes(Writable*, Parameter< Operation::LIST_ATTS > &) override;

void close(int64_t);
void close(ADIOS_FILE*);
void flush_attribute(int64_t group, std::string const& name, Attribute const&);

protected:
template< typename... Args >
CommonADIOS1IOHandlerImpl( Args &&... args)
: AbstractIOHandlerImpl{ std::forward< Args >( args )... }
{}

ADIOS_READ_METHOD m_readMethod;
std::unordered_map< Writable*, std::shared_ptr< std::string > > m_filePaths;
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_groups;
std::unordered_map< std::shared_ptr< std::string >, bool > m_existsOnDisk;
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_openWriteFileHandles;
std::unordered_map< std::shared_ptr< std::string >, ADIOS_FILE* > m_openReadFileHandles;
std::unordered_map< ADIOS_FILE*, std::vector< ADIOS_SELECTION* > > m_scheduledReads;
std::unordered_map< int64_t, std::unordered_map< std::string, Attribute > > m_attributeWrites;
/**
* Call this function to get adios file id for a Writable. Will create one if does not exist
* @return returns an adios file id.
*/
int64_t GetFileHandle(Writable*);
}; // ParallelADIOS1IOHandlerImpl
} // openPMD

#endif
46 changes: 5 additions & 41 deletions include/openPMD/IO/ADIOS/ParallelADIOS1IOHandlerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
#include "openPMD/IO/AbstractIOHandler.hpp"

#if openPMD_HAVE_ADIOS1 && openPMD_HAVE_MPI
# include "openPMD/IO/AbstractIOHandlerImpl.hpp"
# include <adios.h>
# include <adios_read.h>
# include "openPMD/IO/ADIOS/CommonADIOS1IOHandler.hpp"
#endif

#include <future>
Expand All @@ -42,8 +40,11 @@
namespace openPMD
{
#if openPMD_HAVE_ADIOS1 && openPMD_HAVE_MPI
class OPENPMDAPI_EXPORT ParallelADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
class OPENPMDAPI_EXPORT ParallelADIOS1IOHandlerImpl
: public CommonADIOS1IOHandlerImpl< ParallelADIOS1IOHandlerImpl >
{
private:
using Base_t = CommonADIOS1IOHandlerImpl< ParallelADIOS1IOHandlerImpl >;
public:
ParallelADIOS1IOHandlerImpl(AbstractIOHandler*, MPI_Comm);
virtual ~ParallelADIOS1IOHandlerImpl();
Expand All @@ -52,48 +53,11 @@ namespace openPMD

std::future< void > flush() override;

void createFile(Writable*, Parameter< Operation::CREATE_FILE > const&) override;
void createPath(Writable*, Parameter< Operation::CREATE_PATH > const&) override;
void createDataset(Writable*, Parameter< Operation::CREATE_DATASET > const&) override;
void extendDataset(Writable*, Parameter< Operation::EXTEND_DATASET > const&) override;
void openFile(Writable*, Parameter< Operation::OPEN_FILE > const&) override;
void closeFile(Writable*, Parameter< Operation::CLOSE_FILE > const&) override;
void availableChunks(Writable*, Parameter< Operation::AVAILABLE_CHUNKS > &) override;
void openPath(Writable*, Parameter< Operation::OPEN_PATH > const&) override;
void openDataset(Writable*, Parameter< Operation::OPEN_DATASET > &) override;
void deleteFile(Writable*, Parameter< Operation::DELETE_FILE > const&) override;
void deletePath(Writable*, Parameter< Operation::DELETE_PATH > const&) override;
void deleteDataset(Writable*, Parameter< Operation::DELETE_DATASET > const&) override;
void deleteAttribute(Writable*, Parameter< Operation::DELETE_ATT > const&) override;
void writeDataset(Writable*, Parameter< Operation::WRITE_DATASET > const&) override;
void writeAttribute(Writable*, Parameter< Operation::WRITE_ATT > const&) override;
void readDataset(Writable*, Parameter< Operation::READ_DATASET > &) override;
void readAttribute(Writable*, Parameter< Operation::READ_ATT > &) override;
void listPaths(Writable*, Parameter< Operation::LIST_PATHS > &) override;
void listDatasets(Writable*, Parameter< Operation::LIST_DATASETS > &) override;
void listAttributes(Writable*, Parameter< Operation::LIST_ATTS > &) override;

virtual int64_t open_write(Writable *);
virtual ADIOS_FILE* open_read(std::string const & name);
void close(int64_t);
void close(ADIOS_FILE*);
int64_t initialize_group(std::string const& name);
void flush_attribute(int64_t group, std::string const& name, Attribute const&);

protected:
ADIOS_READ_METHOD m_readMethod;
std::unordered_map< Writable*, std::shared_ptr< std::string > > m_filePaths;
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_groups;
std::unordered_map< std::shared_ptr< std::string >, bool > m_existsOnDisk;
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_openWriteFileHandles;
std::unordered_map< std::shared_ptr< std::string >, ADIOS_FILE* > m_openReadFileHandles;
std::unordered_map< ADIOS_FILE*, std::vector< ADIOS_SELECTION* > > m_scheduledReads;
std::unordered_map< int64_t, std::unordered_map< std::string, Attribute > > m_attributeWrites;
/**
* Call this function to get adios file id for a Writable. Will create one if does not exist
* @return returns an adios file id.
*/
int64_t GetFileHandle(Writable*);
MPI_Comm m_mpiComm;
MPI_Info m_mpiInfo;
}; // ParallelADIOS1IOHandlerImpl
Expand Down
1 change: 1 addition & 0 deletions include/openPMD/backend/Writable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Writable final
friend class ParticleSpecies;
friend class SeriesInterface;
friend class Record;
template< typename > friend class CommonADIOS1IOHandlerImpl;
friend class ADIOS1IOHandlerImpl;
friend class ParallelADIOS1IOHandlerImpl;
friend class ADIOS2IOHandlerImpl;
Expand Down
24 changes: 5 additions & 19 deletions src/IO/ADIOS/ADIOS1IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@
#include "openPMD/IO/ADIOS/ADIOS1IOHandlerImpl.hpp"

#if openPMD_HAVE_ADIOS1
# include "openPMD/auxiliary/Filesystem.hpp"
# include "openPMD/auxiliary/DerefDynamicCast.hpp"
# include "openPMD/auxiliary/Memory.hpp"
# include "openPMD/auxiliary/StringManip.hpp"
# include "openPMD/IO/AbstractIOHandlerImpl.hpp"
# include "openPMD/IO/ADIOS/ADIOS1Auxiliary.hpp"
# include "openPMD/IO/ADIOS/ADIOS1FilePosition.hpp"

# include "openPMD/IO/IOTask.hpp"
# include <adios.h>
# include <cstring>
# include <iostream>
# include <map>
# include <memory>
# include <string>
#endif
#include <utility>


namespace openPMD
Expand All @@ -47,7 +44,7 @@ namespace openPMD
# endif

ADIOS1IOHandlerImpl::ADIOS1IOHandlerImpl(AbstractIOHandler* handler)
: AbstractIOHandlerImpl(handler)
: Base_t(handler)
{ }

ADIOS1IOHandlerImpl::~ADIOS1IOHandlerImpl()
Expand Down Expand Up @@ -319,17 +316,6 @@ ADIOS1IOHandlerImpl::initialize_group(std::string const &name)
return group;
}

} // namespace openPMD

#ifndef DOXYGEN_SHOULD_SKIP_THIS
#define CommonADIOS1IOHandlerImpl ADIOS1IOHandlerImpl
#include "CommonADIOS1IOHandler.cpp"
#undef CommonADIOS1IOHandlerImpl
#endif

namespace openPMD
{

#else
ADIOS1IOHandler::ADIOS1IOHandler(std::string path, Access at)
: AbstractIOHandler(std::move(path), at)
Expand Down
Loading

0 comments on commit dda356b

Please sign in to comment.