| 162 | } |
| 163 | |
| 164 | void init_random(int seed, int num_io_RNGs, lbann_comm* comm) |
| 165 | { |
| 166 | generator_inited = true; |
| 167 | fast_generator_inited = true; |
| 168 | |
| 169 | // Use different seed on each rank in trainer |
| 170 | if (seed == -1) { |
| 171 | std::random_device rd; |
| 172 | seed = rd(); |
| 173 | } |
| 174 | else if (comm != nullptr) { |
| 175 | seed = hash_combine(seed, comm->get_rank_in_trainer()); |
| 176 | } |
| 177 | else if (El::mpi::Initialized()) { |
| 178 | seed = hash_combine(seed, El::mpi::Rank(El::mpi::COMM_WORLD)); |
| 179 | } |
| 180 | |
| 181 | // Seed every OpenMP thread, if present. |
| 182 | // Note: Threadprivate OMP variables don't work with dynamic threads. |
| 183 | #ifdef _OPENMP |
| 184 | #pragma omp parallel |
| 185 | { |
| 186 | const int thread = omp_get_thread_num(); |
| 187 | const int thread_seed = hash_combine(seed, thread); |
| 188 | get_generator().seed(thread_seed); |
| 189 | get_fast_generator().seed( |
| 190 | hash_combine(thread_seed, 132241)); // 12345th prime |
| 191 | } |
| 192 | #else |
| 193 | get_generator().seed(seed); |
| 194 | get_fast_generator().seed(hash_combine(seed, 41263)); // 4321th prime |
| 195 | #endif |
| 196 | |
| 197 | // Set Elemental's RNG seed |
| 198 | El::Generator().seed(hash_combine(seed, 104729)); // 10000th prime |
| 199 | |
| 200 | // Initialize IO RNGs |
| 201 | init_io_random(seed, num_io_RNGs); |
| 202 | } |
| 203 | |
| 204 | void init_data_seq_random(int seed) |
| 205 | { |
no test coverage detected