diff --git a/source/adios2/capsule/heap/STLVector.cpp b/source/adios2/capsule/heap/STLVector.cpp index 2b6b9a289fcded2c1cc3fddcd36673befd82fe87..9893948669be5570d12044e9fbf32b968603d3fd 100644 --- a/source/adios2/capsule/heap/STLVector.cpp +++ b/source/adios2/capsule/heap/STLVector.cpp @@ -2,37 +2,38 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * Heap.cpp + * STLVector.cpp * * Created on: Dec 22, 2016 * Author: wfg */ -#include "STLVector.h" - +/// \cond EXCLUDE_FROM_DOXYGEN #include <new> //std::bad_alloc #include <stdexcept> //std::runtime_error +/// \endcond + +#include "STLVector.h" namespace adios { namespace capsule { -STLVector::STLVector(std::string accessMode, int rankMPI, bool debugMode) -: Capsule{"Heap", std::move(accessMode), rankMPI, debugMode} +STLVector::STLVector(const bool debugMode) +: Capsule("heap/STLVector", debugMode) { - m_Data.reserve(16777216); } char *STLVector::GetData() { return m_Data.data(); } char *STLVector::GetMetadata() { return m_Metadata.data(); } -std::size_t STLVector::GetDataSize() const { return m_Data.size(); } +size_t STLVector::GetDataSize() const { return m_Data.size(); } -std::size_t STLVector::GetMetadataSize() const { return m_Metadata.size(); } +size_t STLVector::GetMetadataSize() const { return m_Metadata.size(); } -void STLVector::ResizeData(const std::size_t size) +void STLVector::ResizeData(const size_t size) { if (m_DebugMode == true) { @@ -53,7 +54,7 @@ void STLVector::ResizeData(const std::size_t size) } } -void STLVector::ResizeMetadata(const std::size_t size) +void STLVector::ResizeMetadata(const size_t size) { if (m_DebugMode == true) { diff --git a/source/adios2/capsule/heap/STLVector.h b/source/adios2/capsule/heap/STLVector.h index aaa7bd095cedb6d252c7d7ec1d7c28787613a0dd..ae00013690608e90a87597a6a52185ad08a8c0c1 100644 --- a/source/adios2/capsule/heap/STLVector.h +++ b/source/adios2/capsule/heap/STLVector.h @@ -30,31 +30,27 @@ class STLVector : public Capsule { public: - std::vector<char> m_Data; ///< data buffer allocated using the STL in heap - /// memory, default size = 16 Mb - std::vector<char> - m_Metadata; ///< metadata buffer allocated using the STL in - /// heap memory, default size = 100 Kb + /** data buffer allocated using the STL in heap */ + std::vector<char> m_Data; + /** might be used in cases other than files */ + std::vector<char> m_Metadata; /** * Unique constructor - * @param accessMode read, write or append - * @param rankMPI MPI rank - * @param debugMode true: extra checks, slower + * @param debugMode true: exceptions checks */ - STLVector(const std::string accessMode, const int rankMPI, - const bool debugMode = false); + STLVector(const bool debugMode = false); ~STLVector() = default; char *GetData(); char *GetMetadata(); - std::size_t GetDataSize() const; - std::size_t GetMetadataSize() const; + size_t GetDataSize() const; + size_t GetMetadataSize() const; - void ResizeData(const std::size_t size); - void ResizeMetadata(const std::size_t size); + void ResizeData(const size_t size); + void ResizeMetadata(const size_t size); }; } // end namespace capsule diff --git a/source/adios2/capsule/shmem/ShmSystemV.cpp b/source/adios2/capsule/shmem/ShmSystemV.cpp index c241b6eab36ecd106ab9feec7df510320e31c570..b9c78211c7921cb367c4537722d660475b78e8ec 100644 --- a/source/adios2/capsule/shmem/ShmSystemV.cpp +++ b/source/adios2/capsule/shmem/ShmSystemV.cpp @@ -8,35 +8,37 @@ * Author: wfg */ -#include "ShmSystemV.h" - #include <sys/shm.h> +/// \cond EXCLUDE_FROM_DOXYGEN #include <ios> //std::ios_base::failure #include <utility> +/// \endcond + +#include "ShmSystemV.h" namespace adios { -ShmSystemV::ShmSystemV(std::string accessMode, int rankMPI, - const std::string &pathName, size_t dataSize, - size_t metadataSize, bool debugMode) -: Capsule{"ShmSystemV", std::move(accessMode), rankMPI, debugMode}, - m_DataSize{dataSize}, m_MetadataSize{metadataSize} +ShmSystemV::ShmSystemV(const std::string &pathName, const int rankMPI, + const size_t dataSize, const size_t metadataSize, + const bool debugMode) +: Capsule("ShmSystemV", debugMode), m_DataSize(dataSize), + m_MetadataSize(metadataSize) { // Data Shared memory sector const std::string dataPath(pathName + "/adios.shm.data." + - std::to_string(m_RankMPI)); - m_DataKey = ftok(dataPath.c_str(), m_RankMPI + 1); + std::to_string(rankMPI)); + // 2nd field must be greater than zero and unique + m_DataKey = ftok(dataPath.c_str(), rankMPI + 1); m_DataShmID = shmget(m_DataKey, m_DataSize, IPC_CREAT | 0666); m_Data = static_cast<char *>(shmat(m_DataShmID, nullptr, 0)); // Metadata Shared memory sector const std::string metadataPath(pathName + "/adios.shm.metadata." + - std::to_string(m_RankMPI)); - m_MetadataKey = - ftok(metadataPath.c_str(), - m_RankMPI + 1); // 2nd field must be greater than zero and unique + std::to_string(rankMPI)); + // 2nd field must be greater than zero and unique + m_MetadataKey = ftok(metadataPath.c_str(), rankMPI + 1); m_MetadataShmID = shmget(m_MetadataKey, m_MetadataSize, IPC_CREAT | 0666); m_Metadata = static_cast<char *>(shmat(m_MetadataShmID, nullptr, 0)); diff --git a/source/adios2/capsule/shmem/ShmSystemV.h b/source/adios2/capsule/shmem/ShmSystemV.h index 68631624b214716fac3e54a272835c5917fab43b..ca8872bfcb32d073c685c5cd7e44aed7a62064c4 100644 --- a/source/adios2/capsule/shmem/ShmSystemV.h +++ b/source/adios2/capsule/shmem/ShmSystemV.h @@ -24,15 +24,16 @@ class ShmSystemV : public Capsule public: /** - * Create a Capsule in shared memory using System V shm API - * @param accessMode - * @param pathName used to create the key as a unique identifier - * @param dataSize size of allocated memory segment for data - * @param metadataSize size of allocated memory segment for metadata - * @param debugMode true: extra checks, slower - */ - ShmSystemV(std::string accessMode, int rankMPI, const std::string &pathName, - size_t dataSize, size_t metadataSize, bool debugMode = false); + * Create a Capsule in shared memory using System V shm API + * @param accessMode + * @param pathName used to create the key as a unique identifier + * @param dataSize size of allocated memory segment for data + * @param metadataSize size of allocated memory segment for metadata + * @param debugMode true: extra checks, slower + */ + ShmSystemV(const std::string &pathName, const int rankMPI, + const size_t dataSize, const size_t metadataSize, + const bool debugMode = false); ~ShmSystemV() = default; @@ -43,24 +44,21 @@ public: size_t GetMetadataSize() const; ///< get current metadata buffer size private: - char *m_Data = nullptr; ///< reference to a shared memory data buffer - /// created with shmget + /** reference to a shared memory data buffer */ + char *m_Data = nullptr; const size_t m_DataSize; ///< size of the allocated shared memory segment key_t m_DataKey; ///< key associated with the data buffer, created with ftok int m_DataShmID; ///< data shared memory buffer id - char *m_Metadata = - nullptr; ///< reference to a shared memory metadata buffer - /// created with shmget - const size_t - m_MetadataSize; ///< size of the allocated shared memory segment - key_t m_MetadataKey; ///< key associated with the metadata buffer, created - /// with ftok - int m_MetadataShmID; ///< metadata shared memory buffer id + /** reference to a shared memory metadata buffer created with shmget */ + char *m_Metadata = nullptr; + const size_t m_MetadataSize; ///< size of the allocated segment + key_t m_MetadataKey; ///< ftok metadata buffer key + int m_MetadataShmID; ///< metadata shared memory buffer id - void CheckShm() const; ///< checks if all shared memory allocations are - /// correct, throws std::bad_alloc, called from - /// constructor if debug mode is true + /** checks if all shared memory allocations are correct, throws + std::bad_alloc, called from constructor if debug mode is true */ + void CheckShm() const; }; } // end namespace adios diff --git a/source/adios2/core/Capsule.cpp b/source/adios2/core/Capsule.cpp index 60888e8f85ee0bd4bad144c8e7c28b75033ef25a..2388c03fdf73556dc8658ae247eddf60ab8e1cd6 100644 --- a/source/adios2/core/Capsule.cpp +++ b/source/adios2/core/Capsule.cpp @@ -10,15 +10,11 @@ #include "Capsule.h" -#include <utility> - namespace adios { -Capsule::Capsule(const std::string type, const std::string accessMode, - int rankMPI, bool debugMode) -: m_Type{std::move(type)}, m_AccessMode{std::move(accessMode)}, - m_RankMPI{rankMPI}, m_DebugMode{debugMode} +Capsule::Capsule(const std::string type, const bool debugMode) +: m_Type(type), m_DebugMode(debugMode) { } diff --git a/source/adios2/core/Capsule.h b/source/adios2/core/Capsule.h index c3e3cdcebef36517998014186d664affea40342f..51e7098dc61899e59b65a814f9c0785a877a337f 100644 --- a/source/adios2/core/Capsule.h +++ b/source/adios2/core/Capsule.h @@ -5,7 +5,7 @@ * Capsule.h * * Created on: Dec 7, 2016 - * Author: wfgtemplates and pointers + * Author: wfg */ #ifndef ADIOS2_CORE_CAPSULE_H_ @@ -29,40 +29,40 @@ class Capsule { public: - const std::string m_Type; ///< buffer type - const std::string m_AccessMode; ///< 'w': write, 'r': read, 'a': append + /** Derived class ID */ + const std::string m_Type; - std::size_t m_DataPosition = 0; ///< position in current data buffer (not - /// included data flushed to transports) - std::size_t m_DataAbsolutePosition = 0; ///< include bytes flushed + /** position in current data buffer */ + size_t m_DataPosition = 0; - std::size_t m_MetadataPosition = 0; ///< position in metadata buffer + /** position in current data buffer + bytes flushed in transports */ + size_t m_DataAbsolutePosition = 0; + + /** position in metadata buffer */ + size_t m_MetadataPosition = 0; /** - * Base class constructor providing type from derived class and accessMode - * @param type derived class type - * @param accessMode 'w':write, 'r':read, 'a':append - * @param rankMPI current MPI rank - * @param debugMode + * Unique constructor + * @param type derived class + * @param debugMode true: extra exception checks */ - Capsule(const std::string type, const std::string accessMode, - const int rankMPI, const bool debugMode); + Capsule(const std::string type, const bool debugMode); virtual ~Capsule() = default; - virtual char *GetData() = 0; ///< return the pointer to the raw data buffer - virtual char * - GetMetadata() = 0; ///< return the pointer to the raw metadata buffer + /** pointer to the raw data buffer */ + virtual char *GetData() = 0; + /** pointer to the raw metadata buffer */ + virtual char *GetMetadata() = 0; - virtual std::size_t GetDataSize() const = 0; ///< data buffer size - virtual std::size_t GetMetadataSize() const = 0; ///< metadata buffer size + virtual size_t GetDataSize() const = 0; ///< data buffer memory size + virtual size_t GetMetadataSize() const = 0; ///< metadata buffer memory size - virtual void ResizeData(std::size_t size); ///< resize data buffer - virtual void ResizeMetadata(std::size_t size); ///< resize metadata buffer + virtual void ResizeData(size_t size); ///< resize data buffer + virtual void ResizeMetadata(size_t size); ///< resize metadata buffer protected: - const int m_RankMPI = 0; ///< current MPI rank - const bool m_DebugMode = false; ///< true: extra checks + const bool m_DebugMode = false; ///< true: extra exception checks }; } // end namespace diff --git a/source/adios2/engine/bp/BPFileReader.cpp b/source/adios2/engine/bp/BPFileReader.cpp index ef4951a0a65487bcf8b28d253092a92bdc140179..d74d94adac0ab80f5b2a5cef3b0cfb56803b6b7a 100644 --- a/source/adios2/engine/bp/BPFileReader.cpp +++ b/source/adios2/engine/bp/BPFileReader.cpp @@ -24,7 +24,7 @@ BPFileReader::BPFileReader(ADIOS &adios, const std::string &name, const Method &method) : Engine(adios, "BPFileReader", name, accessMode, mpiComm, method, " BPFileReader constructor (or call to ADIOS Open).\n"), - m_Buffer(accessMode, m_RankMPI, m_DebugMode) + m_Heap(m_DebugMode) { Init(); } diff --git a/source/adios2/engine/bp/BPFileReader.h b/source/adios2/engine/bp/BPFileReader.h index cba6a54ea7724d530cef9a22ab351b13351a36b7..6f36b4f336810ec97aff3ff6b437c0a221a7092c 100644 --- a/source/adios2/engine/bp/BPFileReader.h +++ b/source/adios2/engine/bp/BPFileReader.h @@ -113,7 +113,7 @@ public: private: capsule::STLVector - m_Buffer; ///< heap capsule, contains data and metadata buffers + m_Heap; ///< heap capsule, contains data and metadata buffers // format::BP1Writer m_BP1Writer; ///< format object will provide the // required // BP functionality to be applied on m_Buffer and m_Transports diff --git a/source/adios2/engine/bp/BPFileWriter.cpp b/source/adios2/engine/bp/BPFileWriter.cpp index 013a19ec07d72c18371f3041fbb0b6ac29c528f4..ad033c333d7d0c5e507f0dd3e3ed04586df5f11a 100644 --- a/source/adios2/engine/bp/BPFileWriter.cpp +++ b/source/adios2/engine/bp/BPFileWriter.cpp @@ -25,9 +25,8 @@ BPFileWriter::BPFileWriter(ADIOS &adios, const std::string &name, const Method &method) : Engine(adios, "BPFileWriter", name, accessMode, mpiComm, method, " BPFileWriter constructor (or call to ADIOS Open).\n"), - m_Buffer(accessMode, m_RankMPI, m_DebugMode), - m_BP1Aggregator(m_MPIComm, m_DebugMode), - m_MaxBufferSize(m_Buffer.m_Data.max_size()) + m_Heap(m_DebugMode), m_BP1Aggregator(m_MPIComm, m_DebugMode), + m_MaxBufferSize(m_Heap.m_Data.max_size()) { m_MetadataSet.TimeStep = 1; // to be compatible with ADIOS1.x Init(); @@ -245,7 +244,7 @@ void BPFileWriter::Write(const std::string & /*variableName*/, void BPFileWriter::Advance(float /*timeout_sec*/) { - m_BP1Writer.Advance(m_MetadataSet, m_Buffer); + m_BP1Writer.Advance(m_MetadataSet, m_Heap); } void BPFileWriter::Close(const int transportIndex) @@ -255,15 +254,14 @@ void BPFileWriter::Close(const int transportIndex) { for (auto &transport : m_Transports) { // by reference or value or it doesn't matter? - m_BP1Writer.Close(m_MetadataSet, m_Buffer, *transport, - m_IsFirstClose, + m_BP1Writer.Close(m_MetadataSet, m_Heap, *transport, m_IsFirstClose, false); // false: not using aggregation for now } } else { - m_BP1Writer.Close(m_MetadataSet, m_Buffer, - *m_Transports[transportIndex], m_IsFirstClose, + m_BP1Writer.Close(m_MetadataSet, m_Heap, *m_Transports[transportIndex], + m_IsFirstClose, false); // false: not using aggregation for now } @@ -559,7 +557,7 @@ void BPFileWriter::WriteProcessGroupIndex() m_BP1Writer.WriteProcessGroupIndex(isFortran, std::to_string(m_RankMPI), static_cast<std::uint32_t>(m_RankMPI), - m_Transports, m_Buffer, m_MetadataSet); + m_Transports, m_Heap, m_MetadataSet); } } // end namespace adios diff --git a/source/adios2/engine/bp/BPFileWriter.h b/source/adios2/engine/bp/BPFileWriter.h index f6754ed382681feb4441ef9a9a58bbc247545945..1c0c533a3fd4efd98e69a9aafda18742e353a7cb 100644 --- a/source/adios2/engine/bp/BPFileWriter.h +++ b/source/adios2/engine/bp/BPFileWriter.h @@ -98,7 +98,7 @@ public: void Close(const int transportIndex = -1); private: - capsule::STLVector m_Buffer; ///< heap capsule using STL std::vector<char> + capsule::STLVector m_Heap; ///< heap capsule using STL std::vector<char> format::BP1Writer m_BP1Writer; ///< format object will provide the required BP /// functionality to be applied on m_Buffer and @@ -160,7 +160,7 @@ private: // m_Buffer.m_Data ); // WRITE INDEX to data buffer and metadata structure (in memory)// - m_BP1Writer.WriteVariableMetadata(variable, m_Buffer, m_MetadataSet); + m_BP1Writer.WriteVariableMetadata(variable, m_Heap, m_MetadataSet); if (m_TransportFlush == true) // in batches { @@ -172,7 +172,7 @@ private: } else // Write data to buffer { - m_BP1Writer.WriteVariablePayload(variable, m_Buffer, m_nThreads); + m_BP1Writer.WriteVariablePayload(variable, m_Heap, m_nThreads); } variable.m_AppValues = diff --git a/source/adios2/engine/dataman/DataManReader.cpp b/source/adios2/engine/dataman/DataManReader.cpp index bb520b5011ad22cce0c48ee25e973a4bccf4676e..6ecc32f09beff58eeeb04d064043f59f9109523f 100644 --- a/source/adios2/engine/dataman/DataManReader.cpp +++ b/source/adios2/engine/dataman/DataManReader.cpp @@ -25,7 +25,7 @@ DataManReader::DataManReader(ADIOS &adios, const std::string &name, const Method &method) : Engine(adios, "DataManReader", name, accessMode, mpiComm, method, " DataManReader constructor (or call to ADIOS Open).\n"), - m_Buffer(accessMode, m_RankMPI, m_DebugMode) + m_Heap(m_DebugMode) { Init(); } diff --git a/source/adios2/engine/dataman/DataManReader.h b/source/adios2/engine/dataman/DataManReader.h index 003fad9776b587b96bfcb0b7a60247f4549509ba..4475c31059cf2bf86469f230b158968e9a8cf0c5 100644 --- a/source/adios2/engine/dataman/DataManReader.h +++ b/source/adios2/engine/dataman/DataManReader.h @@ -101,7 +101,7 @@ public: private: capsule::STLVector - m_Buffer; ///< heap capsule, contains data and metadata buffers + m_Heap; ///< heap capsule, contains data and metadata buffers format::BP1Writer m_BP1Writer; ///< format object will provide the required BP /// functionality to be applied on m_Buffer and diff --git a/source/adios2/engine/dataman/DataManWriter.cpp b/source/adios2/engine/dataman/DataManWriter.cpp index c125c10cbbb21b16d6341830213ab1992bc2feaa..1cf180ffe0fb5bbf3ec55ea8e8756ce948cdd4c5 100644 --- a/source/adios2/engine/dataman/DataManWriter.cpp +++ b/source/adios2/engine/dataman/DataManWriter.cpp @@ -25,7 +25,7 @@ DataManWriter::DataManWriter(ADIOS &adios, const std::string name, const Method &method) : Engine(adios, "DataManWriter", name, accessMode, mpiComm, method, " DataManWriter constructor (or call to ADIOS Open).\n"), - m_Buffer(accessMode, m_RankMPI, m_DebugMode) + m_Heap(m_DebugMode) { Init(); } diff --git a/source/adios2/engine/dataman/DataManWriter.h b/source/adios2/engine/dataman/DataManWriter.h index 0edaeb2e1a067d95caba640c3ec30328d2343cff..44567dddff6d6fc6b497d17cfbe713b738c413db 100644 --- a/source/adios2/engine/dataman/DataManWriter.h +++ b/source/adios2/engine/dataman/DataManWriter.h @@ -98,7 +98,7 @@ public: private: capsule::STLVector - m_Buffer; ///< heap capsule, contains data and metadata buffers + m_Heap; ///< heap capsule, contains data and metadata buffers format::BP1Writer m_BP1Writer; ///< format object will provide the required BP /// functionality to be applied on m_Buffer and