diff --git a/cmake/NeuronFileLists.cmake b/cmake/NeuronFileLists.cmake index 8ce6f43969..789867c6a3 100644 --- a/cmake/NeuronFileLists.cmake +++ b/cmake/NeuronFileLists.cmake @@ -10,7 +10,6 @@ set(STRUCTURED_HEADER_FILES_TO_INSTALL neuron/model_data_fwd.hpp) set(HEADER_FILES_TO_INSTALL gnu/mcran4.h - gnu/nrnisaac.h gnu/nrnran123.h nrniv/backtrace_utils.h nrniv/bbsavestate.h diff --git a/src/gnu/CMakeLists.txt b/src/gnu/CMakeLists.txt index 1ce00c7fe6..6bf0820654 100644 --- a/src/gnu/CMakeLists.txt +++ b/src/gnu/CMakeLists.txt @@ -6,14 +6,11 @@ add_library( Erlang.cpp Geom.cpp HypGeom.cpp - isaac64.cpp - Isaac64RNG.cpp LogNorm.cpp MCellRan4RNG.cpp mcran4.cpp NegExp.cpp Normal.cpp - nrnisaac.cpp nrnran123.cpp Poisson.cpp Rand.cpp diff --git a/src/gnu/Isaac64RNG.cpp b/src/gnu/Isaac64RNG.cpp deleted file mode 100644 index 559c307d4d..0000000000 --- a/src/gnu/Isaac64RNG.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "Isaac64RNG.hpp" - -uint32_t Isaac64::cnt_ = 0; - -Isaac64::Isaac64(std::uint32_t seed) { - if (cnt_ == 0) { - cnt_ = 0xffffffff; - } - --cnt_; - seed_ = seed; - if (seed_ == 0) { - seed_ = cnt_; - } - rng_ = nrnisaac_new(); - reset(); -} - -Isaac64::~Isaac64() { - nrnisaac_delete(rng_); -} diff --git a/src/gnu/Isaac64RNG.hpp b/src/gnu/Isaac64RNG.hpp deleted file mode 100644 index c825c741ca..0000000000 --- a/src/gnu/Isaac64RNG.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include - -#include "RNG.h" -#include "nrnisaac.h" - -class Isaac64: public RNG { - public: - Isaac64(std::uint32_t seed = 0); - ~Isaac64(); - std::uint32_t asLong() { - return nrnisaac_uint32_pick(rng_); - } - void reset() { - nrnisaac_init(rng_, seed_); - } - double asDouble() { - return nrnisaac_dbl_pick(rng_); - } - std::uint32_t seed() { - return seed_; - } - void seed(std::uint32_t s) { - seed_ = s; - reset(); - } - - private: - std::uint32_t seed_; - void* rng_; - static std::uint32_t cnt_; -}; diff --git a/src/gnu/Rand.hpp b/src/gnu/Rand.hpp index 4d49a1155e..10e4df6380 100644 --- a/src/gnu/Rand.hpp +++ b/src/gnu/Rand.hpp @@ -9,7 +9,7 @@ struct Object; * 0: ACG * 1: unused * 2: MCellRan4 - * 3: Isaac64 + * 3: unused * 4: Random123 */ class Rand { diff --git a/src/gnu/isaac64.cpp b/src/gnu/isaac64.cpp deleted file mode 100644 index b0c6c40317..0000000000 --- a/src/gnu/isaac64.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* ------------------------------------------------------------------------------- -isaac64.cpp: A Fast cryptographic random number generator - for 32-bit and 64-bit machines. -By Bob Jenkins, 1996. Public Domain. - -Modified for modularity by Tom Bartol and Rex Kerr ------------------------------------------------------------------------------- -*/ -#include "isaac64.h" - - -#define ind(mm, x) (*(ub8*) ((ub1*) (mm) + ((x) & ((RANDSIZ - 1) << 3)))) - -#define rngstep(mix, a, b, mm, m, m2, r, x) \ - { \ - x = *m; \ - a = (mix) + *(m2++); \ - *(m++) = y = ind(mm, x) + a + b; \ - *(r++) = b = ind(mm, y >> RANDSIZL) + x; \ - } - -#define mix(a, b, c, d, e, f, g, h) \ - { \ - a -= e; \ - f ^= h >> 9; \ - h += a; \ - b -= f; \ - g ^= a << 9; \ - a += b; \ - c -= g; \ - h ^= b >> 23; \ - b += c; \ - d -= h; \ - a ^= c << 15; \ - c += d; \ - e -= a; \ - b ^= d >> 14; \ - d += e; \ - f -= b; \ - c ^= e << 20; \ - e += f; \ - g -= c; \ - d ^= f >> 17; \ - f += g; \ - h -= d; \ - e ^= g << 14; \ - g += h; \ - } - - -void isaac64_generate(struct isaac64_state* rng) { - ub8 a, b, x, y, *m, *m2, *r, *mend; - - m = rng->mm; - r = rng->randrsl; - a = rng->aa; - b = rng->bb + (++rng->cc); - for (m = rng->mm, mend = m2 = m + (RANDSIZ / 2); m < mend;) { - rngstep(~(a ^ (a << 21)), a, b, rng->mm, m, m2, r, x); - rngstep(a ^ (a >> 5), a, b, rng->mm, m, m2, r, x); - rngstep(a ^ (a << 12), a, b, rng->mm, m, m2, r, x); - rngstep(a ^ (a >> 33), a, b, rng->mm, m, m2, r, x); - } - for (m2 = rng->mm; m2 < mend;) { - rngstep(~(a ^ (a << 21)), a, b, rng->mm, m, m2, r, x); - rngstep(a ^ (a >> 5), a, b, rng->mm, m, m2, r, x); - rngstep(a ^ (a << 12), a, b, rng->mm, m, m2, r, x); - rngstep(a ^ (a >> 33), a, b, rng->mm, m, m2, r, x); - } - rng->bb = b; - rng->aa = a; -} - - -void isaac64_init(struct isaac64_state* rng, ub4 seed) { - ub8 *r, *m; - ub8 a, b, c, d, e, f, g, h; - ub4 i; - - rng->aa = (ub8) 0; - rng->bb = (ub8) 0; - rng->cc = (ub8) 0; - - a = b = c = d = e = f = g = h = 0x9e3779b97f4a7c13LL; /* the golden ratio */ - - r = rng->randrsl; - m = rng->mm; - - for (i = 0; i < RANDSIZ; ++i) - r[i] = (ub8) 0; - - r[0] = seed; - - for (i = 0; i < 4; ++i) /* scramble it */ - { - mix(a, b, c, d, e, f, g, h); - } - - for (i = 0; i < RANDSIZ; i += 8) /* fill in m[] with messy stuff */ - { - /* use all the information in the seed */ - a += r[i]; - b += r[i + 1]; - c += r[i + 2]; - d += r[i + 3]; - e += r[i + 4]; - f += r[i + 5]; - g += r[i + 6]; - h += r[i + 7]; - mix(a, b, c, d, e, f, g, h); - m[i] = a; - m[i + 1] = b; - m[i + 2] = c; - m[i + 3] = d; - m[i + 4] = e; - m[i + 5] = f; - m[i + 6] = g; - m[i + 7] = h; - } - - /* do a second pass to make all of the seed affect all of m[] */ - for (i = 0; i < RANDSIZ; i += 8) { - a += m[i]; - b += m[i + 1]; - c += m[i + 2]; - d += m[i + 3]; - e += m[i + 4]; - f += m[i + 5]; - g += m[i + 6]; - h += m[i + 7]; - mix(a, b, c, d, e, f, g, h); - m[i] = a; - m[i + 1] = b; - m[i + 2] = c; - m[i + 3] = d; - m[i + 4] = e; - m[i + 5] = f; - m[i + 6] = g; - m[i + 7] = h; - } - - isaac64_generate(rng); /* fill in the first set of results */ - rng->randcnt = RANDMAX; /* prepare to use the first set of results */ -} diff --git a/src/gnu/isaac64.h b/src/gnu/isaac64.h deleted file mode 100644 index 4af3b7586e..0000000000 --- a/src/gnu/isaac64.h +++ /dev/null @@ -1,88 +0,0 @@ -#pragma once - -/* ------------------------------------------------------------------------------- -isaac64.h: Definitions for a fast cryptographic random number generator -Bob Jenkins, 1996, Public Domain - -Modified for modularity by Tom Bartol and Rex Kerr - -Reference: -http://burtleburtle.net/bob/rand/isaacafa.html -Jenkins, R.J. (1996) ISAAC, in Fast Software Encryption, vol. 1039, - ed. Gollmann, D. Spinger-Verlag, Cambridge - ------------------------------------------------------------------------------- -*/ - -#include - -#define RANDSIZL (4) /* I recommend 8 for crypto, 4 for simulations */ -#define RANDSIZ (1 << RANDSIZL) -#define RANDMAX (2 * RANDSIZ) - -typedef unsigned long long ub8; -#if defined(uint32_t) -typedef uint32_t ub4; -#else -typedef unsigned int ub4; -#endif -typedef unsigned short int ub2; -typedef unsigned char ub1; - -#define DBL32 (2.3283064365386962890625e-10) -#define DBL53 (1.1102230246251565404236316680908203125e-16) -#define DBL64 (5.42101086242752217003726400434970855712890625e-20) -#define MSK53 0x001FFFFFFFFFFFFFLL - -struct isaac64_state { - int randcnt; - ub8 aa; - ub8 bb; - ub8 cc; - ub8 randrsl[RANDSIZ]; - ub8 mm[RANDSIZ]; -}; - - -void isaac64_init(struct isaac64_state* rng, ub4 seed); - -void isaac64_generate(struct isaac64_state* rng); - -/* ------------------------------------------------------------------------------- -Macros to get individual random numbers ------------------------------------------------------------------------------- -*/ - -#define isaac64_uint32(rng) \ - (rng->randcnt > 0 ? (*(((ub4*) (rng->randrsl)) + (rng->randcnt -= 1))) \ - : (isaac64_generate(rng), \ - rng->randcnt = RANDMAX - 1, \ - *(((ub4*) (rng->randrsl)) + rng->randcnt))) - -#define isaac64_uint64(rng) \ - (rng->randcnt > 1 ? (*((ub8*) (((ub4*) (rng->randrsl)) + (rng->randcnt -= 2)))) \ - : (isaac64_generate(rng), \ - rng->randcnt = RANDMAX - 2, \ - *((ub8*) (((ub4*) (rng->randrsl)) + rng->randcnt)))) - -#define isaac64_dbl32(rng) \ - (rng->randcnt > 0 ? (DBL32 * (*(((ub4*) (rng->randrsl)) + (rng->randcnt -= 1)))) \ - : (isaac64_generate(rng), \ - rng->randcnt = RANDMAX - 1, \ - DBL32 * (*(((ub4*) (rng->randrsl)) + rng->randcnt)))) - -#define isaac64_dbl53(rng) \ - (rng->randcnt > 1 \ - ? (DBL53 * ((*((ub8*) (((ub4*) (rng->randrsl)) + (rng->randcnt -= 2)))) >> 11)) \ - : (isaac64_generate(rng), \ - rng->randcnt = RANDMAX - 2, \ - DBL64 * ((*((ub8*) (((ub4*) (rng->randrsl)) + rng->randcnt))) >> 11))) - -#define isaac64_dbl64(rng) \ - (rng->randcnt > 1 ? (DBL64 * (*((ub8*) (((ub4*) (rng->randrsl)) + (rng->randcnt -= 2))))) \ - : (isaac64_generate(rng), \ - rng->randcnt = RANDMAX - 2, \ - DBL64 * (*((ub8*) (((ub4*) (rng->randrsl)) + rng->randcnt))))) - diff --git a/src/gnu/nrnisaac.cpp b/src/gnu/nrnisaac.cpp deleted file mode 100644 index f0549a4d9a..0000000000 --- a/src/gnu/nrnisaac.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include "nrnisaac.h" -#include "isaac64.h" - -using RNG = struct isaac64_state; - -void* nrnisaac_new() { - return new RNG; -} - -void nrnisaac_delete(void* v) { - delete static_cast(v); -} - -void nrnisaac_init(void* v, unsigned long int seed) { - isaac64_init(static_cast(v), seed); -} - -double nrnisaac_dbl_pick(void* v) { - return isaac64_dbl32(static_cast(v)); -} - -std::uint32_t nrnisaac_uint32_pick(void* v) { - return isaac64_uint32(static_cast(v)); -} diff --git a/src/gnu/nrnisaac.h b/src/gnu/nrnisaac.h deleted file mode 100644 index 5322febafe..0000000000 --- a/src/gnu/nrnisaac.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include - -void* nrnisaac_new(); -void nrnisaac_delete(void* rng); -void nrnisaac_init(void* rng, unsigned long int seed); -double nrnisaac_dbl_pick(void* rng); -std::uint32_t nrnisaac_uint32_pick(void* rng); diff --git a/src/ivoc/ivocmain.cpp b/src/ivoc/ivocmain.cpp index 226b37cf11..5262af8ae3 100644 --- a/src/ivoc/ivocmain.cpp +++ b/src/ivoc/ivocmain.cpp @@ -234,14 +234,6 @@ extern std::string nrnmpi_load(); void nrnmpi_load_or_exit(); #endif -// some things are defined in libraries earlier than they are used so... -#include -static void force_load() { - if (always_false) { - nrnisaac_new(); - } -} - #ifdef MINGW // see iv/src/OS/directory.cpp #include @@ -382,7 +374,6 @@ int ivocmain_session(int argc, const char** argv, const char** env, int start_se // extern char** environ; int i; // prargs("at beginning", argc, argv); - force_load(); nrn_global_argc = argc; // https://en.cppreference.com/w/cpp/language/main_function, note that argv is // of length argc + 1 and argv[argc] is null. diff --git a/src/ivoc/ivocrand.cpp b/src/ivoc/ivocrand.cpp index 7e67c17a92..957f256874 100644 --- a/src/ivoc/ivocrand.cpp +++ b/src/ivoc/ivocrand.cpp @@ -9,7 +9,6 @@ #include #include "classreg.h" #include "oc2iv.h" -#include "nrnisaac.h" #include "utils/enumerate.h" #include @@ -31,7 +30,6 @@ #include #include #include -#include #include #include @@ -246,29 +244,6 @@ int nrn_random123_getseq(Rand* r, uint32_t* seq, char* which) { return 1; } -static double r_Isaac64(void* r) { - Rand* x = (Rand*) r; - - uint32_t seed1 = 0; - - if (ifarg(1)) { - seed1 = static_cast(*getarg(1)); - } - - double seed{}; - try { - Isaac64* mcr = new Isaac64(seed1); - x->rand->generator(mcr); - delete x->gen; - x->gen = x->rand->generator(); - x->type_ = 3; - seed = mcr->seed(); - } catch (const std::bad_alloc& e) { - hoc_execerror("Bad allocation for Isaac64 generator", e.what()); - } - return seed; -} - // Pick again from the distribution last used // syntax: // r.repick() @@ -465,7 +440,6 @@ extern "C" void nrn_random_play() { static Member_func r_members[] = {{"ACG", r_ACG}, - {"Isaac64", r_Isaac64}, {"MCellRan4", r_MCellRan4}, {"Random123", r_nrnran123}, {"Random123_globalindex", r_ran123_globalindex}, diff --git a/src/nrniv/multisend_setup.cpp b/src/nrniv/multisend_setup.cpp index 8e66681e8c..d9c70d08ad 100644 --- a/src/nrniv/multisend_setup.cpp +++ b/src/nrniv/multisend_setup.cpp @@ -9,6 +9,8 @@ the source host owning the gid. */ #include "oc_ansi.h" +#include + static void del(int* a) { if (a) { delete[] a; @@ -92,18 +94,16 @@ void TarList::alloc() { } } -#include -static void* ranstate; +static nrnran123_State* ranstate; static void random_init(int i) { if (!ranstate) { - ranstate = nrnisaac_new(); + ranstate = nrnran123_newstream(i, 0); } - nrnisaac_init(ranstate, nrnmpi_myid + 1); } static unsigned int get_random() { - return nrnisaac_uint32_pick(ranstate); + return nrnran123_ipick(ranstate); } static int iran(int i1, int i2) {