NEURON
test_random.cpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2024 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================.
7 */
8 #include <catch2/catch_test_macros.hpp>
9 #include <set>
11 
12 using namespace coreneuron;
13 
14 TEST_CASE("random123 smoke test") {
15  const int SEED_KEY = 1;
16  const int NUM_STREAMS = 20;
17  const int NUM_SAMPLES = 1000;
18  nrnran123_State* rand_streams[NUM_STREAMS];
19 
20  const int res_size = NUM_SAMPLES * NUM_STREAMS;
21  double res[res_size];
22 
23  for (int i = 0; i < NUM_STREAMS; i++) {
24  rand_streams[i] = nrnran123_newstream(SEED_KEY, i);
25  nrnran123_setseq(rand_streams[i], 0, 0);
26  }
27 
28  nrn_pragma_omp(target teams distribute parallel for map(tofrom: res[0:res_size]) map(to: rand_streams[0:NUM_STREAMS]))
29  nrn_pragma_acc(parallel loop copy(res [0:res_size]) copyin(rand_streams [0:NUM_STREAMS]))
30  for (int i = 0; i < NUM_STREAMS; i++) {
31  for (int j = 0; j < NUM_SAMPLES; j++) {
32  double val = nrnran123_dblpick(rand_streams[i]);
33  res[i * NUM_SAMPLES + j] = val;
34  }
35  }
36 
37  // there should be no duplicates
38 
39  std::set<double> check_set;
40 
41  for (int i = 0; i < NUM_STREAMS * NUM_SAMPLES; i++) {
42  double d = res[i];
43  size_t old_size = check_set.size();
44  check_set.insert(res[i]);
45  size_t new_size = check_set.size();
46 
47  if (old_size == new_size) {
48  std::cerr << "Duplicate found! i = " << i << ", d = " << d << std::endl;
49  }
50  }
51  REQUIRE(check_set.size() == NUM_SAMPLES * NUM_STREAMS);
52 }
#define i
Definition: md1redef.h:19
nrn_pragma_acc(routine seq) nrn_pragma_omp(declare target) philox4x32_ctr_t coreneuron_random123_philox4x32_helper(coreneuron nrn_pragma_omp(end declare target) namespace coreneuron
Provide a helper function in global namespace that is declared target for OpenMP offloading to functi...
Definition: nrnran123.h:66
nrnran123_State * nrnran123_newstream()
Construct a new Random123 stream based on the philox4x32 generator.
Definition: nrnran123.cpp:31
double nrnran123_dblpick(nrnran123_State *s)
Definition: nrnran123.cpp:122
void nrnran123_setseq(nrnran123_State *s, std::uint32_t seq, char which)
Set a Random123 sequence for a sequnece ID and which selector.
Definition: nrnran123.cpp:55
static double map(void *v)
Definition: mlinedit.cpp:43
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
nrn_pragma_acc(routine seq) int vector_capacity(void *v)
Definition: ivocvect.cpp:30
size_t j
TEST_CASE("random123 smoke test")
Definition: test_random.cpp:14