From ff97334f3f76d8aa394d6e9e75fb8b824f72e810 Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Wed, 31 Oct 2018 13:45:17 +0100
Subject: [PATCH] Extracted JSON conversion of timing data structures

- CUDA compiler has problems to compile external json library
- timing pool is included by BlockForest, and previously timing pool
  included JSON library
---
 src/core/timing/Timer.h      | 16 --------
 src/core/timing/TimingJSON.h | 72 ++++++++++++++++++++++++++++++++++++
 src/core/timing/TimingNode.h | 16 --------
 src/core/timing/TimingTree.h |  8 ----
 4 files changed, 72 insertions(+), 40 deletions(-)
 create mode 100644 src/core/timing/TimingJSON.h

diff --git a/src/core/timing/Timer.h b/src/core/timing/Timer.h
index ec0cc9ee3..86814b043 100644
--- a/src/core/timing/Timer.h
+++ b/src/core/timing/Timer.h
@@ -27,7 +27,6 @@
 #include "CpuPolicy.h"
 #include "WcPolicy.h"
 #include "core/DataTypes.h"
-#include "core/extern/json.hpp"
 
 #include <limits>
 
@@ -442,21 +441,6 @@ inline void Timer<TP>::merge( const Timer<TP> & other )
 }
 //**********************************************************************************************************************
 
-//**********************************************************************************************************************
-/*!\brief Converts timer to json The signature is required by the json library
-// \relates Timer
-*/
-template < typename TP > // Timing policy
-void to_json( nlohmann::json& j, const Timer< TP >& timer )
-{
-   j = nlohmann::json{{"total", timer.total()},
-                      {"average", timer.average()},
-                      {"count", timer.getCounter()},
-                      {"min", timer.min()},
-                      {"max", timer.max()},
-                      {"variance", timer.variance()}};
-}
-//**********************************************************************************************************************
 
 } // namespace timing
 
diff --git a/src/core/timing/TimingJSON.h b/src/core/timing/TimingJSON.h
new file mode 100644
index 000000000..b6826f367
--- /dev/null
+++ b/src/core/timing/TimingJSON.h
@@ -0,0 +1,72 @@
+//======================================================================================================================
+//
+//  This file is part of waLBerla. waLBerla is free software: you can
+//  redistribute it and/or modify it under the terms of the GNU General Public
+//  License as published by the Free Software Foundation, either version 3 of
+//  the License, or (at your option) any later version.
+//
+//  waLBerla is distributed in the hope that it will be useful, but WITHOUT
+//  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+//  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+//  for more details.
+//
+//  You should have received a copy of the GNU General Public License along
+//  with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
+//
+//! \file Timer.h
+//! \ingroup core
+//!
+//
+//======================================================================================================================
+
+#include "core/extern/json.hpp"
+#include "core/timing/Timer.h"
+#include "core/timing/TimingNode.h"
+#include "core/timing/TimingTree.h"
+
+
+namespace walberla {
+namespace timing {
+
+
+/*! Converts timer to json The signature is required by the json library
+// \relates Timer
+*/
+template < typename TP > // Timing policy
+void to_json( nlohmann::json& j, const Timer< TP >& timer )
+{
+   j = nlohmann::json{{"total", timer.total()},
+                      {"average", timer.average()},
+                      {"count", timer.getCounter()},
+                      {"min", timer.min()},
+                      {"max", timer.max()},
+                      {"variance", timer.variance()}};
+}
+
+/// Converts a TimingNode to json. The signature is required by the json library
+/// \relates TimingNode
+template < typename TP > // Timing policy
+void to_json( nlohmann::json& j, const TimingNode< TP >& tn )
+{
+   /// ignore the first timer in the timing node since it is empty
+   if( tn.last_ == nullptr )
+   {
+      j = nlohmann::json( tn.tree_ );
+   } else
+   {
+      j           = nlohmann::json( tn.timer_ );
+      j["childs"] = nlohmann::json( tn.tree_ );
+   }
+}
+
+/// Converts a TimingTree to json. The signature is required by the json library
+/// \relates TimingTree
+template < typename TP > // Timing policy
+void to_json( nlohmann::json& j, const TimingTree< TP >& tt )
+{
+   j = nlohmann::json( tt.getRawData() );
+}
+
+
+}
+}
\ No newline at end of file
diff --git a/src/core/timing/TimingNode.h b/src/core/timing/TimingNode.h
index 80f258690..9fa8fab62 100644
--- a/src/core/timing/TimingNode.h
+++ b/src/core/timing/TimingNode.h
@@ -30,7 +30,6 @@
 #include "core/mpi/MPIManager.h"
 #include "core/mpi/Reduce.h"
 #include "core/mpi/SetReduction.h"
-#include "core/extern/json.hpp"
 
 
 #include <algorithm>
@@ -483,21 +482,6 @@ std::ostream& operator<<(std::ostream& os, const TimingNode<TP>& tn)
    return os;
 }
 
-/// convertes a TimingNode to json. The signature is required by the json library
-/// \relates TimingNode
-template < typename TP > // Timing policy
-void to_json( nlohmann::json& j, const TimingNode< TP >& tn )
-{
-   /// ignore the first timer in the timing node since it is empty
-   if( tn.last_ == nullptr )
-   {
-      j = nlohmann::json( tn.tree_ );
-   } else
-   {
-      j           = nlohmann::json( tn.timer_ );
-      j["childs"] = nlohmann::json( tn.tree_ );
-   }
-}
 
 namespace internal {
 /// adds a sub timer containing the remainder of all other subtimers on the same hierarchy level
diff --git a/src/core/timing/TimingTree.h b/src/core/timing/TimingTree.h
index 8ae9b51c4..b4f4e736b 100644
--- a/src/core/timing/TimingTree.h
+++ b/src/core/timing/TimingTree.h
@@ -28,7 +28,6 @@
 #include "core/logging/Logging.h"
 #include "core/mpi/MPIManager.h"
 #include "core/mpi/Reduce.h"
-#include "core/extern/json.hpp"
 
 #include <algorithm>
 #include <iostream>
@@ -252,13 +251,6 @@ TimingTree< TP > TimingTree< TP >::getCopyWithRemainder() const
    return tt;
 }
 
-/// convertes a TimingTree to json. The signature is required by the json library
-/// \relates TimingTree
-template < typename TP > // Timing policy
-void to_json( nlohmann::json& j, const TimingTree< TP >& tt )
-{
-   j = nlohmann::json( tt.getRawData() );
-}
 }
 
 typedef timing::TimingTree<timing::WcPolicy>  WcTimingTree;
-- 
GitLab