[flang-commits] [flang] 301a0db - [flang][runtime] Better non-repeatable RANDOM_INIT() (#67363)
via flang-commits
flang-commits at lists.llvm.org
Mon Oct 16 14:29:44 PDT 2023
Author: Peter Klausler
Date: 2023-10-16T14:29:40-07:00
New Revision: 301a0dba56e176e3f236fc069405e3b929a76c94
URL: https://github.com/llvm/llvm-project/commit/301a0dba56e176e3f236fc069405e3b929a76c94
DIFF: https://github.com/llvm/llvm-project/commit/301a0dba56e176e3f236fc069405e3b929a76c94.diff
LOG: [flang][runtime] Better non-repeatable RANDOM_INIT() (#67363)
Use a higher-frequency clock base when initializing the pseudo-random
number generator to implement
CALL RANDOM_INIT(REPEATABLE=.FALSE.)
Added:
Modified:
flang/runtime/random.cpp
Removed:
################################################################################
diff --git a/flang/runtime/random.cpp b/flang/runtime/random.cpp
index b7175d6b63c35f8..8b00cfd1cac1950 100644
--- a/flang/runtime/random.cpp
+++ b/flang/runtime/random.cpp
@@ -20,10 +20,10 @@
#include <algorithm>
#include <cmath>
#include <cstdint>
-#include <ctime>
#include <limits>
#include <memory>
#include <random>
+#include <time.h>
namespace Fortran::runtime {
@@ -100,7 +100,13 @@ void RTNAME(RandomInit)(bool repeatable, bool /*image_distinct*/) {
if (repeatable) {
generator.seed(0);
} else {
- generator.seed(std::time(nullptr));
+#ifdef CLOCK_REALTIME
+ timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ generator.seed(ts.tv_sec & ts.tv_nsec);
+#else
+ generator.seed(time(nullptr));
+#endif
}
}
}
More information about the flang-commits
mailing list