iterative-solver 0.0
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
10using molpro::mpi::comm_global;
11
12namespace molpro::linalg::array {
24
25private:
26 fs::path m_directory;
27 fs::path m_filename;
28 mutable std::unique_ptr<std::fstream>
29 m_stream; // use a pointer just in case the implementation of std::fstream is not movable
30 mutable std::mutex m_mutex;
31 [[nodiscard]] std::tuple<index_type, index_type, index_type>
32 local_bounds() const;
33public:
34 DistrArrayFile() = delete;
35 DistrArrayFile(const DistrArrayFile& source);
37 explicit DistrArrayFile(size_t dimension, MPI_Comm comm = comm_global(), const std::string& directory = ".");
38 explicit DistrArrayFile(std::unique_ptr<Distribution> distribution, MPI_Comm comm = comm_global(),
39 const std::string& directory = ".");
40 explicit DistrArrayFile(const DistrArray& source);
41
42 DistrArrayFile& operator=(const DistrArrayFile& source) = delete;
43 DistrArrayFile& operator=(DistrArrayFile&& source) noexcept;
44
45 static DistrArrayFile CreateTempCopy(const DistrArray& source, const std::string& directory = ".");
46
47 friend void swap(DistrArrayFile& x, DistrArrayFile& y) noexcept;
48
49 ~DistrArrayFile() override;
50
51 bool compatible(const DistrArrayFile& source) const;
52
54 void erase() override {}
56 value_type at(index_type ind) const override;
58 void set(index_type ind, value_type val) override;
60 void get(index_type lo, index_type hi, value_type* buf) const override;
62 std::vector<value_type> get(index_type lo, index_type hi) const override;
64 void put(index_type lo, index_type hi, const value_type* data) override;
67 void acc(index_type lo, index_type hi, const value_type* data) override;
68 std::vector<value_type> gather(const std::vector<index_type>& indices) const override;
69 void scatter(const std::vector<index_type>& indices, const std::vector<value_type>& data) override;
70 void scatter_acc(std::vector<index_type>& indices, const std::vector<value_type>& data) override;
71 std::vector<value_type> vec() const override;
72};
73
74} // namespace molpro::linalg::array
75
76#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_DISTRARRAYFILE_H
Distributed array located primarily on disk.
Definition: DistrArrayDisk.h:36
const Distribution & distribution() const override
Access distribution of the array among processes.
Definition: DistrArrayDisk.cpp:85
Distributed array storing the buffer on disk using temporary local files.
Definition: DistrArrayFile.h:23
void put(index_type lo, index_type hi, const value_type *data) override
Writes requested values to file.
Definition: DistrArrayFile.cpp:210
void erase() override
Dummy.
Definition: DistrArrayFile.h:54
std::vector< value_type > vec() const override
Copies the whole buffer into a vector. Blocking.
Definition: DistrArrayFile.cpp:280
bool compatible(const DistrArrayFile &source) const
Definition: DistrArrayFile.cpp:147
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:255
void set(index_type ind, value_type val) override
Writes value at a given index.
Definition: DistrArrayFile.cpp:162
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:273
void acc(index_type lo, index_type hi, const value_type *data) override
Definition: DistrArrayFile.cpp:229
void get(index_type lo, index_type hi, value_type *buf) const override
Reads requested values.
Definition: DistrArrayFile.cpp:164
value_type at(index_type ind) const override
Definition: DistrArrayFile.cpp:156
std::vector< value_type > gather(const std::vector< index_type > &indices) const override
gets elements with discontinuous indices from array. Blocking
Definition: DistrArrayFile.cpp:239
friend void swap(DistrArrayFile &x, DistrArrayFile &y) noexcept
Definition: DistrArrayFile.cpp:122
DistrArrayFile()=delete
returns local array boundaries and size
DistrArrayFile & operator=(const DistrArrayFile &source)=delete
static DistrArrayFile CreateTempCopy(const DistrArray &source, const std::string &directory=".")
Definition: DistrArrayFile.cpp:116
~DistrArrayFile() override
Definition: DistrArrayFile.cpp:133
Array distributed across many processes supporting remote-memory-access, access to process local buff...
Definition: DistrArray.h:90
double value_type
Definition: DistrArray.h:93
size_t index_type
Definition: DistrArray.h:94
Definition: ArrayHandler.h:22