From 6c60ea84f13158644888a1c018260783a39a4350 Mon Sep 17 00:00:00 2001 From: Szabolcs Horvat Date: Sun, 20 Nov 2022 13:28:36 +0000 Subject: [PATCH] upstream: fixed: benchmarks: RNG call: explicit order Origin: upstream Forwarded: not-needed Last-Update: 2022-11-20 Upstream patch 3ae6dcb: refactor RNG calls [in t/b/igraph_distances.c] to guarantee evaluation order Gbp-Pq: Name upstream-fixed-benchmarks-ig_distances-RNG-explicit_order.patch --- tests/benchmarks/igraph_distances.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/benchmarks/igraph_distances.c b/tests/benchmarks/igraph_distances.c index 1a0fb46..51ba2d2 100644 --- a/tests/benchmarks/igraph_distances.c +++ b/tests/benchmarks/igraph_distances.c @@ -46,7 +46,10 @@ int main(void) { RNG_BEGIN(); for (igraph_integer_t i=0; i < trunc(0.005 * igraph_ecount(&g)); i++) { - VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = RNG_UNIF(-0.05, 0); + /* For reproducibility, do not write two RNG_...() calls on the same line + * as the C language does not guarantee any evaluation order between them. */ + igraph_real_t w = RNG_UNIF(-0.05, 0); + VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = w; } RNG_END(); @@ -97,7 +100,10 @@ int main(void) { RNG_BEGIN(); for (igraph_integer_t i=0; i < trunc(0.002 * igraph_ecount(&g)); i++) { - VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = RNG_UNIF(-0.02, 0); + /* For reproducibility, do not write two RNG_...() calls on the same line + * as the C language does not guarantee any evaluation order between them. */ + igraph_real_t w = RNG_UNIF(-0.02, 0); + VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = w; } RNG_END(); @@ -148,7 +154,10 @@ int main(void) { RNG_BEGIN(); for (igraph_integer_t i=0; i < trunc(0.01 * igraph_ecount(&g)); i++) { - VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = RNG_UNIF(-0.02, 0); + /* For reproducibility, do not write two RNG_...() calls on the same line + * as the C language does not guarantee any evaluation order between them. */ + igraph_real_t w = RNG_UNIF(-0.02, 0); + VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = w; } RNG_END(); -- 2.30.2