From e25ebfffdb0d654523f71235de6d50e1950c7ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Thu, 29 Aug 2024 08:35:11 +0200 Subject: [PATCH 1/2] fix: distribute species names across all processes --- src/poet.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/poet.cpp b/src/poet.cpp index 6a16b177a..4a0abc2c1 100644 --- a/src/poet.cpp +++ b/src/poet.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ #include "Base/argh.hpp" #include +#include using namespace std; using namespace poet; @@ -403,6 +405,49 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, const RuntimeParameters ¶ms, return profiling; } +std::vector getSpeciesNames(const Field &&field, int root, + MPI_Comm comm) { + std::uint32_t n_elements; + std::uint32_t n_string_size; + + int rank; + MPI_Comm_rank(comm, &rank); + + const bool is_master = root == rank; + + // first, the master sends all the species names iterative + if (is_master) { + n_elements = field.GetProps().size(); + MPI_Bcast(&n_elements, 1, MPI_UINT32_T, root, MPI_COMM_WORLD); + + for (std::uint32_t i = 0; i < n_elements; i++) { + n_string_size = field.GetProps()[i].size(); + MPI_Bcast(&n_string_size, 1, MPI_UINT32_T, root, MPI_COMM_WORLD); + MPI_Bcast(const_cast(field.GetProps()[i].c_str()), n_string_size, + MPI_CHAR, root, MPI_COMM_WORLD); + } + + return field.GetProps(); + } + + // now all the worker stuff + MPI_Bcast(&n_elements, 1, MPI_UINT32_T, root, comm); + + std::vector species_names_out(n_elements); + + for (std::uint32_t i = 0; i < n_elements; i++) { + MPI_Bcast(&n_string_size, 1, MPI_UINT32_T, root, MPI_COMM_WORLD); + + char recv_buf[n_string_size]; + + MPI_Bcast(recv_buf, n_string_size, MPI_CHAR, root, MPI_COMM_WORLD); + + species_names_out[i] = std::string(recv_buf, n_string_size); + } + + return species_names_out; +} + int main(int argc, char *argv[]) { int world_size; @@ -442,7 +487,7 @@ int main(int argc, char *argv[]) { init_list.getChemistryInit(), MPI_COMM_WORLD); const ChemistryModule::SurrogateSetup surr_setup = { - init_list.getInitialGrid().GetProps(), + getSpeciesNames(init_list.getInitialGrid(), 0, MPI_COMM_WORLD), run_params.use_dht, run_params.dht_size, run_params.use_interp, From 1f9ffe999f9f18b5ff0b91a2a4e96a2ecf3d089e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Thu, 29 Aug 2024 08:35:17 +0200 Subject: [PATCH 2/2] Update subproject commit reference --- ext/iphreeqc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/iphreeqc b/ext/iphreeqc index e6e5e0d51..48e65d87a 160000 --- a/ext/iphreeqc +++ b/ext/iphreeqc @@ -1 +1 @@ -Subproject commit e6e5e0d5156c093241a53e6ce074ef346d64ae26 +Subproject commit 48e65d87ad70f84aec01c27d9560cd3094a8129c