Open zoziha opened 2 years ago
The reason I modified the stdlib_random
was because I planned to generate a downstream stdlib
with only real64
and int32
, so that I could use lightweight stdlib
(see dp-stdlib) within fpm projects.
@zoziha For what it's worth I've previously run into compiler problems at this part of the code (when using inter-procedural optimization). Although it would be good to hear from @Jim-215-Fisher, to my knowledge the line si = res + int01
is not a coding error -- the intention is indeed to update the random number generator state.
To give a bit more context - if I compile stdlib with:
make -B -f Makefile.manual ADD_FYPPFLAGS=-DMAXRANK=4 FC=gfortran FFLAGS="-O3 -flto"
then I get a segfault on the test program in stdlib/src/tests/stats/test_random
, which I believe is also related to this part of the code (it manifests in repeated calls to splitmix64
).
But if I remove the link-time-optimization then it works OK, i.e. using
make -B -f Makefile.manual ADD_FYPPFLAGS=-DMAXRANK=4 FC=gfortran FFLAGS="-O3"
the same test passes.
The following may be relevant. concerning linkage time optimization causing segmentation fault https://stackoverflow.com/questions/68723476/why-does-link-time-optimization-cause-a-segmentation-fault
Link time optimization causing segmentation faults from a scholars context. https://scholar.google.com.au/scholar?hl=en&as_sdt=0%2C5&q=link+time+optimization+causes+segmentation+fault&btnG=
Undefined behaviours in computer programming, a scholarly reading list and bibliography, because undefined behaviors lead to segmentation faults. https://scholar.google.com/scholar?hl=en&as_sdt=0%2C5&q=undefined+behaviour+in+computer+programs&btnG=
Detecting undefined behavious in computer programming a scholarly bibliography and reading list, because undefined behaviours can lead to segmentation faults. https://scholar.google.com.au/scholar?hl=en&as_sdt=0%2C5&q=detecting+undefined+behaviour+in+computer+programs&btnG=
Description
During a development, I found an unexpected situation: swapping
optval(s, si)
in thestdlib_random
forif (present(s)) then ..
form, and unit tests ofmacos
andubuntu
systems failed.(see https://github.com/zoziha/stdlib/commits/update_random)
Possible Problem https://github.com/fortran-lang/stdlib/blob/100f76098c834df29a800b3dcb1a0a59f295ae12/src/stdlib_random.fypp#L123 Maybe:
cc @Jim-215-Fisher
Expected Behaviour
CI failed: https://github.com/zoziha/stdlib/actions/runs/1554566528
Expected behaviour:
optval
==if (present(..)) then ..
Version of stdlib
100f76098c834df29a800b3dcb1a0a59f295ae12
Platform and Architecture
MacOS, GFortran 9 10 11; Ubuntu, GFortran 10
Additional Information
No response