Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
prng_utilities.h
1// STL Includes
2#include <chrono>
3#include <random>
4#include <string>
5
6// Local includes
7#include "../global/global.h"
8
9#pragma once
10
12{
13 public:
14 static std::mt19937_64 generator;
15
17 {
18 // If the seed isn't defined in the settings file or argv then generate
19 // a random seed
20 if (P->prng_seed == 0) {
21 // Since std::random_device isn't guaranteed to be random or
22 // different for each rank we're going to convert both the base seed
23 // and MPI rank to strings, concatenated them, then hash the result.
24 // This should give a fairly random seed even if std::random_device
25 // isn't random
26 std::string hashString = std::to_string(std::random_device{}())
27#ifdef MPI_CHOLLA
28 + std::to_string(static_cast<std::uint_fast64_t>(procID))
29#endif
30 + std::to_string(std::chrono::high_resolution_clock::now().time_since_epoch().count());
31 std::size_t hashedSeed = std::hash<std::string>{}(hashString);
32 P->prng_seed = static_cast<std::uint_fast64_t>(hashedSeed);
33 }
34
35 // Initialize the PRNG
36 generator.seed(P->prng_seed);
37 };
38 ~ChollaPrngGenerator() = default;
39};
Definition prng_utilities.h:12
Definition global.h:217