5 #include "op_utility.hpp"
20 template <
typename VectorType>
21 void writeVectorToDisk(
const std::vector<VectorType> & vector,
int local_rank, std::string local_vector_string)
23 std::stringstream local_vector_file;
24 local_vector_file << local_vector_string <<
"." << local_rank;
25 std::ofstream local_vector(local_vector_file.str());
26 for (
auto v : vector) {
27 local_vector << v << std::endl;
40 template <
typename VectorType>
53 template <
typename VectorType>
54 void readVectorFromDisk(std::vector<VectorType> & vector,
int local_rank, std::string local_vector_string)
56 std::stringstream local_vector_file;
57 local_vector_file << local_vector_string <<
"." << local_rank;
58 std::ifstream local_vector(local_vector_file.str());
59 while (local_vector.good() && !local_vector.eof()) {
75 template <
typename VectorIndexType>
78 std::stringstream comm_pattern_file_name;
79 comm_pattern_file_name << comm_pattern_string <<
"." << local_rank;
80 std::ofstream comm_pattern_file(comm_pattern_file_name.str());
82 auto rank_comm = comm_pattern.rank_communication;
84 comm_pattern_file <<
"rank communication:" << std::endl;
85 comm_pattern_file <<
"send:" << std::endl;
86 for (
auto [rank, values] : rank_comm.send) {
87 comm_pattern_file << rank << std::endl <<
" : " << std::endl;
88 for (
auto v : values) {
89 comm_pattern_file << v << std::endl;
91 comm_pattern_file << std::endl;
94 comm_pattern_file <<
"recv:" << std::endl;
95 for (
auto [rank, values] : rank_comm.recv) {
96 comm_pattern_file << rank << std::endl <<
" : " << std::endl;
97 for (
auto v : values) {
98 comm_pattern_file << v << std::endl;
100 comm_pattern_file << std::endl;
103 comm_pattern_file <<
"owned_variable_list:" << std::endl;
104 for (
auto v : comm_pattern.owned_variable_list) {
105 comm_pattern_file << v << std::endl;
107 comm_pattern_file << std::endl;
109 comm_pattern_file <<
"local_variable_list:" << std::endl;
110 for (
auto v : comm_pattern.local_variable_list) {
111 comm_pattern_file << v << std::endl;
113 comm_pattern_file << std::endl;
114 comm_pattern_file.close();
125 template <
typename VectorIndexType>
130 std::stringstream comm_pattern_file_name;
131 comm_pattern_file_name << comm_pattern_string <<
"." << local_rank;
132 std::ifstream comm_pattern_file(comm_pattern_file_name.str());
134 auto rank_comm = comm_pattern.rank_communication;
139 std::getline(comm_pattern_file, buffer);
142 std::getline(comm_pattern_file, buffer);
144 if (buffer ==
"send:") {
146 while(comm_pattern_file.good()) {
148 std::getline(comm_pattern_file, buffer);
149 if (buffer ==
"recv:")
break;
150 int rank = std::stoi(buffer);
152 std::getline(comm_pattern_file, buffer);
154 std::getline(comm_pattern_file, buffer);
156 VectorIndexType indices;
157 while (comm_pattern_file.good() && buffer.length() > 0) {
158 std::size_t index = std::stoul(buffer);
159 indices.push_back(index);
161 std::getline(comm_pattern_file, buffer);
164 comm_pattern.rank_communication.send[rank] = indices;
168 if (buffer ==
"recv:") {
170 while(comm_pattern_file.good()) {
172 std::getline(comm_pattern_file, buffer);
173 if (buffer ==
"owned_variable_list:")
break;
174 int rank = std::stoi(buffer);
176 std::getline(comm_pattern_file, buffer);
178 std::getline(comm_pattern_file, buffer);
180 VectorIndexType indices;
181 while (comm_pattern_file.good() && buffer.length() > 0) {
182 std::size_t index = std::stoul(buffer);
183 indices.push_back(index);
185 std::getline(comm_pattern_file, buffer);
188 comm_pattern.rank_communication.recv[rank] = indices;
194 std::getline(comm_pattern_file, buffer);
195 while(comm_pattern_file.good() && buffer.length() > 0) {
196 if constexpr (std::is_same_v<typename VectorIndexType::value_type, int>) {
197 comm_pattern.owned_variable_list.push_back(std::stoi(buffer));
198 }
else if constexpr(std::is_same_v<typename VectorIndexType::value_type, std::size_t>){
199 comm_pattern.owned_variable_list.push_back(std::stoul(buffer));
202 std::getline(comm_pattern_file, buffer);
207 std::getline(comm_pattern_file, buffer);
209 std::getline(comm_pattern_file, buffer);
210 while(comm_pattern_file.good() && buffer.length() > 0) {
211 if constexpr (std::is_same_v<typename VectorIndexType::value_type, int>) {
212 comm_pattern.local_variable_list.push_back(std::stoi(buffer));
213 }
else if constexpr(std::is_same_v<typename VectorIndexType::value_type, std::size_t>){
214 comm_pattern.local_variable_list.push_back(std::stoul(buffer));
217 std::getline(comm_pattern_file, buffer);
220 comm_pattern_file.close();
Abstracted Optimization Vector container.
VectorType & data()
Get the underlying data.
void writeCommPatternToDisk(op::utility::CommPattern< VectorIndexType > &comm_pattern, int local_rank, std::string comm_pattern_string="pattern")
Write comm_pattern to disk. Files are named comm_pattern_string.rank.
Complete Op communication pattern information.
void writeVectorToDisk(const std::vector< VectorType > &vector, int local_rank, std::string local_vector_string)
Write vector to disk. Files are named vector_string.rank.
void writeVariablesToDisk(const op::Vector< VectorType > &op_variables, int local_rank, std::string local_variable_string="local_variables")
Write local variables to disk. Files are named local_variable_string.rank.
void readVectorFromDisk(std::vector< VectorType > &vector, int local_rank, std::string local_vector_string)
Read vector to disk. Files are named vector_string.rank.
op::utility::CommPattern< VectorIndexType > readCommPatternFromDisk(int local_rank, std::string comm_pattern_string="pattern")
Read comm_pattern to disk. Files are named comm_pattern_string.rank.