From c865c5caad623f0452e385e56d68aa6243886632 Mon Sep 17 00:00:00 2001
From: Sebastian Eibl <sebastian.eibl@fau.de>
Date: Tue, 8 Jan 2019 10:36:55 +0100
Subject: [PATCH] BufferSystem now provides number of bytes sent/received

---
 src/core/mpi/BufferSystem.cpp       | 12 ++++++++++++
 src/core/mpi/BufferSystem.h         |  6 ++++++
 tests/core/mpi/BufferSystemTest.cpp |  6 ++++++
 3 files changed, 24 insertions(+)

diff --git a/src/core/mpi/BufferSystem.cpp b/src/core/mpi/BufferSystem.cpp
index 551fce3e6..cfe037d8f 100644
--- a/src/core/mpi/BufferSystem.cpp
+++ b/src/core/mpi/BufferSystem.cpp
@@ -53,6 +53,9 @@ void BufferSystem::iterator::operator++()
    currentRecvBuffer_ = bufferSystem_.waitForNext( currentSenderRank_ );
    if ( ! currentRecvBuffer_ ) {
       WALBERLA_ASSERT_EQUAL( currentSenderRank_, -1 );
+   } else
+   {
+      bufferSystem_.bytesReceived_ += currentRecvBuffer_->size() * sizeof(RecvBuffer::ElementType);
    }
 }
 
@@ -303,7 +306,10 @@ void BufferSystem::sendAll()
       if ( ! iter->second.alreadySent )
       {
          if ( iter->second.buffer.size() > 0 )
+         {
+            bytesSent_ += iter->second.buffer.size() * sizeof(SendBuffer::ElementType);
             currentComm_->send( iter->first, iter->second.buffer );
+         }
 
          iter->second.alreadySent = true;
       }
@@ -331,7 +337,10 @@ void BufferSystem::send( MPIRank rank )
    WALBERLA_ASSERT( ! iter->second.alreadySent ); // this buffer has already been sent
 
    if ( iter->second.buffer.size() > 0 )
+   {
+      bytesSent_ += iter->second.buffer.size() * sizeof(SendBuffer::ElementType);
       currentComm_->send( rank, iter->second.buffer );
+   }
 
    iter->second.alreadySent = true;
 }
@@ -362,6 +371,9 @@ void BufferSystem::startCommunication()
 
    currentComm_->scheduleReceives( recvInfos_ );
    communicationRunning_ = true;
+
+   bytesSent_     = 0;
+   bytesReceived_ = 0;
 }
 
 
diff --git a/src/core/mpi/BufferSystem.h b/src/core/mpi/BufferSystem.h
index a79322d1a..03ea8bcbe 100644
--- a/src/core/mpi/BufferSystem.h
+++ b/src/core/mpi/BufferSystem.h
@@ -193,6 +193,9 @@ public:
    //@}
    //*******************************************************************************************************************
 
+   int64_t getBytesSent() const { return bytesSent_; }
+   int64_t getBytesReceived() const { return bytesReceived_; }
+
 
    //* Rank Ranges     *************************************************************************************************
    /*! \name Rank Ranges  */
@@ -240,6 +243,9 @@ protected:
    //stores tags of running communications in debug mode to ensure that
    //each concurrently running communication uses different tags
    static std::set<int> activeTags_;
+
+   int64_t bytesSent_     = 0; ///< number of bytes sent during last communication
+   int64_t bytesReceived_ = 0; ///< number of bytes received during last communication
 };
 
 
diff --git a/tests/core/mpi/BufferSystemTest.cpp b/tests/core/mpi/BufferSystemTest.cpp
index a57d24123..d84d12da3 100644
--- a/tests/core/mpi/BufferSystemTest.cpp
+++ b/tests/core/mpi/BufferSystemTest.cpp
@@ -110,6 +110,9 @@ void symmetricCommunication()
 
       WALBERLA_CHECK_EQUAL( receivedVal, it.rank() );
    }
+
+   WALBERLA_CHECK_EQUAL( bs.getBytesSent(), (MSG_SIZE * sizeof(int) + MSG_SIZE * mpi::BUFFER_DEBUG_OVERHEAD) * 2 );
+   WALBERLA_CHECK_EQUAL( bs.getBytesReceived(), (MSG_SIZE * sizeof(int) + MSG_SIZE * mpi::BUFFER_DEBUG_OVERHEAD) * 2 );
 }
 
 /**
@@ -175,6 +178,9 @@ void asymmetricCommunication()
          WALBERLA_CHECK( it.buffer().isEmpty() );
       }
    }
+
+   WALBERLA_CHECK_EQUAL( bs.getBytesSent(), int64_c(sizeof(int) + mpi::BUFFER_DEBUG_OVERHEAD) * int64_c(rank + rank) );
+   WALBERLA_CHECK_EQUAL( bs.getBytesReceived(), int64_c(sizeof(int) + mpi::BUFFER_DEBUG_OVERHEAD) * int64_c(leftNeighbor + rightNeighbor) );
 }
 
 
-- 
GitLab