29 #ifndef _MPTENSOR_LOAD_HELPER_HPP_
30 #define _MPTENSOR_LOAD_HELPER_HPP_
44 constexpr
bool debug =
false;
50 std::ostringstream ss;
52 ss << std::setw(4) << std::setfill(
'0') << comm_rank;
57 inline std::string
index_filename(
const std::string& prefix,
int comm_rank) {
58 std::ostringstream ss;
60 ss << std::setw(4) << std::setfill(
'0') << comm_rank;
66 void load_binary(
const std::string& prefix,
int comm_rank, C* data_head,
67 std::size_t local_size) {
70 std::ifstream fin(
filename, std::ofstream::binary);
71 assert(fin.is_open());
72 fin.read(
reinterpret_cast<char*
>(data_head),
sizeof(C) * local_size);
76 template <
template <
typename>
class Matrix,
typename C>
78 size_t& local_size, std::vector<int>& dest_rank,
79 std::vector<size_t>& local_idx, std::vector<C>& data,
80 const Matrix<C>& mat) {
81 std::vector<size_t> g_row;
82 std::vector<size_t> g_col;
91 assert(fin.is_open());
93 fin >> dummy >> local_size;
94 fin >> dummy >> local_n_row;
95 fin >> dummy >> local_n_col;
96 assert(local_size == local_n_row * local_n_col);
98 g_row.resize(local_n_row);
99 g_col.resize(local_n_col);
102 for (
size_t i = 0; i < local_n_row; ++i) {
106 for (
size_t i = 0; i < local_n_col; ++i) {
112 dest_rank.resize(local_size);
113 local_idx.resize(local_size);
114 for (
size_t i = 0; i < local_size; ++i) {
115 size_t i_row = i % local_n_row;
116 size_t i_col = i / local_n_row;
117 mat.local_position(g_row[i_row], g_col[i_col], dest_rank[i], local_idx[i]);
120 data.resize(local_size);
121 load_binary(prefix, comm_rank, &(data[0]), local_size);
124 template <
template <
typename>
class Matrix,
typename C>
127 const size_t this_comm_size = mat.get_comm_size();
128 const size_t this_comm_rank = mat.get_comm_rank();
130 std::vector<int> dest_rank;
131 std::vector<size_t> local_idx;
133 int n = loaded_comm_size / this_comm_size;
134 if (loaded_comm_size % this_comm_size > 0) n += 1;
135 for (
int i = 0; i < n; ++i) {
136 int comm_rank = this_comm_rank + i * this_comm_size;
137 if (comm_rank < loaded_comm_size) {
142 local_idx.resize(local_size);
143 dest_rank.resize(local_size);
144 data.resize(local_size);
std::string filename(const std::string &prefix, int proc_size)
Definition: common.hpp:32
List of header files for matrix classes.
void load_local_files(const std::string &prefix, int comm_rank, size_t &local_size, std::vector< int > &dest_rank, std::vector< size_t > &local_idx, std::vector< C > &data, const Matrix< C > &mat)
Definition: io_helper.hpp:77
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
std::string index_filename(const std::string &prefix, int comm_rank)
Definition: io_helper.hpp:57
std::string binary_filename(const std::string &prefix, int comm_rank)
Definition: io_helper.hpp:49
void load_scalapack(const std::string &prefix, int loaded_comm_size, Matrix< C > &mat)
Definition: io_helper.hpp:125
void replace_matrix_data(const Matrix< C > &M, const std::vector< int > &dest_rank, const std::vector< size_t > &local_position, Matrix< C > &M_new)
Definition: matrix_lapack_impl.hpp:323
Definition: complex.hpp:34