iterative-solver 0.0
 
Loading...
Searching...
No Matches
DistrArrayFile.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_DISTRARRAYFILE_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_DISTRARRAYFILE_H
3
4#include "util/fs.h"
5#include <molpro/linalg/array/DistrArrayDisk.h>
6#include <molpro/mpi.h>
7#include <fstream>
8#include <memory>
9
10namespace molpro::linalg::array {
22
23private:
24 fs::path m_directory;
25 fs::path m_filename;
26 mutable std::unique_ptr<std::fstream>
27 m_stream; // use a pointer just in case the implementation of std::fstream is not movable
28 mutable std::mutex m_mutex;
29 [[nodiscard]] std::tuple<index_type, index_type, index_type>
30 local_bounds() const;
31public:
32 DistrArrayFile() = delete;
34 DistrArrayFile(const DistrArrayFile& source);
36 explicit DistrArrayFile(size_t dimension, MPI_Comm comm = molpro::mpi::comm_global(),
37 const std::string& directory = ".");
38 explicit DistrArrayFile(std::unique_ptr<Distribution> distribution,
39 MPI_Comm comm = molpro::mpi::comm_global(),
40 const std::string& directory = ".");
43 explicit DistrArrayFile(const DistrArray& source);
44
45 DistrArrayFile& operator=(const DistrArrayFile& source) = delete;
46 DistrArrayFile& operator=(DistrArrayFile&& source) noexcept;
47
55 static DistrArrayFile CreateTempCopy(const DistrArray& source, const std::string& directory = "");
62 static DistrArrayFile CreateTempCopy(Span<const value_type> source, MPI_Comm comm,
63 const std::string& directory = ".");
64
65 friend void swap(DistrArrayFile& x, DistrArrayFile& y) noexcept;
66
67 ~DistrArrayFile() override;
68
69 [[nodiscard]] std::string file_directory() const override { return m_directory.string(); }
70
71 bool compatible(const DistrArrayFile& source) const;
72
74 void erase() override {}
76 value_type at(index_type ind) const override;
78 void set(index_type ind, value_type val) override;
80 void get(index_type lo, index_type hi, value_type* buf) const override;
82 std::vector<value_type> get(index_type lo, index_type hi) const override;
84 void put(index_type lo, index_type hi, const value_type* data) override;
87 void acc(index_type lo, index_type hi, const value_type* data) override;
88 std::vector<value_type> gather(const std::vector<index_type>& indices) const override;
89 void scatter(const std::vector<index_type>& indices, const std::vector<value_type>& data) override;
90 void scatter_acc(std::vector<index_type>& indices, const std::vector<value_type>& data) override;
91 std::vector<value_type> vec() const override;
92};
93
94} // namespace molpro::linalg::array
95
96#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_DISTRARRAYFILE_H
Distributed array located primarily on disk.
Definition DistrArrayDisk.h:37
const Distribution & distribution() const override
Access distribution of the array among processes.
Definition DistrArrayDisk.cpp:30
Distributed array storing the buffer on disk using temporary local files.
Definition DistrArrayFile.h:21
void put(index_type lo, index_type hi, const value_type *data) override
Writes requested values to file.
Definition DistrArrayFile.cpp:241
void erase() override
Dummy.
Definition DistrArrayFile.h:74
std::vector< value_type > vec() const override
Copies the whole buffer into a vector. Blocking.
Definition DistrArrayFile.cpp:321
bool compatible(const DistrArrayFile &source) const
Definition DistrArrayFile.cpp:171
void scatter(const std::vector< index_type > &indices, const std::vector< value_type > &data) override
array[indices[i]] = data[i] Puts vals of elements with discontinuous indices of array....
Definition DistrArrayFile.cpp:294
void set(index_type ind, value_type val) override
Writes value at a given index.
Definition DistrArrayFile.cpp:186
void scatter_acc(std::vector< index_type > &indices, const std::vector< value_type > &data) override
array[indices[i]] += vals[i] Accumulates vals of elements into discontinuous indices of array....
Definition DistrArrayFile.cpp:314
void acc(index_type lo, index_type hi, const value_type *data) override
Definition DistrArrayFile.cpp:266
void get(index_type lo, index_type hi, value_type *buf) const override
Reads requested values.
Definition DistrArrayFile.cpp:188
value_type at(index_type ind) const override
Definition DistrArrayFile.cpp:180
std::vector< value_type > gather(const std::vector< index_type > &indices) const override
gets elements with discontinuous indices from array. Blocking
Definition DistrArrayFile.cpp:276
static DistrArrayFile CreateTempCopy(const DistrArray &source, const std::string &directory="")
Creates a copy of source, with the same distribution and communicator, in a file which is erased on d...
Definition DistrArrayFile.cpp:132
friend void swap(DistrArrayFile &x, DistrArrayFile &y) noexcept
Definition DistrArrayFile.cpp:146
DistrArrayFile()=delete
returns local array boundaries and size
std::string file_directory() const override
The directory of the file holding this array, or an empty string if that is not known.
Definition DistrArrayFile.h:69
DistrArrayFile & operator=(const DistrArrayFile &source)=delete
~DistrArrayFile() override
Definition DistrArrayFile.cpp:157
Array distributed across many processes supporting remote-memory-access, access to process local buff...
Definition DistrArray.h:138
double value_type
Definition DistrArray.h:141
size_t index_type
Definition DistrArray.h:142
Non-owning container taking a pointer to the data buffer and its size and exposing routines for itera...
Definition Span.h:31
Definition ArrayHandler.h:19