mptensor v0.6.0
Parallel Library for Tensor Network Methods
Loading...
Searching...
No Matches
file_io_common.hpp
Go to the documentation of this file.
1#ifndef MPTENSOR_TEST_FILE_IO_COMMON_HPP_
2#define MPTENSOR_TEST_FILE_IO_COMMON_HPP_
3
4#include <cstddef>
5#include <iomanip>
6#include <sstream>
7#include <string>
8
10
11#include "tensor_types.hpp"
12
13namespace mptensor_test {
14
18
19constexpr std::size_t kFileIoN = 6;
20
23template <typename TensorType>
25 const std::size_t n = kFileIoN;
26 TensorType t(Shape(n, n + 1, n + 2, n + 3));
27 for (std::size_t i = 0; i < t.local_size(); ++i) {
28 const Index idx = t.global_index(i);
29 t[i] = idx[0] + idx[1] * 100 + idx[2] * 10000 + idx[3] * 1000000;
30 }
31 t.transpose(Axes(3, 1, 0, 2));
32 return t;
33}
34
36inline std::string data_filename(const std::string& prefix, int proc_size) {
37 std::ostringstream ss;
38 ss << prefix << "_mpi" << std::setw(4) << std::setfill('0') << proc_size;
39 return ss.str();
40}
41
43inline std::string binary_filename(const std::string& base, int rank) {
44 std::ostringstream ss;
45 ss << base << "." << std::setw(4) << std::setfill('0') << rank << ".bin";
46 return ss.str();
47}
48
49} // namespace mptensor_test
50
51#endif // MPTENSOR_TEST_FILE_IO_COMMON_HPP_
Definition index.hpp:102
std::complex< double > complex
Definition complex.hpp:38
Index Shape
Definition index.hpp:215
Index Axes
Definition index.hpp:212
Top header file of mptensor.
Definition mpi_helpers.hpp:10
std::string binary_filename(const std::string &base, int rank)
Per-rank binary file written by Tensor::save: "<base>.NNNN.bin".
Definition file_io_common.hpp:43
Tensor< lapack::Matrix< double > > LocalTensorD
Non-distributed tensor types (always LAPACK).
Definition file_io_common.hpp:16
constexpr std::size_t kFileIoN
Definition file_io_common.hpp:19
Tensor< lapack::Matrix< complex > > LocalTensorC
Definition file_io_common.hpp:17
TensorType make_initial_tensor()
Definition file_io_common.hpp:24
std::string data_filename(const std::string &prefix, int proc_size)
"<prefix>_mpi000N" (same names as legacy).
Definition file_io_common.hpp:36