Less and more informative stdout messages

This commit is contained in:
Marco De Lucia 2024-12-12 16:20:09 +01:00 committed by Max Lübke
parent 61d3a8a227
commit a519edd102
3 changed files with 20 additions and 16 deletions

View File

@ -94,7 +94,7 @@ master_iteration_end <- function(setup, state_T, state_C) {
## Add last time step to simulation time ## Add last time step to simulation time
setup$simulation_time <- setup$simulation_time + setup$timesteps[iter] setup$simulation_time <- setup$simulation_time + setup$timesteps[iter]
msgm("done iteration", iter, "/", length(setup$timesteps)) ## msgm("done iteration", iter, "/", length(setup$timesteps))
setup$iter <- setup$iter + 1 setup$iter <- setup$iter + 1
return(setup) return(setup)
} }
@ -132,7 +132,7 @@ ReadRObj <- function(path) {
## Handler to store R objs to binary files using either builtin ## Handler to store R objs to binary files using either builtin
## saveRDS() or qs::qsave() based on file extension ## saveRDS() or qs::qsave() based on file extension
SaveRObj <- function(x, path) { SaveRObj <- function(x, path) {
msgm("Storing to", path) ## msgm("Storing to", path)
## code borrowed from tools::file_ext() ## code borrowed from tools::file_ext()
pos <- regexpr("\\.([[:alnum:]]+)$", path) pos <- regexpr("\\.([[:alnum:]]+)$", path)
extension <- ifelse(pos > -1L, substring(path, pos + 1L), "") extension <- ifelse(pos > -1L, substring(path, pos + 1L), "")

View File

@ -70,7 +70,7 @@ VecToMatrix(const std::vector<TugType> &vec, std::uint32_t n_rows,
// static constexpr double ZERO_MULTIPLICATOR = 10E-14; // static constexpr double ZERO_MULTIPLICATOR = 10E-14;
void DiffusionModule::simulate(double requested_dt) { void DiffusionModule::simulate(double requested_dt) {
MSG("Starting diffusion ..."); // MSG("Starting diffusion ...");
const auto start_diffusion_t = std::chrono::high_resolution_clock::now(); const auto start_diffusion_t = std::chrono::high_resolution_clock::now();
const auto &n_rows = this->param_list.n_rows; const auto &n_rows = this->param_list.n_rows;

View File

@ -39,13 +39,14 @@
#include <memory> #include <memory>
#include <mpi.h> #include <mpi.h>
#include <string> #include <string>
#include <format>
#include <CLI/CLI.hpp> #include <CLI/CLI.hpp>
#include <poet.hpp> #include <poet.hpp>
#include <vector> #include <vector>
using namespace std; // using namespace std;
using namespace poet; using namespace poet;
using namespace Rcpp; using namespace Rcpp;
@ -292,18 +293,19 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, const RuntimeParameters &params,
const double &dt = params.timesteps[iter - 1]; const double &dt = params.timesteps[iter - 1];
// cout << "CPP: Next time step is " << dt << "[s]" << endl; std::cout << std::endl;
MSG("Next time step is " + std::to_string(dt) + " [s]");
/* displaying iteration number, with C++ and R iterator */ /* displaying iteration number, with C++ and R iterator */
MSG("Going through iteration " + std::to_string(iter)); MSG("Going through iteration " + std::to_string(iter) + "/" +
std::to_string(maxiter));
MSG("Current time step is " + std::format("{:.2f}", dt));
/* run transport */ /* run transport */
diffusion.simulate(dt); diffusion.simulate(dt);
chem.getField().update(diffusion.getField()); chem.getField().update(diffusion.getField());
MSG("Chemistry step"); // MSG("Chemistry start");
if (params.use_ai_surrogate) { if (params.use_ai_surrogate) {
double ai_start_t = MPI_Wtime(); double ai_start_t = MPI_Wtime();
// Save current values from the tug field as predictor for the ai step // Save current values from the tug field as predictor for the ai step
@ -319,16 +321,16 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, const RuntimeParameters &params,
R.parseEval("predictors_scaled <- preprocess(predictors)"); R.parseEval("predictors_scaled <- preprocess(predictors)");
// Predict // Predict
MSG("AI Predict"); MSG("AI Prediction");
R.parseEval( R.parseEval(
"aipreds_scaled <- prediction_step(model, predictors_scaled)"); "aipreds_scaled <- prediction_step(model, predictors_scaled)");
// Apply postprocessing // Apply postprocessing
MSG("AI Postprocesing"); MSG("AI Postprocessing");
R.parseEval("aipreds <- postprocess(aipreds_scaled)"); R.parseEval("aipreds <- postprocess(aipreds_scaled)");
// Validate prediction and write valid predictions to chem field // Validate prediction and write valid predictions to chem field
MSG("AI Validate"); MSG("AI Validation");
R.parseEval( R.parseEval(
"validity_vector <- validate_predictions(predictors, aipreds)"); "validity_vector <- validate_predictions(predictors, aipreds)");
@ -338,8 +340,8 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, const RuntimeParameters &params,
MSG("AI TempField"); MSG("AI TempField");
std::vector<std::vector<double>> RTempField = std::vector<std::vector<double>> RTempField =
R.parseEval("set_valid_predictions(predictors,\ R.parseEval("set_valid_predictions(predictors,\
aipreds,\ aipreds,\
validity_vector)"); validity_vector)");
MSG("AI Set Field"); MSG("AI Set Field");
Field predictions_field = Field predictions_field =
@ -390,9 +392,11 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, const RuntimeParameters &params,
MSG("End of *coupling* iteration " + std::to_string(iter) + "/" + MSG("End of *coupling* iteration " + std::to_string(iter) + "/" +
std::to_string(maxiter)); std::to_string(maxiter));
MSG(); // MSG();
} // END SIMULATION LOOP } // END SIMULATION LOOP
std::cout << std::endl;
Rcpp::List chem_profiling; Rcpp::List chem_profiling;
chem_profiling["simtime"] = chem.GetChemistryTime(); chem_profiling["simtime"] = chem.GetChemistryTime();
chem_profiling["loop"] = chem.GetMasterLoopTime(); chem_profiling["loop"] = chem.GetMasterLoopTime();
@ -588,7 +592,7 @@ int main(int argc, char *argv[]) {
R["setup"] = *global_rt_setup; R["setup"] = *global_rt_setup;
R["setup$out_ext"] = run_params.out_ext; R["setup$out_ext"] = run_params.out_ext;
string r_vis_code; std::string r_vis_code;
r_vis_code = "SaveRObj(x = profiling, path = paste0(out_dir, " r_vis_code = "SaveRObj(x = profiling, path = paste0(out_dir, "
"'/timings.', setup$out_ext));"; "'/timings.', setup$out_ext));";
R.parseEval(r_vis_code); R.parseEval(r_vis_code);