View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000233 | OpenFOAM | Bug | public | 2011-06-29 11:18 | 2011-11-03 17:12 |
Reporter | wyldckat | Assigned To | |||
Priority | normal | Severity | tweak | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Summary | 0000233: srand48, lrand48 and drand48 are POSIX and therefore OS specific | ||||
Description | OpenFOAM's random functions are directly relying on POSIX (srand48, lrand48, drand48) or Unix functions (random, srandom). Attached is a patch that extracts these "basic" functions from the OpenFOAM core to the OS specific _outlier level_. | ||||
Steps To Reproduce | When "hacking" the code for compatibility with other Operating Systems, the Foam::Random class gets a seriously "ugly hack" done on it :( | ||||
Additional Information | This separation can make life a bit easier for changing how the random numbers are calculated, including some optimizations or upgrades can be made for using more or less bits (GMP or MPFR? Or even independent hardware random number generator!). | ||||
Tags | No tags attached. | ||||
|
|
|
see commit a53a51fcc0679440d6dc3ab396e3da080a179205 Thanks for that. |
|
Nice! But... I think you forgot to push it to the repo 2.0.x on github :( |
|
I did indeed forget the push. Should be there now. Thanks, Mattijs |
|
I'm sorry for re-opening this issue again, but I forgot about the need to divide by INT_MAX when using USE_RANDOM. I only noticed it when reviewing the commit you pushed. The attached file "patch_random_unix_part" fixes this last issue. |
|
patch_random_unix_part (707 bytes)
diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index dba1e73..c79d8f0 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -59,6 +59,10 @@ Description #ifdef USE_RANDOM # include <climits> +# if INT_MAX != 2147483647 +# error "INT_MAX != 2147483647" +# error "The random number generator may not work!" +# endif #endif // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -1250,7 +1254,7 @@ Foam::label Foam::osRandomInteger() Foam::scalar Foam::osRandomDouble() { #ifdef USE_RANDOM - return (scalar)random(); + return (scalar)random()/INT_MAX; #else return drand48(); #endif |
|
Fixed in commit f6fa6eb9dafe4e1eea0fbdead745ba641afae6de |
|
I missed a line in the initially proposed patch. The recently attached file "cachedRandom_missing_patch" has the missing change. The "#if INT_MAX then error" at the top might also be discarded, since it's not being used in this particular file. Note: I saw this thanks to Symscape's mingw patches. |
|
cachedRandom_missing_patch (526 bytes)
diff --git a/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.C b/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.C index 4bf4054..7cd5d84 100644 --- a/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.C +++ b/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.C @@ -79,7 +79,7 @@ Foam::cachedRandom::cachedRandom(const label seed, const label count) osRandomSeed(seed_); forAll(samples_, i) { - samples_[i] = drand48(); + samples_[i] = osRandomDouble(); } } |
|
pushed to 0721eb3218b63f48209b54fa13f5e23825a141ec Thanks for cleanup. |
Date Modified | Username | Field | Change |
---|---|---|---|
2011-06-29 11:18 | wyldckat | New Issue | |
2011-06-29 11:18 | wyldckat | File Added: patch_random_to_OSspecific.gz | |
2011-07-01 16:16 |
|
Note Added: 0000502 | |
2011-07-01 16:16 |
|
Status | new => resolved |
2011-07-01 16:16 |
|
Fixed in Version | => 2.0.x |
2011-07-01 16:16 |
|
Resolution | open => fixed |
2011-07-01 16:16 |
|
Assigned To | => user4 |
2011-07-01 22:57 | wyldckat | Note Added: 0000503 | |
2011-07-01 22:57 | wyldckat | Status | resolved => feedback |
2011-07-01 22:57 | wyldckat | Resolution | fixed => reopened |
2011-07-04 09:53 |
|
Note Added: 0000507 | |
2011-07-04 09:53 |
|
Status | feedback => closed |
2011-07-04 09:53 |
|
Resolution | reopened => fixed |
2011-07-04 12:50 | wyldckat | Note Added: 0000513 | |
2011-07-04 12:50 | wyldckat | Status | closed => feedback |
2011-07-04 12:50 | wyldckat | Resolution | fixed => reopened |
2011-07-04 12:50 | wyldckat | File Added: patch_random_unix_part | |
2011-07-04 14:41 |
|
Note Added: 0000515 | |
2011-07-04 14:41 |
|
Status | feedback => resolved |
2011-07-04 14:41 |
|
Resolution | reopened => fixed |
2011-10-06 11:50 | wyldckat | Note Added: 0000690 | |
2011-10-06 11:50 | wyldckat | Status | resolved => feedback |
2011-10-06 11:50 | wyldckat | Resolution | fixed => reopened |
2011-10-06 11:51 | wyldckat | File Added: cachedRandom_missing_patch | |
2011-10-06 11:51 | wyldckat | Note Edited: 0000690 | |
2011-11-03 17:12 |
|
Note Added: 0000783 | |
2011-11-03 17:12 |
|
Status | feedback => resolved |
2011-11-03 17:12 |
|
Resolution | reopened => fixed |