Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optval issue in stdlib_random module #592

Open
zoziha opened this issue Dec 8, 2021 · 7 comments
Open

optval issue in stdlib_random module #592

zoziha opened this issue Dec 8, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@zoziha
Copy link
Contributor

zoziha commented Dec 8, 2021

Description

During a development, I found an unexpected situation: swapping optval(s, si) in the stdlib_random for if (present(s)) then .. form, and unit tests of macos and ubuntu systems failed.

image
(see https://github.com/zoziha/stdlib/commits/update_random)

Possible Problem

si = res + int01

Maybe:

res = res + int01 !?

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

100f760

Platform and Architecture

MacOS, GFortran 9 10 11; Ubuntu, GFortran 10

Additional Information

No response

@zoziha zoziha added the bug Something isn't working label Dec 8, 2021
@zoziha
Copy link
Contributor Author

zoziha commented Dec 8, 2021

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.

@gareth-nx
Copy link
Contributor

@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.

@gareth-nx
Copy link
Contributor

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.

gareth-nx added a commit to gareth-nx/stdlib that referenced this issue Dec 12, 2021
This removes the use of the option `-flto` in the instructions to compile with a Makefile.

The reason for doing that is that currently, `-flto` can cause some tests to break - see [discussion here](fortran-lang#592 (comment)).
@iajzenszmi
Copy link

iajzenszmi commented Dec 15, 2021

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

@iajzenszmi
Copy link

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=

@iajzenszmi
Copy link

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=

@iajzenszmi
Copy link

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=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants