star-sp

Random number generators and distributions
git clone git://git.meso-star.fr/star-sp.git
Log | Files | Refs | README | LICENSE

commit 4089873f6642a7bbe4fb2a0ba266a064ceb8aa90
parent a370aae963dfbab4aab5adba378736dc29afe6ac
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  2 Dec 2020 11:16:18 +0100

Comment the tests on the RNG proxy cache

Diffstat:
Msrc/test_ssp_rng_proxy.c | 38++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/test_ssp_rng_proxy.c b/src/test_ssp_rng_proxy.c @@ -468,23 +468,56 @@ test_cache(void) size_t i; /* Create a proxy with a very small sequence size of 2 RNs per bucket in - * order to maximize the number of cached states. */ + * order to maximize the number of cached states. Furthermore, use the + * Mersenne Twister RNG type since its internal state is the greatest one of + * the proposed builtin type and is thus the one that will fill quickly the + * cache stream. */ args.type = &ssp_rng_mt19937_64; args.sequence_size = 4; args.sequence_pitch = 4; args.nbuckets = 2; - CHK(ssp_rng_proxy_create2(NULL, &args, &proxy) == RES_OK); + /* Simply test that the RNs generated by the proxy are the same thant the + * ones generated by a regular RNG. Since each RNG invocation are + * interleaved, the cache pressure is very low, at most 1 RNG state is + * cached. */ + CHK(ssp_rng_proxy_create2(NULL, &args, &proxy) == RES_OK); CHK(ssp_rng_proxy_create_rng(proxy, 0, &rng0) == RES_OK); CHK(ssp_rng_proxy_create_rng(proxy, 1, &rng1) == RES_OK); + CHK(ssp_rng_create(NULL, &ssp_rng_mt19937_64, &rng) == RES_OK); + FOR_EACH(i, 0, nrands*2) { + if((i / 2) % 2) { + CHK(ssp_rng_get(rng1) == ssp_rng_get(rng)); + } else { + CHK(ssp_rng_get(rng0) == ssp_rng_get(rng)); + } + } + CHK(ssp_rng_proxy_ref_put(proxy) == RES_OK); + CHK(ssp_rng_ref_put(rng0) == RES_OK); + CHK(ssp_rng_ref_put(rng1) == RES_OK); + CHK(ssp_rng_ref_put(rng) == RES_OK); + CHK(ssp_rng_proxy_create2(NULL, &args, &proxy) == RES_OK); + CHK(ssp_rng_proxy_create_rng(proxy, 0, &rng0) == RES_OK); + CHK(ssp_rng_proxy_create_rng(proxy, 1, &rng1) == RES_OK); CHK(ssp_rng_create(NULL, &ssp_rng_mt19937_64, &rng) == RES_OK); + + /* Generate several RNs for the first RNG only to make under pressure the + * cache stream of 'rng1'. The cache stream limit is set to 32 MB and the + * size of a Mersenne Twister RNG state is greater than 6 KB. Consquently, + * ~5500 RNG states will exceed the cache stream, i.e. 5500*2 = 11000 + * random generations (since there is 2 RNs per bucket). Above this limit, + * 'rng1' will not rely anymore on the proxy RNG to manage its state. + * + * For both RNGs, ensure that the generated RNs are the expected ones by + * comparing them to the ones generated by a regular RNG */ FOR_EACH(i, 0, nrands) { CHK(ssp_rng_get(rng0) == ssp_rng_get(rng)); if(i % 2) CHK(ssp_rng_discard(rng, 2) == RES_OK); } CHK(ssp_rng_ref_put(rng) == RES_OK); + /* Check the cache mechanisme of rng1 */ CHK(ssp_rng_create(NULL, &ssp_rng_mt19937_64, &rng) == RES_OK); CHK(ssp_rng_discard(rng, 2) == RES_OK); FOR_EACH(i, 0, nrands) { @@ -496,6 +529,7 @@ test_cache(void) CHK(ssp_rng_proxy_ref_put(proxy) == RES_OK); CHK(ssp_rng_ref_put(rng0) == RES_OK); CHK(ssp_rng_ref_put(rng1) == RES_OK); + } int