From 9bd7bff3fa24c93428ea1eb5c0f959f192d16753 Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Fri, 31 May 2019 11:15:21 +0200
Subject: [PATCH] Field communication benchmark

---
 .../FieldCommunication/FieldCommunication.cpp |  2 +-
 apps/benchmarks/FieldCommunication/config.py  | 39 +++++++++++++++----
 python/waLBerla/__init__.py                   | 23 ++++++++---
 3 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/apps/benchmarks/FieldCommunication/FieldCommunication.cpp b/apps/benchmarks/FieldCommunication/FieldCommunication.cpp
index 0a301898..2273126b 100644
--- a/apps/benchmarks/FieldCommunication/FieldCommunication.cpp
+++ b/apps/benchmarks/FieldCommunication/FieldCommunication.cpp
@@ -36,7 +36,7 @@ class SingleMessageBufferedScheme
 public:
     typedef Stencil_T Stencil;
 
-    SingleMessageBufferedScheme( weak_ptr_wrapper< StructuredBlockForest > bf, const int tag = 17953 )
+    SingleMessageBufferedScheme( const weak_ptr_wrapper< StructuredBlockForest > & bf, const int tag = 17953 )
             : blockForest_( bf ), tag_( tag ) {}
 
     inline void addDataToCommunicate( const shared_ptr< communication::UniformPackInfo > &packInfo )
diff --git a/apps/benchmarks/FieldCommunication/config.py b/apps/benchmarks/FieldCommunication/config.py
index 09a8d677..56b480f1 100644
--- a/apps/benchmarks/FieldCommunication/config.py
+++ b/apps/benchmarks/FieldCommunication/config.py
@@ -2,11 +2,17 @@ import waLBerla
 import subprocess
 import re
 from collections import defaultdict
+import sys
+from datetime import timedelta
 
 base = (32, 16, 2, 64)
 BlOCK_SIZES_SQ = [(i, i, i) for i in base]
 BLOCK_SIZES_RECT = [(i, i, i // 2) for i in base] + [(i, i // 2, i // 2) for i in base]
 
+time_for_benchmark = 0.25
+outer_iterations = 2
+db_file = 'FieldCommunication.sqlite'
+
 
 def supermuc_network_spread():
     try:
@@ -28,7 +34,7 @@ sng_network = supermuc_network_spread()
 
 class AlreadySimulated:
 
-    def __init__(self, db_file, properties=('layout', 'ghostLayers', 'cartesianCommunicator', 'stencil',
+    def __init__(self, db_file, properties=('processes0*processes1*processes2', 'layout', 'ghostLayers', 'cartesianCommunicator', 'stencil',
                                             'cellsPerBlock0', 'cellsPerBlock1', 'cellsPerBlock2',
                                             'blocksPerProcess', 'localCommunicationMode', 'singleMessage',
                                             'fieldsPdf', 'fieldsPdfOpt', 'fieldsVector', 'fieldsScalar',
@@ -50,9 +56,13 @@ class AlreadySimulated:
 
 
 @waLBerla.callback("config")
-def config():
-    simulated_db = AlreadySimulated('FieldCommunication.sqlite')
+def config(processes=None):
+    simulated_db = AlreadySimulated(db_file)
+    isWalberlaRun = processes is None
     skipped = 0
+    simulated = 0
+    if isWalberlaRun:
+        processes = waLBerla.mpi.numProcesses()
     for layout in ('fzyx', 'zyxf'):
         for ghost_layers in (1, 2):
             for cartesian_comm in (False, True):
@@ -67,14 +77,18 @@ def config():
                                             if blocksPerProcess >= 8 and cells[0] >= 64 and cells[1] >= 64 and cells[2] >= 64:
                                                 continue
 
-                                            data = (layout, ghost_layers, int(cartesian_comm), stencil, *cells, blocksPerProcess, local_comm,
+                                            data = (processes, layout, ghost_layers, int(cartesian_comm), stencil, *cells, blocksPerProcess, local_comm,
                                                     int(single_message), pdf, pdf_opt, vector, scalar, buffered)
 
                                             if simulated_db.in_db(data):
                                                 skipped += 1
-                                                if skipped % 100 == 0:
+                                                if skipped % 100 == 0 and isWalberlaRun:
                                                     waLBerla.log_info_on_root("Skipped {} scenarios".format(skipped))
                                                 continue
+                                            else:
+                                                simulated += 1
+                                                if not isWalberlaRun:
+                                                    continue
 
                                             cfg = {
                                                 'Domain': {
@@ -100,9 +114,9 @@ def config():
                                                 'Run': {
                                                     'warmupIterations': 3,
                                                     'iterations': 100,
-                                                    'outerIterations': 2,
-                                                    'databaseFile': 'FieldCommunication.sqlite',
-                                                    'timeForBenchmark': 0.25,
+                                                    'outerIterations': outer_iterations,
+                                                    'databaseFile': db_file,
+                                                    'timeForBenchmark': time_for_benchmark,
                                                     'minIterations': 2,
                                                     'maxIterations': 10000,
                                                 },
@@ -114,3 +128,12 @@ def config():
                                                 }
                                             }
                                             yield cfg
+    if not isWalberlaRun:
+        print("Skipped", skipped, "to simulate", simulated)
+        estimated_seconds = simulated * time_for_benchmark * outer_iterations
+        print("Estimated time ", timedelta(seconds=estimated_seconds))
+
+
+if __name__ == '__main__':
+    for _ in config(int(sys.argv[1])):
+        pass
diff --git a/python/waLBerla/__init__.py b/python/waLBerla/__init__.py
index 93244d0a..3de7ea24 100644
--- a/python/waLBerla/__init__.py
+++ b/python/waLBerla/__init__.py
@@ -1,5 +1,5 @@
 from .callbacks import callback, ScenarioManager, memberCallback
-from .callbacks import memberCallback as member_callback # deprecated, was renamed to memberCallback
+from .callbacks import memberCallback as member_callback  # deprecated, was renamed to memberCallback
 
 import sys
 
@@ -8,18 +8,31 @@ import sys
 
 try:
     from .walberla_cpp import *
-    cpp_available=True
+    cpp_available = True
 except ImportError:
     try:
         from walberla_cpp import *
-        cpp_available=True
+        cpp_available = True
     except ImportError:
-        cpp_available=False
+        cpp_available = False
+        thismodule = sys.modules[__name__]
+        thismodule.log_info_on_root = print
+        thismodule.log_progress_on_root = print
+        thismodule.log_result_on_root = print
+        thismodule.log_devel_on_root = print
+        thismodule.log_detail_on_root = print
+        thismodule.log_warning_on_root = print
+        thismodule.log_info = print
+        thismodule.log_result = print
+        thismodule.log_devel = print
+        thismodule.log_progress = print
+        thismodule.log_detail = print
+        thismodule.log_warning = print
 
 if cpp_available:
     from .core_extension  import extend as extend_core
     thismodule = sys.modules[__name__]
-    extend_core ( thismodule )
+    extend_core(thismodule)
 
     if 'field' in globals(): # check if field was exported
         # Update modules dict to be able to write e.g. from waLBerla import field
-- 
GitLab