Skip to content

Commit

Permalink
Save diagnostics about auto-determine dynamics
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewcarbone committed May 27, 2024
1 parent 3783e85 commit 94f0b4a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
3 changes: 1 addition & 2 deletions inc/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* the code, as well as general utils.
*/

#include <fstream> // std::ofstream

#include "ArbitraryPrecision/ap/ap.hpp"
#include "Json/json.hpp"
using json = nlohmann::json;
Expand Down Expand Up @@ -44,6 +42,7 @@ using json = nlohmann::json;
#define CONFIG_PATH "config.json"
#define RESULTS_PATH "results.json"
#define DIAGNOSTICS_PATH "diagnostics.json"
#define AUTO_DYNAMICS_DIAGNOSTIC_PATH "auto_dynamics_diagnostics.json"

namespace utils
{
Expand Down
21 changes: 8 additions & 13 deletions src/main_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,10 @@ void auto_determine_dynamics_(utils::SimulationParameters* params)
if (mpi_rank % 2 == 0)
{
times[mpi_rank] = get_sim_time(p, "standard");
// MPI_Recv(&gillespie_time, 1, MPI_DOUBLE, 1, 0, mpi_comm, MPI_STATUS_IGNORE);
}
else if (mpi_rank % 2 != 0)
{
times[mpi_rank] = get_sim_time(p, "gillespie");
// MPI_Send(&gillespie_time, 1, MPI_DOUBLE, 0, 0, mpi_comm);
}
MPI_Barrier(MPI_COMM_WORLD);

Expand Down Expand Up @@ -459,6 +457,14 @@ void auto_determine_dynamics_(utils::SimulationParameters* params)
result_int = 0;
}
fflush(stdout);

// Save this auto run information
json j;
j["gillespie_mean"] = gillespie_time;
j["gillespie_std"] = gillespie_std;
j["standard_mean"] = standard_time;
j["standard_std"] = standard_std;
utils::json_to_file(j, AUTO_DYNAMICS_DIAGNOSTIC_PATH);
}

MPI_Bcast(&result_int, 1, MPI_INT, 0, MPI_COMM_WORLD);
Expand Down Expand Up @@ -510,18 +516,8 @@ std::vector<std::string> get_completed_json_filenames()
std::sort(all_current_results.begin(), all_current_results.end());

return all_current_results;

// if (all_current_results.size() == 0){return 0;}

//

// // Get the last entry here, which will correspond to the start index,
// // since we don't want to risk that a json file was partially written
// const size_t N = all_current_results.size();
// return get_index(all_current_results[N - 1]) + 1;
}


void execute_process_pool(const utils::SimulationParameters params)
{
int mpi_rank, mpi_world_size;
Expand All @@ -531,7 +527,6 @@ void execute_process_pool(const utils::SimulationParameters params)
// Execute the process pool
if (mpi_rank == MASTER)
{
// TODO add some logic for checkpoint-restart here
const std::vector<std::string> completed_json_filenames = get_completed_json_filenames();
size_t start_index = 0;
const size_t total_jobs_completed = completed_json_filenames.size();
Expand Down
11 changes: 11 additions & 0 deletions src/processing_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,17 @@ void postprocess()

utils::json_to_file(j, RESULTS_PATH);
printf("Results saved to %s\n", RESULTS_PATH);


// Quickly cleanup the auto-determine dynamics stuff
if (std::filesystem::exists(AUTO_DYNAMICS_DIAGNOSTIC_PATH))
{
json j = utils::read_json(DIAGNOSTICS_PATH);
json j2 = utils::read_json(AUTO_DYNAMICS_DIAGNOSTIC_PATH);
j["auto_determine_dynamics"] = j2;
std::remove(AUTO_DYNAMICS_DIAGNOSTIC_PATH);
utils::json_to_file(j, DIAGNOSTICS_PATH);
}
utils::cleanup_directories();
printf("Simulation completed successfully\n");
}
Expand Down
1 change: 1 addition & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <sstream> // oss
#include <algorithm>
#include <fstream> // std::ofstream

#include "utils.h"
#include "ArbitraryPrecision/ap/ap.hpp"
Expand Down

0 comments on commit 94f0b4a

Please sign in to comment.