29 #ifndef _MPTENSOR_LOAD_HPP_
30 #define _MPTENSOR_LOAD_HPP_
52 template <
template <
typename>
class Matrix,
typename C>
54 const bool comm_root = (get_comm_rank() == 0);
59 size_t& loaded_version_major = ibuf[0];
60 size_t& loaded_version_minor = ibuf[1];
61 size_t& loaded_version_patch = ibuf[2];
62 size_t& loaded_matrix_type = ibuf[3];
63 size_t& loaded_value_type = ibuf[4];
64 size_t& loaded_comm_size = ibuf[5];
65 size_t& loaded_ndim = ibuf[6];
66 size_t& loaded_urank = ibuf[7];
67 const size_t this_matrix_type = Matrix<C>::matrix_type_tag;
68 const size_t this_value_type = value_type_tag<C>();
69 const size_t this_comm_size = get_comm_size();
77 fin >> dummy >> version;
79 if (dummy !=
"mptensor") {
85 sscanf(version.c_str(),
"%lu.%lu.%lu", &(ibuf[0]), &(ibuf[1]),
87 fin >> dummy >> ibuf[3] >> dummy;
88 fin >> dummy >> ibuf[4] >> dummy;
89 fin >> dummy >> ibuf[5];
90 fin >> dummy >> ibuf[6];
91 fin >> dummy >> ibuf[7];
94 Mat.bcast(ibuf, 8, 0);
96 if (ibuf[0] == 0 && ibuf[1] <= 2) {
101 const size_t count = 2 * loaded_ndim;
102 size_t* buffer =
new size_t[count];
107 for (
size_t i = 0; i < loaded_ndim; ++i) fin >> buffer[k++];
109 for (
size_t i = 0; i < loaded_ndim; ++i) fin >> buffer[k++];
112 Mat.bcast(buffer, count, 0);
114 loaded_shape.
assign(loaded_ndim, buffer);
115 loaded_map.
assign(loaded_ndim, (buffer + loaded_ndim));
120 assert(loaded_value_type == this_value_type);
123 init(loaded_shape, loaded_urank, loaded_map);
126 if (loaded_matrix_type == this_matrix_type &&
127 loaded_comm_size == this_comm_size) {
129 std::clog <<
"Info: Load a tensor directly." << std::endl;
136 std::clog <<
"Info: Load a non-distributed tensor." << std::endl;
143 <<
"Info: Load a tensor distributed on different-size communicator."
161 template <
template <
typename>
class Matrix,
typename C>
162 void Tensor<Matrix, C>::load_ver_0_2(
const char*
filename) {
169 if (get_comm_rank() == 0) {
170 std::clog <<
"Warning: \"" <<
filename
171 <<
"\" will be loaded using v0.2 interface." << std::endl;
176 if (get_comm_rank() == 0) {
182 const size_t count = 2 * n + 1;
183 size_t* buffer =
new size_t[count];
185 if (get_comm_rank() == 0) {
186 for (
size_t i = 0; i < count; ++i) fin >> buffer[i];
189 Mat.bcast(buffer, count, 0);
192 shape.assign(n, (buffer + 1));
193 map.assign(n, (buffer + n + 1));
199 init(
shape, urank, map);
203 char* datafile =
new char[std::strlen(
filename) + 16];
204 sprintf(datafile,
"%s.%04d",
filename, get_comm_rank());
207 fin.open(datafile, std::ofstream::binary);
208 fin.read(
reinterpret_cast<char*
>(get_matrix().head()),
209 sizeof(C) * local_size());
void assign(size_t n, size_t j[])
Definition: index.cc:37
void load(const std::string &filename)
Load a tensor from files.
Definition: load.hpp:53
std::string filename(const std::string &prefix, int proc_size)
Definition: common.hpp:32
Header file of helper functions for file io.
constexpr size_t MATRIX_TYPE_TAG_LAPACK
Definition: matrix.hpp:34
constexpr size_t MATRIX_TYPE_TAG_SCALAPACK
Definition: matrix.hpp:35
constexpr bool debug
Definition: io_helper.hpp:46
void load_binary(const std::string &prefix, int comm_rank, C *data_head, std::size_t local_size)
Definition: io_helper.hpp:66
void load_scalapack(const std::string &prefix, int loaded_comm_size, Matrix< C > &mat)
Definition: io_helper.hpp:125
Definition: complex.hpp:34
Index Shape
Definition: tensor.hpp:46
Index Axes
Definition: tensor.hpp:45
tuple shape
Definition: output.py:28