diff options
author | 2022-05-30 19:00:25 +0200 | |
---|---|---|
committer | 2022-05-30 10:00:25 -0700 | |
commit | e267ac91316d5c590f3b73af20f4c5c567068e46 (patch) | |
tree | db8b35542186c4bc0d4cba6507ebe49885500046 /Source/Utils/MsgLogger/MsgLogger.cpp | |
parent | f630bf6d4e8e973276d6078f19a0e2be8764f034 (diff) | |
download | WarpX-e267ac91316d5c590f3b73af20f4c5c567068e46.tar.gz WarpX-e267ac91316d5c590f3b73af20f4c5c567068e46.tar.zst WarpX-e267ac91316d5c590f3b73af20f4c5c567068e46.zip |
move serialization to ablastr (#3145)
Diffstat (limited to 'Source/Utils/MsgLogger/MsgLogger.cpp')
-rw-r--r-- | Source/Utils/MsgLogger/MsgLogger.cpp | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/Source/Utils/MsgLogger/MsgLogger.cpp b/Source/Utils/MsgLogger/MsgLogger.cpp index 45e275129..df303e0b8 100644 --- a/Source/Utils/MsgLogger/MsgLogger.cpp +++ b/Source/Utils/MsgLogger/MsgLogger.cpp @@ -7,9 +7,10 @@ #include "MsgLogger.H" -#include "MsgLoggerSerialization.H" #include "Utils/TextMsg.H" +#include <ablastr/utils/Serialization.H> + #ifdef AMREX_USE_MPI # include <AMReX_ParallelDescriptor.H> #endif @@ -20,6 +21,7 @@ #include <numeric> using namespace Utils::MsgLogger; +namespace abl_ser = ablastr::utils::serialization; #ifdef AMREX_USE_MPI // Helper functions used only in this source file @@ -125,10 +127,10 @@ std::vector<char> Msg::serialize() const { std::vector<char> serialized_msg; - put_in(this->topic, serialized_msg); - put_in(this->text, serialized_msg); + abl_ser::put_in(this->topic, serialized_msg); + abl_ser::put_in(this->text, serialized_msg); const int int_priority = static_cast<int>(this->priority); - put_in(int_priority, serialized_msg); + abl_ser::put_in(int_priority, serialized_msg); return serialized_msg; } @@ -137,9 +139,9 @@ Msg Msg::deserialize (std::vector<char>::const_iterator& it) { Msg msg; - msg.topic = get_out<std::string> (it); - msg.text = get_out<std::string> (it); - msg.priority = static_cast<Priority> (get_out<int> (it)); + msg.topic = abl_ser::get_out<std::string> (it); + msg.text = abl_ser::get_out<std::string> (it); + msg.priority = static_cast<Priority> (abl_ser::get_out<int> (it)); return msg; } @@ -153,8 +155,8 @@ std::vector<char> MsgWithCounter::serialize() const { std::vector<char> serialized_msg_with_counter; - put_in_vec(msg.serialize(), serialized_msg_with_counter); - put_in(this->counter, serialized_msg_with_counter); + abl_ser::put_in_vec(msg.serialize(), serialized_msg_with_counter); + abl_ser::put_in(this->counter, serialized_msg_with_counter); return serialized_msg_with_counter; } @@ -163,10 +165,10 @@ MsgWithCounter MsgWithCounter::deserialize (std::vector<char>::const_iterator& i { MsgWithCounter msg_with_counter; - const auto vec = get_out_vec<char>(it); + const auto vec = abl_ser::get_out_vec<char>(it); auto iit = vec.begin(); msg_with_counter.msg = Msg::deserialize(iit); - msg_with_counter.counter = get_out<std::int64_t> (it); + msg_with_counter.counter = abl_ser::get_out<std::int64_t> (it); return msg_with_counter; } @@ -180,9 +182,9 @@ std::vector<char> MsgWithCounterAndRanks::serialize() const { std::vector<char> serialized_msg_with_counter_and_ranks; - put_in_vec(this->msg_with_counter.serialize(), serialized_msg_with_counter_and_ranks); - put_in(this->all_ranks, serialized_msg_with_counter_and_ranks); - put_in_vec(this->ranks, serialized_msg_with_counter_and_ranks); + abl_ser::put_in_vec(this->msg_with_counter.serialize(), serialized_msg_with_counter_and_ranks); + abl_ser::put_in(this->all_ranks, serialized_msg_with_counter_and_ranks); + abl_ser::put_in_vec(this->ranks, serialized_msg_with_counter_and_ranks); return serialized_msg_with_counter_and_ranks; } @@ -192,11 +194,11 @@ MsgWithCounterAndRanks::deserialize (std::vector<char>::const_iterator& it) { MsgWithCounterAndRanks msg_with_counter_and_ranks; - const auto vec = get_out_vec<char>(it); + const auto vec = abl_ser::get_out_vec<char>(it); auto iit = vec.begin(); msg_with_counter_and_ranks.msg_with_counter = MsgWithCounter::deserialize(iit); - msg_with_counter_and_ranks.all_ranks = get_out<bool>(it); - msg_with_counter_and_ranks.ranks = get_out_vec<int>(it); + msg_with_counter_and_ranks.all_ranks = abl_ser::get_out<bool>(it); + msg_with_counter_and_ranks.ranks = abl_ser::get_out_vec<int>(it); return msg_with_counter_and_ranks; } @@ -372,7 +374,7 @@ Logger::compute_msgs_with_counter_and_ranks( // get counters generated by rank rr auto it = all_data.begin() + displacements[rr]; - const auto counters_rr = get_out_vec<std::int64_t>(it); + const auto counters_rr = abl_ser::get_out_vec<std::int64_t>(it); //for each counter from rank rr std::int64_t c = 0; @@ -396,11 +398,11 @@ Logger::compute_msgs_with_counter_and_ranks( } // for each additional message coming from rank rr - const auto how_many_additional_msgs_with_counter = get_out<int>(it); + const auto how_many_additional_msgs_with_counter = abl_ser::get_out<int>(it); for(int i = 0; i < how_many_additional_msgs_with_counter; ++i){ //deserialize the message - const auto serialized_msg_with_counter = get_out_vec<char>(it); + const auto serialized_msg_with_counter = abl_ser::get_out_vec<char>(it); auto msg_with_counter = MsgWithCounter::deserialize(serialized_msg_with_counter.begin()); @@ -460,7 +462,7 @@ void Logger::swap_with_io_rank( if(m_rank == gather_rank){ auto package = std::vector<char>{}; for (const auto& el: msgs_with_counter_and_ranks) - put_in_vec<char>(el.serialize(), package); + abl_ser::put_in_vec<char>(el.serialize(), package); auto package_size = static_cast<int>(package.size()); amrex::ParallelDescriptor::Send(&package_size, 1, m_io_rank, 0); @@ -477,7 +479,7 @@ void Logger::swap_with_io_rank( amrex::ParallelDescriptor::Recv(&list_size, 1, gather_rank, 2); auto it = package.cbegin(); for (int i = 0; i < list_size; ++i){ - const auto vec = get_out_vec<char>(it); + const auto vec = abl_ser::get_out_vec<char>(it); msgs_with_counter_and_ranks.emplace_back( MsgWithCounterAndRanks::deserialize(vec.begin()) ); @@ -548,12 +550,12 @@ compute_package_for_gather_rank( } counter++; } - put_in_vec(gather_rank_msg_counters, package); + abl_ser::put_in_vec(gather_rank_msg_counters, package); // Add the additional messages seen by the current rank to the package - put_in(static_cast<int>(msgs_to_send.size()), package); + abl_ser::put_in(static_cast<int>(msgs_to_send.size()), package); for (const auto& el : msgs_to_send) - put_in_vec<char>( + abl_ser::put_in_vec<char>( MsgWithCounter{el.first, el.second}.serialize(), package); return package; @@ -620,10 +622,10 @@ std::vector<char> serialize_msgs( auto serialized = std::vector<char>{}; const auto how_many = static_cast<int> (msgs.size()); - put_in (how_many, serialized); + abl_ser::put_in (how_many, serialized); for (const auto& msg : msgs){ - put_in_vec(msg.serialize(), serialized); + abl_ser::put_in_vec(msg.serialize(), serialized); } return serialized; } @@ -633,12 +635,12 @@ std::vector<Msg> deserialize_msgs( { auto it = serialized.begin(); - const auto how_many = get_out<int>(it); + const auto how_many = abl_ser::get_out<int>(it); auto msgs = std::vector<Msg>{}; msgs.reserve(how_many); for (int i = 0; i < how_many; ++i){ - const auto vv = get_out_vec<char>(it); + const auto vv = abl_ser::get_out_vec<char>(it); msgs.emplace_back(Msg::deserialize(vv.begin())); } |