Skip to content

Commit

Permalink
Use system UUID generator for run ID if available
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree authored and johnomotani committed Feb 9, 2021
1 parent 0d6b0c1 commit 9d07413
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions include/bout/solver.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ protected:
std::string run_id = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
/// The run from which this was restarted.
std::string run_restart_from = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
/// Generate a random UUID and broadcast it to all processors
std::string createRunId();
/// Generate a random UUID (version 4) and broadcast it to all processors
std::string createRunId() const;

/// Run the user's RHS function
int run_rhs(BoutReal t);
Expand Down
24 changes: 15 additions & 9 deletions src/solver/solver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -529,20 +529,26 @@ int Solver::solve(int NOUT, BoutReal TIMESTEP) {
return status;
}

std::string Solver::createRunId() {
std::string Solver::createRunId() const {

std::string result;
result.resize(36);

if (MYPE == 0) {
std::random_device rd;
auto seed_data = std::array<int, std::mt19937::state_size> {};
std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
std::mt19937 generator(seq);
uuids::uuid_random_generator gen{generator};

result = uuids::to_string(gen()); // Different each time the simulation is run
// Generate a unique ID for this run
if (bout::build::has_uuid_system_generator) {
uuids::uuid_system_generator gen{};
result = uuids::to_string(gen());
} else {
std::random_device rd;
auto seed_data = std::array<int, std::mt19937::state_size> {};
std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
std::mt19937 generator(seq);
uuids::uuid_random_generator gen{generator};

result = uuids::to_string(gen());
}
}

// All ranks have same run_id
Expand Down

0 comments on commit 9d07413

Please sign in to comment.