From 9d07413813b7610dc38a8b372e01ef7490c1b0a4 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 3413fb2a82..d8d3318151 100644 --- a/include/bout/solver.hxx +++ b/include/bout/solver.hxx @@ -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); diff --git a/src/solver/solver.cxx b/src/solver/solver.cxx index 3e55d84d3a..1c51016db7 100644 --- a/src/solver/solver.cxx +++ b/src/solver/solver.cxx @@ -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 {}; - 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