openPMD-api
ParallelADIOS1IOHandlerImpl.hpp
1 /* Copyright 2017-2021 Fabian Koller
2  *
3  * This file is part of openPMD-api.
4  *
5  * openPMD-api is free software: you can redistribute it and/or modify
6  * it under the terms of of either the GNU General Public License or
7  * the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * openPMD-api is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License and the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * and the GNU Lesser General Public License along with openPMD-api.
19  * If not, see <http://www.gnu.org/licenses/>.
20  */
21 #pragma once
22 
23 #include "openPMD/IO/AbstractIOHandler.hpp"
24 #include "openPMD/auxiliary/Export.hpp"
25 #include "openPMD/config.hpp"
26 
27 #if openPMD_HAVE_ADIOS1 && openPMD_HAVE_MPI
28 #include "openPMD/IO/AbstractIOHandlerImpl.hpp"
29 #include <adios.h>
30 #include <adios_read.h>
31 #endif
32 
33 #include <future>
34 #include <memory>
35 #include <string>
36 #if openPMD_HAVE_ADIOS1
37 #include <unordered_map>
38 #include <unordered_set>
39 #endif
40 
41 namespace openPMD
42 {
43 #if openPMD_HAVE_ADIOS1 && openPMD_HAVE_MPI
44 class OPENPMDAPI_EXPORT ParallelADIOS1IOHandlerImpl
45  : public AbstractIOHandlerImpl
46 {
47 public:
49  virtual ~ParallelADIOS1IOHandlerImpl();
50 
51  virtual void init();
52 
53  std::future<void> flush();
54 
55  void
56  createFile(Writable *, Parameter<Operation::CREATE_FILE> const &) override;
57  void
58  createPath(Writable *, Parameter<Operation::CREATE_PATH> const &) override;
59  void createDataset(
61  void extendDataset(
63  void openFile(Writable *, Parameter<Operation::OPEN_FILE> const &) override;
64  void
65  closeFile(Writable *, Parameter<Operation::CLOSE_FILE> const &) override;
66  void availableChunks(
68  void openPath(Writable *, Parameter<Operation::OPEN_PATH> const &) override;
69  void openDataset(Writable *, Parameter<Operation::OPEN_DATASET> &) override;
70  void
71  deleteFile(Writable *, Parameter<Operation::DELETE_FILE> const &) override;
72  void
73  deletePath(Writable *, Parameter<Operation::DELETE_PATH> const &) override;
74  void deleteDataset(
76  void deleteAttribute(
77  Writable *, Parameter<Operation::DELETE_ATT> const &) override;
78  void writeDataset(
79  Writable *, Parameter<Operation::WRITE_DATASET> const &) override;
80  void writeAttribute(
81  Writable *, Parameter<Operation::WRITE_ATT> const &) override;
82  void readDataset(Writable *, Parameter<Operation::READ_DATASET> &) override;
83  void readAttribute(Writable *, Parameter<Operation::READ_ATT> &) override;
84  void listPaths(Writable *, Parameter<Operation::LIST_PATHS> &) override;
85  void
86  listDatasets(Writable *, Parameter<Operation::LIST_DATASETS> &) override;
87  void listAttributes(Writable *, Parameter<Operation::LIST_ATTS> &) override;
88 
89  virtual int64_t open_write(Writable *);
90  virtual ADIOS_FILE *open_read(std::string const &name);
91  void close(int64_t);
92  void close(ADIOS_FILE *);
93  int64_t initialize_group(std::string const &name);
94  void
95  flush_attribute(int64_t group, std::string const &name, Attribute const &);
96 
97 protected:
98  ADIOS_READ_METHOD m_readMethod;
99  std::unordered_map<Writable *, std::shared_ptr<std::string> > m_filePaths;
100  std::unordered_map<std::shared_ptr<std::string>, int64_t> m_groups;
101  std::unordered_map<std::shared_ptr<std::string>, bool> m_existsOnDisk;
102  std::unordered_map<std::shared_ptr<std::string>, int64_t>
103  m_openWriteFileHandles;
104  std::unordered_map<std::shared_ptr<std::string>, ADIOS_FILE *>
105  m_openReadFileHandles;
107  {
108  ADIOS_SELECTION *selection;
109  std::shared_ptr<void> data; // needed to avoid early freeing
110  };
111  std::unordered_map<ADIOS_FILE *, std::vector<ScheduledRead> >
112  m_scheduledReads;
113  std::unordered_map<int64_t, std::unordered_map<std::string, Attribute> >
114  m_attributeWrites;
120  int64_t GetFileHandle(Writable *);
121  MPI_Comm m_mpiComm;
122  MPI_Info m_mpiInfo;
123 }; // ParallelADIOS1IOHandlerImpl
124 #else
125 class OPENPMDAPI_EXPORT ParallelADIOS1IOHandlerImpl
126 {}; // ParallelADIOS1IOHandlerImpl
127 #endif
128 
129 } // namespace openPMD
Varidic datatype supporting at least all formats for attributes specified in the openPMD standard...
Definition: Attribute.hpp:51
Definition: ParallelADIOS1IOHandlerImpl.hpp:106
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:122
Public definitions of openPMD-api.
Definition: Date.cpp:28
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:63
Definition: AbstractIOHandlerImpl.hpp:35
Definition: ParallelADIOS1IOHandlerImpl.hpp:44