From 41873b6ede77ce6126b94d4b307d9b1d5be31426 Mon Sep 17 00:00:00 2001
From: Michael Buehlmann <buehlmann.michi@gmail.com>
Date: Thu, 7 Sep 2023 15:31:27 -0500
Subject: [PATCH] remove rebalance_sourceranks function

(was added 2 years ago and did not turn out to be useful.
Also causing problems on some compilers, eg on theta)
---
 GenericIO.cxx        | 33 ---------------------------------
 GenericIO.h          |  3 ---
 python/genericio.cpp | 13 -------------
 3 files changed, 49 deletions(-)

diff --git a/GenericIO.cxx b/GenericIO.cxx
index ac00f34..bcae435 100644
--- a/GenericIO.cxx
+++ b/GenericIO.cxx
@@ -1793,39 +1793,6 @@ void GenericIO::readData(int EffRank, size_t RowOffset, int Rank,
   }
 }
 
-#ifndef GENERICIO_NO_MPI
-void GenericIO::rebalanceSourceRanks() {
-  if(Redistributing) {
-    int NRanks, Rank;
-    MPI_Comm_rank(Comm, &Rank);
-    MPI_Comm_size(Comm, &NRanks);
-
-    std::vector<std::pair<int, size_t>> rank_sizes;
-    std::vector<std::tuple<int, size_t, std::vector<int>>> new_source_ranks;
-    for(int i=0; i<NRanks; ++i) {
-      new_source_ranks.emplace_back(std::make_tuple(i, 0ul, std::vector<int>()));
-    }
-    for(int i=0; i<readNRanks(); ++i) {
-      rank_sizes.emplace_back(std::make_pair(i, readNumElems(i)));
-    }
-    std::sort(rank_sizes.begin(), rank_sizes.end(), [](const auto& p1, const auto& p2){ return p1.second > p2.second; });
-    // Distribute ranks
-    for(size_t i=0; i<rank_sizes.size(); ++i) {
-      // Assign to first rank
-      std::get<2>(new_source_ranks[0]).push_back(rank_sizes[i].first);
-      std::get<1>(new_source_ranks[0]) += rank_sizes[i].second;
-      // Reorder ranks (could be optimized since array already sorted)
-      std::stable_sort(new_source_ranks.begin(), new_source_ranks.end(), [](const auto& s1, const auto& s2){ return std::get<1>(s1) < std::get<1>(s2); });
-    }
-    // copy own array
-    SourceRanks.resize(0);
-    std::copy(std::get<2>(new_source_ranks[Rank]).begin(), std::get<2>(new_source_ranks[Rank]).end(), std::back_inserter(SourceRanks));
-  } else {
-    std::cerr << "rebalancing source ranks has no effect when Redistributing==false" << std::endl;
-  }
-}
-#endif
-
 void GenericIO::getVariableInfo(vector<VariableInfo> &VI) {
   if (FH.isBigEndian())
     getVariableInfo<true>(VI);
diff --git a/GenericIO.h b/GenericIO.h
index 02bf685..3241415 100644
--- a/GenericIO.h
+++ b/GenericIO.h
@@ -439,9 +439,6 @@ public:
   int readGlobalRankNumber(int EffRank = -1);
 
   void readData(int EffRank = -1, bool PrintStats = true, bool CollStats = true);
-#ifndef GENERICIO_NO_MPI
-  void rebalanceSourceRanks();
-#endif
   void getSourceRanks(std::vector<int> &SR);
 
   void close() {
diff --git a/python/genericio.cpp b/python/genericio.cpp
index a29d478..64bc989 100644
--- a/python/genericio.cpp
+++ b/python/genericio.cpp
@@ -204,14 +204,9 @@ std::map<std::string, py::array> read_genericio(
     PyGenericIO::MismatchBehavior redistribute=PyGenericIO::MismatchBehavior::MismatchRedistribute,
     bool print_stats=true,
     bool collective_stats=true,
-    bool rebalance_source_ranks=false,
     int eff_rank=-1
   ) {
   PyGenericIO reader(filename, method, redistribute, eff_rank);
-#ifndef GENERICIO_NO_MPI
-  if(rebalance_source_ranks)
-    reader.rebalanceSourceRanks();
-#endif
   return reader.read(var_names, print_stats, collective_stats, eff_rank);
 }
 
@@ -383,7 +378,6 @@ PYBIND11_MODULE(pygio, m) {
       .def_static("setNaturalDefaultPartition", &PyGenericIO::setNaturalDefaultPartition)
       .def_static("setDefaultFileIOType", &PyGenericIO::setDefaultFileIOType)
 #ifndef GENERICIO_NO_MPI
-      .def("rebalance_source_ranks", &PyGenericIO::rebalanceSourceRanks)
       .def_static("setCollectiveMPIIOThreshold", &PyGenericIO::setCollectiveMPIIOThreshold)
 #endif
       ;
@@ -423,12 +417,6 @@ PYBIND11_MODULE(pygio, m) {
         collective_stats: bool
             if ``True``, aggregate statistics among reading ranks (if using MPI)
 
-        rebalance_sourceranks: bool
-            if ``True``, the code will re-assign the file ranks to the reading
-            MPI ranks to equalize the data size each rank is reading. Only
-            relevant if using MPI and more ranks were used to write the file
-            than reading.
-
         Returns
         -------
         data: Mapping[str, np.ndarray]
@@ -441,7 +429,6 @@ PYBIND11_MODULE(pygio, m) {
         py::arg("redistribute")=PyGenericIO::MismatchBehavior::MismatchRedistribute,
         py::arg("print_stats")=true,
         py::arg("collective_stats")=true,
-        py::arg("rebalance_sourceranks")=false,
         py::arg("eff_rank")=-1,
         py::return_value_policy::move);
 
-- 
GitLab