Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate outputs of realization config in MPI computation #866

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/realizations/catchment/Formulation_Manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ namespace realization {

~Formulation_Manager() = default;

void read(geojson::GeoJSON fabric, utils::StreamHandler output_stream) {
void read(geojson::GeoJSON fabric, utils::StreamHandler output_stream, int mpi_rank) {
//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);
global_config = realization::config::Config(*possible_global_config, mpi_rank);
}

auto possible_simulation_time = tree.get_child_optional("time");
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace realization {

for (std::pair<std::string, boost::property_tree::ptree> layer_config : *layers_json_array)
{
layer = config::Layer(layer_config.second);
layer = config::Layer(layer_config.second, mpi_rank);
layer_desc = layer.get_descriptor();

// add the layer to storage
Expand Down Expand Up @@ -152,7 +152,7 @@ namespace realization {
#endif
continue;
}
realization::config::Config catchment_formulation(catchment_config.second);
realization::config::Config catchment_formulation(catchment_config.second, mpi_rank);

if(!catchment_formulation.has_formulation()){
throw std::runtime_error("ERROR: No formulations defined for "+catchment_config.first+".");
Expand Down
4 changes: 2 additions & 2 deletions include/realizations/config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace realization{
*
* @param tree
*/
Config(const boost::property_tree::ptree& tree){
Config(const boost::property_tree::ptree& tree, int mpi_rank){

auto possible_forcing = tree.get_child_optional("forcing");

Expand All @@ -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);
formulation = Formulation(*possible_formulation_tree, mpi_rank);
}
}

Expand Down
12 changes: 9 additions & 3 deletions include/realizations/config/formulation.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef NGEN_REALIZATION_CONFIG_FORMULATION_H
#define NGEN_REALIZATION_CONFIG_FORMULATION_H

#include <NGenConfig.h>
#include <boost/property_tree/ptree.hpp>
#include <string>

Expand Down Expand Up @@ -39,7 +40,7 @@ namespace realization{
*
* @param tree property tree to build Formulation from
*/
Formulation(const boost::property_tree::ptree& tree){
Formulation(const boost::property_tree::ptree& tree, int mpi_rank){
type = tree.get<std::string>("name");
for (std::pair<std::string, boost::property_tree::ptree> setting : tree.get_child("params")) {
//Construct the geoJSON PropertyMap from each key, value pair in "params"
Expand All @@ -51,11 +52,16 @@ 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));
nested.push_back(Formulation(module.second, mpi_rank));
}
#if NGEN_WITH_MPI
PhilMiller marked this conversation as resolved.
Show resolved Hide resolved
if (mpi_rank == 0) {
geojson::JSONProperty::print_property(parameters.at("modules"));
}

#else
geojson::JSONProperty::print_property(parameters.at("modules"));
#endif
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion include/realizations/config/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace realization{
*
* @param tree
*/
Layer(const boost::property_tree::ptree& tree):formulation(tree){
Layer(const boost::property_tree::ptree& tree, int mpi_rank):formulation(tree, mpi_rank){
std::vector<std::string> missing_keys;
auto name = tree.get_optional<std::string>("name");
if(!name) missing_keys.push_back("name");
Expand Down
2 changes: 1 addition & 1 deletion src/NGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ int main(int argc, char *argv[]) {
nexus_collection->update_ids("id");
std::cout<<"Initializing formulations" << std::endl;
std::shared_ptr<realization::Formulation_Manager> manager = std::make_shared<realization::Formulation_Manager>(REALIZATION_CONFIG_PATH);
manager->read(catchment_collection, utils::getStdOut());
manager->read(catchment_collection, utils::getStdOut(), mpi_rank);

//TODO refactor manager->read so certain configs can be queried before the entire
//realization collection is created
Expand Down
5 changes: 3 additions & 2 deletions test/core/multilayer/MultiLayerParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ TEST_F(MultiLayerParserTest, TestInit0)

TEST_F(MultiLayerParserTest, TestRead0)
{
int mpi_rank = 0;
manager = std::make_shared<realization::Formulation_Manager>(realization_config_path.c_str());
manager->read(catchment_collection, utils::getStdOut());
manager->read(catchment_collection, utils::getStdOut(), mpi_rank);

ASSERT_TRUE(true);
}
}
23 changes: 15 additions & 8 deletions test/realizations/Formulation_Manager_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,8 @@ TEST_F(Formulation_Manager_Test, basic_reading_1) {

this->add_feature("cat-52");
this->add_feature("cat-67");
manager.read(this->fabric, catchment_output);
int mpi_rank = 0;
manager.read(this->fabric, catchment_output, mpi_rank);

ASSERT_EQ(manager.get_size(), 2);

Expand All @@ -736,7 +737,8 @@ TEST_F(Formulation_Manager_Test, basic_reading_2) {

this->add_feature("cat-52");
this->add_feature("cat-67");
manager.read(this->fabric, catchment_output);
int mpi_rank = 0;
manager.read(this->fabric, catchment_output, mpi_rank);

ASSERT_EQ(manager.get_size(), 2);

Expand All @@ -757,7 +759,8 @@ TEST_F(Formulation_Manager_Test, basic_run_1) {

this->add_feature("cat-52");
this->add_feature("cat-67");
manager.read(this->fabric, catchment_output);
int mpi_rank = 0;
manager.read(this->fabric, catchment_output, mpi_rank);

ASSERT_EQ(manager.get_size(), 2);

Expand Down Expand Up @@ -791,7 +794,8 @@ TEST_F(Formulation_Manager_Test, basic_run_3) {
realization::Formulation_Manager manager = realization::Formulation_Manager(stream);

this->add_feature("cat-67");
manager.read(this->fabric, catchment_output);
int mpi_rank = 0;
manager.read(this->fabric, catchment_output, mpi_rank);

ASSERT_EQ(manager.get_size(), 1);
ASSERT_TRUE(manager.contains("cat-67"));
Expand Down Expand Up @@ -828,7 +832,8 @@ TEST_F(Formulation_Manager_Test, read_extra) {
ASSERT_TRUE(manager.is_empty());

this->add_feature("cat-67");
manager.read(this->fabric, catchment_output);
int mpi_rank = 0;
manager.read(this->fabric, catchment_output, mpi_rank);

ASSERT_EQ(manager.get_size(), 1);
ASSERT_TRUE(manager.contains("cat-67"));
Expand All @@ -846,7 +851,8 @@ TEST_F(Formulation_Manager_Test, forcing_provider_specification) {

this->add_feature("cat-67");
this->add_feature("cat-27115");
manager.read(this->fabric, catchment_output);
int mpi_rank = 0;
manager.read(this->fabric, catchment_output, mpi_rank);

ASSERT_EQ(manager.get_size(), 2);
ASSERT_TRUE(manager.contains("cat-67"));
Expand Down Expand Up @@ -942,7 +948,8 @@ TEST_F(Formulation_Manager_Test, read_external_attributes) {
{ "e", geojson::JSONProperty{"e", 2.71828 } }
});

manager.read(this->fabric, catchment_output);
int mpi_rank = 0;
manager.read(this->fabric, catchment_output, mpi_rank);

ASSERT_EQ(manager.get_size(), 3);
check_formulation_values(manager, "cat-67", { 1.70352, 10.0 });
Expand All @@ -960,7 +967,7 @@ TEST_F(Formulation_Manager_Test, read_external_attributes) {
{ "val", geojson::JSONProperty{"val", 7.41722 } }
});

manager.read(this->fabric, catchment_output);
manager.read(this->fabric, catchment_output, mpi_rank);

check_formulation_values(manager, "cat-67", { 7.41722, 9231 });
}
Loading