From dbe31cf2bf46d77fba2903c6e99dcd0d88f8b34a Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 4 Feb 2021 13:40:34 +0000 Subject: [PATCH] Use system UUID generator for run ID if available --- include/bout/solver.hxx | 4 ++-- src/solver/solver.cxx | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/bout/solver.hxx b/include/bout/solver.hxx index 6baad9481d..634ab6ac99 100644 --- a/include/bout/solver.hxx +++ b/include/bout/solver.hxx @@ -447,8 +447,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); diff --git a/src/solver/solver.cxx b/src/solver/solver.cxx index 44c961a0f0..4dad9e8f0b 100644 --- a/src/solver/solver.cxx +++ b/src/solver/solver.cxx @@ -548,20 +548,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 {}; - 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 {}; + 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