From 130d5f6b7506affb5b30df134258a5d8ebb35241 Mon Sep 17 00:00:00 2001
From: Michael Buehlmann <michael.buehlmann@gmail.com>
Date: Tue, 19 Jan 2021 10:31:39 -0600
Subject: [PATCH] add print_stats to new_python

allows suprressing the "Read [...] variables ... " stdout logs
---
 new_python/genericio.cpp | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/new_python/genericio.cpp b/new_python/genericio.cpp
index 59cf08b..8719477 100644
--- a/new_python/genericio.cpp
+++ b/new_python/genericio.cpp
@@ -61,7 +61,11 @@ public:
     }
   }
 
-  std::map<std::string, py::array> read(std::optional<std::vector<std::string>> var_names) {
+  std::map<std::string, py::array> read(
+      std::optional<std::vector<std::string>> var_names, 
+      bool print_stats=true, 
+      bool collective_stats=true
+    ) {
     // read number of elements
     int64_t num_elem = readNumElems();
     
@@ -104,7 +108,7 @@ public:
       }
     }
     
-    readData();
+    readData(-1, print_stats, collective_stats);
   #ifndef GENERICIO_NO_MPI
     MPI_Barrier(MPI_COMM_WORLD);
   #endif
@@ -141,6 +145,8 @@ std::map<std::string, py::array> read_genericio(
     std::optional<std::vector<std::string>> var_names, 
     PyGenericIO::FileIO method=PyGenericIO::FileIO::FileIOPOSIX, 
     PyGenericIO::MismatchBehavior redistribute=PyGenericIO::MismatchBehavior::MismatchRedistribute, 
+    bool print_stats=true,
+    bool collective_stats=true,
     bool rebalance_source_ranks=false
   ) {
   PyGenericIO reader(filename, method, redistribute);
@@ -148,7 +154,7 @@ std::map<std::string, py::array> read_genericio(
   if(rebalance_source_ranks)
     reader.rebalanceSourceRanks();
 #endif
-  return reader.read(var_names);
+  return reader.read(var_names, print_stats, collective_stats);
 }
 
 void inspect_genericio(
@@ -250,7 +256,7 @@ PYBIND11_MODULE(pygio, m) {
       .def("read_total_num_elems", (uint64_t (PyGenericIO::*)(void))(&PyGenericIO::readTotalNumElems))
       .def("read_phys_origin", &PyGenericIO::read_phys_origin)
       .def("read_phys_scale", &PyGenericIO::read_phys_scale)
-      .def("read", &PyGenericIO::read, py::arg("variables")=nullptr)
+      .def("read", &PyGenericIO::read, py::arg("variables")=nullptr, py::arg("print_stats")=true, py::arg("collective_stats")=true)
       .def("get_source_ranks", &PyGenericIO::getSourceRanks)
 #ifndef GENERICIO_NO_MPI
       .def("rebalance_source_ranks", &PyGenericIO::rebalanceSourceRanks)
@@ -273,6 +279,8 @@ PYBIND11_MODULE(pygio, m) {
         py::kw_only(),
         py::arg("method")=PyGenericIO::FileIO::FileIOPOSIX, 
         py::arg("redistribute")=PyGenericIO::MismatchBehavior::MismatchRedistribute, 
+        py::arg("print_stats")=true,
+        py::arg("collective_stats")=true,
         py::arg("rebalance_sourceranks")=false, 
         py::return_value_policy::move);
 
-- 
GitLab