From 55dffe93086574dc8d4f643dc328b904b302608d Mon Sep 17 00:00:00 2001 From: Max Luebke Date: Wed, 12 Jul 2023 12:56:36 +0200 Subject: [PATCH] feat: toggle progressbar by commandline option --- app/poet.cpp | 4 ++++ include/poet/ChemistryModule.hpp | 12 +++++++++++- include/poet/SimParams.hpp | 6 +++++- src/ChemistryModule/MasterFunctions.cpp | 17 ++++++++++++++--- src/ChemistryModule/WorkerFunctions.cpp | 8 +++++++- src/SimParams.cpp | 2 ++ 6 files changed, 43 insertions(+), 6 deletions(-) diff --git a/app/poet.cpp b/app/poet.cpp index 4fb2ef86e..991ac335a 100644 --- a/app/poet.cpp +++ b/app/poet.cpp @@ -131,6 +131,10 @@ inline double RunMasterLoop(SimParams ¶ms, RInside &R, poet::ChemistryModule::SingleCMap init_df = DFToHashMap(d_params.initial_t); chem.initializeField(diffusion.getField()); + if (params.getNumParams().print_progressbar) { + chem.setProgressBarPrintout(true); + } + if (params.getNumParams().dht_enabled) { chem.SetDHTEnabled(true, params.getNumParams().dht_size_per_process, chem_params.dht_species); diff --git a/include/poet/ChemistryModule.hpp b/include/poet/ChemistryModule.hpp index af63f87eb..917300a43 100644 --- a/include/poet/ChemistryModule.hpp +++ b/include/poet/ChemistryModule.hpp @@ -1,4 +1,4 @@ -// Time-stamp: "Last modified 2023-04-24 14:30:06 mluebke" +// Time-stamp: "Last modified 2023-07-12 12:50:53 mluebke" #ifndef CHEMISTRYMODULE_H_ #define CHEMISTRYMODULE_H_ @@ -274,6 +274,13 @@ public: * \return Reference to the chemical field. */ Field &getField() { return this->chem_field; } + + /** + * **Master only** Enable/disable progress bar. + * + * \param enabled True if print progressbar, false if not. + */ + void setProgressBarPrintout(bool enabled); #endif protected: #ifdef POET_USE_PRM @@ -290,6 +297,7 @@ protected: CHEM_DHT_READ_FILE, CHEM_WORK_LOOP, CHEM_PERF, + CHEM_PROGRESSBAR, CHEM_BREAK_MAIN_LOOP }; @@ -391,6 +399,8 @@ protected: std::array base_totals{0}; + bool print_progessbar{false}; + #endif double chem_t = 0.; diff --git a/include/poet/SimParams.hpp b/include/poet/SimParams.hpp index 0d67977c9..3e7483e31 100644 --- a/include/poet/SimParams.hpp +++ b/include/poet/SimParams.hpp @@ -67,6 +67,9 @@ typedef struct { unsigned int wp_size; /** indicates if resulting grid should be stored after every iteration */ bool store_result; + /** indicating whether the progress bar during chemistry simulation should be + * printed or not */ + bool print_progressbar; } t_simparams; using GridParams = struct s_GridParams { @@ -233,7 +236,8 @@ public: private: std::list validateOptions(argh::parser cmdl); - const std::set flaglist{"ignore-result", "dht", "dht-nolog"}; + const std::set flaglist{"ignore-result", "dht", "dht-nolog", "P", + "progress"}; const std::set paramlist{"work-package-size", "dht-signif", "dht-strategy", "dht-size", "dht-snaps", "dht-file"}; diff --git a/src/ChemistryModule/MasterFunctions.cpp b/src/ChemistryModule/MasterFunctions.cpp index c97c50824..316b64cab 100644 --- a/src/ChemistryModule/MasterFunctions.cpp +++ b/src/ChemistryModule/MasterFunctions.cpp @@ -240,7 +240,7 @@ void poet::ChemistryModule::MasterRunParallel() { // grid.shuffleAndExport(mpi_buffer); std::vector mpi_buffer = shuffleField(chem_field.AsVector(), this->n_cells, this->prop_count, - wp_sizes_vector.size()); + wp_sizes_vector.size()); /* setup local variables */ pkg_to_send = wp_sizes_vector.size(); @@ -263,7 +263,9 @@ void poet::ChemistryModule::MasterRunParallel() { // while there are still packages to recv while (pkg_to_recv > 0) { // print a progressbar to stdout - printProgressbar((int)i_pkgs, (int)wp_sizes_vector.size()); + if (print_progessbar) { + printProgressbar((int)i_pkgs, (int)wp_sizes_vector.size()); + } // while there are still packages to send if (pkg_to_send > 0) { // send packages to all free workers ... @@ -288,7 +290,7 @@ void poet::ChemistryModule::MasterRunParallel() { // grid.importAndUnshuffle(mpi_buffer); std::vector out_vec{mpi_buffer}; unshuffleField(mpi_buffer, this->n_cells, this->prop_count, - wp_sizes_vector.size(), out_vec); + wp_sizes_vector.size(), out_vec); chem_field.SetFromVector(out_vec); /* do master stuff */ @@ -332,3 +334,12 @@ poet::ChemistryModule::CalculateWPSizesVector(uint32_t n_cells, return wp_sizes_vector; } + +void poet::ChemistryModule::setProgressBarPrintout(bool enabled) { + if (is_master) { + int type = CHEM_PROGRESSBAR; + ChemBCast(&type, 1, MPI_INT); + ChemBCast(&enabled, 1, MPI_CXX_BOOL); + } + this->print_progessbar = enabled; +} diff --git a/src/ChemistryModule/WorkerFunctions.cpp b/src/ChemistryModule/WorkerFunctions.cpp index a9ed3d3bf..4f5a59fa0 100644 --- a/src/ChemistryModule/WorkerFunctions.cpp +++ b/src/ChemistryModule/WorkerFunctions.cpp @@ -1,4 +1,4 @@ -// Time-stamp: "Last modified 2023-04-24 16:55:34 mluebke" +// Time-stamp: "Last modified 2023-07-12 12:56:17 mluebke" #include "IrmResult.h" #include "poet/ChemistryModule.hpp" @@ -103,6 +103,12 @@ void poet::ChemistryModule::WorkerLoop() { WorkerMetricsToMaster(type); break; } + case CHEM_PROGRESSBAR: { + bool enable; + ChemBCast(&enable, 1, MPI_CXX_BOOL); + setProgressBarPrintout(enable); + break; + } case CHEM_BREAK_MAIN_LOOP: { WorkerPostSim(iteration); loop = false; diff --git a/src/SimParams.cpp b/src/SimParams.cpp index 8e25868d1..8d484a54b 100644 --- a/src/SimParams.cpp +++ b/src/SimParams.cpp @@ -141,6 +141,8 @@ int SimParams::parseFromCmdl(char *argv[], RInside &R) { return poet::PARSER_ERROR; } + simparams.print_progressbar = cmdl[{"P", "progress"}]; + /*Parse DHT arguments*/ simparams.dht_enabled = cmdl["dht"]; // cout << "CPP: DHT is " << ( dht_enabled ? "ON" : "OFF" ) << '\n';