diff --git a/include/realizations/catchment/Formulation_Manager.hpp b/include/realizations/catchment/Formulation_Manager.hpp index 1ad2358b48..f587e1fe36 100644 --- a/include/realizations/catchment/Formulation_Manager.hpp +++ b/include/realizations/catchment/Formulation_Manager.hpp @@ -51,14 +51,14 @@ namespace realization { ~Formulation_Manager() = default; - void read(geojson::GeoJSON fabric, utils::StreamHandler output_stream, int mpi_rank) { + void read(geojson::GeoJSON fabric, utils::StreamHandler output_stream) { //TODO seperate the parsing of configuration options like time //and routing and other non feature specific tasks from this main function //which has to iterate the entire hydrofabric. auto possible_global_config = tree.get_child_optional("global"); if (possible_global_config) { - global_config = realization::config::Config(*possible_global_config, mpi_rank); + global_config = realization::config::Config(*possible_global_config); } auto possible_simulation_time = tree.get_child_optional("time"); @@ -91,7 +91,7 @@ namespace realization { for (std::pair layer_config : *layers_json_array) { - layer = config::Layer(layer_config.second, mpi_rank); + layer = config::Layer(layer_config.second); layer_desc = layer.get_descriptor(); // add the layer to storage @@ -152,7 +152,7 @@ namespace realization { #endif continue; } - realization::config::Config catchment_formulation(catchment_config.second, mpi_rank); + realization::config::Config catchment_formulation(catchment_config.second); if(!catchment_formulation.has_formulation()){ throw std::runtime_error("ERROR: No formulations defined for "+catchment_config.first+"."); diff --git a/include/realizations/config/config.hpp b/include/realizations/config/config.hpp index 6f4fe9e178..fb11dffa38 100644 --- a/include/realizations/config/config.hpp +++ b/include/realizations/config/config.hpp @@ -26,7 +26,7 @@ namespace realization{ * * @param tree */ - Config(const boost::property_tree::ptree& tree, int mpi_rank){ + Config(const boost::property_tree::ptree& tree){ auto possible_forcing = tree.get_child_optional("forcing"); @@ -36,7 +36,7 @@ namespace realization{ //get first empty key under formulations (corresponds to first json array element) auto possible_formulation_tree = tree.get_child_optional("formulations.."); if(possible_formulation_tree){ - formulation = Formulation(*possible_formulation_tree, mpi_rank); + formulation = Formulation(*possible_formulation_tree); } } diff --git a/include/realizations/config/formulation.hpp b/include/realizations/config/formulation.hpp index 24e6665c94..51b976be35 100644 --- a/include/realizations/config/formulation.hpp +++ b/include/realizations/config/formulation.hpp @@ -7,6 +7,10 @@ #include "JSONProperty.hpp" +#if NGEN_WITH_MPI +#include +#endif + namespace realization{ namespace config{ @@ -40,7 +44,7 @@ namespace realization{ * * @param tree property tree to build Formulation from */ - Formulation(const boost::property_tree::ptree& tree, int mpi_rank){ + Formulation(const boost::property_tree::ptree& tree){ type = tree.get("name"); for (std::pair setting : tree.get_child("params")) { //Construct the geoJSON PropertyMap from each key, value pair in "params" @@ -52,16 +56,18 @@ namespace realization{ if(type=="bmi_multi"){ for(auto& module : tree.get_child("params.modules")){ //Create the nested formulations in order of definition - nested.push_back(Formulation(module.second, mpi_rank)); + nested.push_back(Formulation(module.second)); } + // If running MPI job, output with only one processor #if NGEN_WITH_MPI - if (mpi_rank == 0) { - geojson::JSONProperty::print_property(parameters.at("modules")); - } - #else - geojson::JSONProperty::print_property(parameters.at("modules")); + int mpi_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); + if (mpi_rank == 0) #endif + { + geojson::JSONProperty::print_property(parameters.at("modules")); } + } } /** diff --git a/include/realizations/config/layer.hpp b/include/realizations/config/layer.hpp index e51c2d839c..5a0546b537 100644 --- a/include/realizations/config/layer.hpp +++ b/include/realizations/config/layer.hpp @@ -27,7 +27,7 @@ namespace realization{ * * @param tree */ - Layer(const boost::property_tree::ptree& tree, int mpi_rank):formulation(tree, mpi_rank){ + Layer(const boost::property_tree::ptree& tree):formulation(tree){ std::vector missing_keys; auto name = tree.get_optional("name"); if(!name) missing_keys.push_back("name"); diff --git a/src/NGen.cpp b/src/NGen.cpp index 2f05e7b69e..1c0cf2bf28 100644 --- a/src/NGen.cpp +++ b/src/NGen.cpp @@ -394,7 +394,7 @@ int main(int argc, char *argv[]) { nexus_collection->update_ids("id"); std::cout<<"Initializing formulations" << std::endl; std::shared_ptr manager = std::make_shared(REALIZATION_CONFIG_PATH); - manager->read(catchment_collection, utils::getStdOut(), mpi_rank); + manager->read(catchment_collection, utils::getStdOut()); //TODO refactor manager->read so certain configs can be queried before the entire //realization collection is created diff --git a/test/core/multilayer/MultiLayerParserTest.cpp b/test/core/multilayer/MultiLayerParserTest.cpp index 6c526c1ed1..77c3b679d8 100644 --- a/test/core/multilayer/MultiLayerParserTest.cpp +++ b/test/core/multilayer/MultiLayerParserTest.cpp @@ -70,9 +70,8 @@ TEST_F(MultiLayerParserTest, TestInit0) TEST_F(MultiLayerParserTest, TestRead0) { - int mpi_rank = 0; manager = std::make_shared(realization_config_path.c_str()); - manager->read(catchment_collection, utils::getStdOut(), mpi_rank); + manager->read(catchment_collection, utils::getStdOut()); ASSERT_TRUE(true); -} +} \ No newline at end of file diff --git a/test/realizations/Formulation_Manager_Test.cpp b/test/realizations/Formulation_Manager_Test.cpp index 6325546366..ddfd3c1cdf 100644 --- a/test/realizations/Formulation_Manager_Test.cpp +++ b/test/realizations/Formulation_Manager_Test.cpp @@ -713,8 +713,7 @@ TEST_F(Formulation_Manager_Test, basic_reading_1) { this->add_feature("cat-52"); this->add_feature("cat-67"); - int mpi_rank = 0; - manager.read(this->fabric, catchment_output, mpi_rank); + manager.read(this->fabric, catchment_output); ASSERT_EQ(manager.get_size(), 2); @@ -737,8 +736,7 @@ TEST_F(Formulation_Manager_Test, basic_reading_2) { this->add_feature("cat-52"); this->add_feature("cat-67"); - int mpi_rank = 0; - manager.read(this->fabric, catchment_output, mpi_rank); + manager.read(this->fabric, catchment_output); ASSERT_EQ(manager.get_size(), 2); @@ -759,8 +757,7 @@ TEST_F(Formulation_Manager_Test, basic_run_1) { this->add_feature("cat-52"); this->add_feature("cat-67"); - int mpi_rank = 0; - manager.read(this->fabric, catchment_output, mpi_rank); + manager.read(this->fabric, catchment_output); ASSERT_EQ(manager.get_size(), 2); @@ -794,8 +791,7 @@ TEST_F(Formulation_Manager_Test, basic_run_3) { realization::Formulation_Manager manager = realization::Formulation_Manager(stream); this->add_feature("cat-67"); - int mpi_rank = 0; - manager.read(this->fabric, catchment_output, mpi_rank); + manager.read(this->fabric, catchment_output); ASSERT_EQ(manager.get_size(), 1); ASSERT_TRUE(manager.contains("cat-67")); @@ -832,8 +828,7 @@ TEST_F(Formulation_Manager_Test, read_extra) { ASSERT_TRUE(manager.is_empty()); this->add_feature("cat-67"); - int mpi_rank = 0; - manager.read(this->fabric, catchment_output, mpi_rank); + manager.read(this->fabric, catchment_output); ASSERT_EQ(manager.get_size(), 1); ASSERT_TRUE(manager.contains("cat-67")); @@ -851,8 +846,7 @@ TEST_F(Formulation_Manager_Test, forcing_provider_specification) { this->add_feature("cat-67"); this->add_feature("cat-27115"); - int mpi_rank = 0; - manager.read(this->fabric, catchment_output, mpi_rank); + manager.read(this->fabric, catchment_output); ASSERT_EQ(manager.get_size(), 2); ASSERT_TRUE(manager.contains("cat-67")); @@ -948,8 +942,7 @@ TEST_F(Formulation_Manager_Test, read_external_attributes) { { "e", geojson::JSONProperty{"e", 2.71828 } } }); - int mpi_rank = 0; - manager.read(this->fabric, catchment_output, mpi_rank); + manager.read(this->fabric, catchment_output); ASSERT_EQ(manager.get_size(), 3); check_formulation_values(manager, "cat-67", { 1.70352, 10.0 }); @@ -967,7 +960,7 @@ TEST_F(Formulation_Manager_Test, read_external_attributes) { { "val", geojson::JSONProperty{"val", 7.41722 } } }); - manager.read(this->fabric, catchment_output, mpi_rank); + manager.read(this->fabric, catchment_output); check_formulation_values(manager, "cat-67", { 7.41722, 9231 }); }