From 828c3c7949c59dda4b64edb4f4a3d239c75b509b Mon Sep 17 00:00:00 2001 From: "Franz G. Fuchs" Date: Fri, 11 Jan 2019 19:05:11 +0100 Subject: [PATCH] fix for variable number of messages --- opm/simulators/gatherDeferredLogger.cpp | 13 ++++- tests/test_gatherdeferredlogger.cpp | 69 +++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/opm/simulators/gatherDeferredLogger.cpp b/opm/simulators/gatherDeferredLogger.cpp index ae93482ed..8a457d81d 100644 --- a/opm/simulators/gatherDeferredLogger.cpp +++ b/opm/simulators/gatherDeferredLogger.cpp @@ -34,6 +34,9 @@ namespace void packMessages(const std::vector& local_messages, std::vector& buf, int& offset) { + int messagesize = local_messages.size(); + MPI_Pack(&messagesize, 1, MPI_UNSIGNED, buf.data(), buf.size(), &offset, MPI_COMM_WORLD); + for (const auto lm : local_messages) { MPI_Pack(&lm.flag, 1, MPI_INT64_T, buf.data(), buf.size(), &offset, MPI_COMM_WORLD); int tagsize = lm.tag.size(); @@ -80,9 +83,15 @@ namespace { std::vector messages; const int num_processes = displ.size() - 1; + auto* data = const_cast(recv_buffer.data()); for (int process = 0; process < num_processes; ++process) { int offset = displ[process]; - messages.push_back(unpackSingleMessage(recv_buffer, offset)); + // unpack number of messages + unsigned int messagesize; + MPI_Unpack(data, recv_buffer.size(), &offset, &messagesize, 1, MPI_UNSIGNED, MPI_COMM_WORLD); + for (unsigned int i=0; i("COUNTER"); + BOOST_CHECK_EQUAL( 0 , counter->numMessages(Log::MessageType::Info) ); + + std::string expected; + BOOST_CHECK_EQUAL(log_stream.str(), expected); + std::cerr<<""<("COUNTER"); + BOOST_CHECK_EQUAL( 1 , counter->numMessages(Log::MessageType::Info) ); + BOOST_CHECK_EQUAL( 1 , counter->numMessages(Log::MessageType::Warning) ); + BOOST_CHECK_EQUAL( 4 , counter->numMessages(Log::MessageType::Bug) ); + + const std::string expected = Log::prefixMessage(Log::MessageType::Info, "info from rank 1") + "\n" + + Log::prefixMessage(Log::MessageType::Warning, "warning from rank 1") + "\n" + + Log::prefixMessage(Log::MessageType::Bug, "bug from rank 2") + "\n" + + Log::prefixMessage(Log::MessageType::Bug, "bug from rank 2") + "\n" + + Log::prefixMessage(Log::MessageType::Bug, "Message limit reached for message tag: tagme") + "\n"; + BOOST_CHECK_EQUAL(log_stream.str(), expected); + std::cerr<<""<