fortran-lang / stdlib

Fortran Standard Library
https://stdlib.fortran-lang.org
MIT License
1.06k stars 164 forks source link

`loadtxt` test occasionally fails #862

Open minhqdao opened 1 month ago

minhqdao commented 1 month ago

Description

It's a little bit tricky to reproduce but the loadtxt test occasionally fails (maybe 10-20% of the time). Mostly, it happens in the CI with the combination ubuntu-latest/gcc/12/cmake:

159/324 Test #158: loadtxt ................................***Failed    0.01 sec
At line 171 of file /home/runner/work/stdlib/stdlib/build/src/stdlib_io.f90
Fortran runtime error: Bad value during floating point read

Error termination. Backtrace:
#0  0x7fafd0c23960 in ???
#1  0x7fafd0c244d9 in ???
#2  0x7fafd0e75aba in ???
#3  0x7fafd0e796b9 in ???
#4  0x7fafd0e7ae55 in ???
#5  0x7fafd0e77b7a in ???
#6  0x55e0c2cce272 in __stdlib_io_MOD_loadtxt_rsp
#7  0x55e0c2cc33c7 in MAIN__
#8  0x55e0c2cc345b in main

However, I've also seen it happening with intel and intel-classic:

157/324 Test #158: loadtxt ................................***Failed    0.01 sec
forrtl: severe (24): end-of-file during read, unit -129, file /home/runner/work/stdlib/stdlib/example/io/example.dat
Image              PC                Routine            Line        Source             
example_loadtxt    0000000000436426  Unknown               Unknown  Unknown
example_loadtxt    00000000004049DB  Unknown               Unknown  Unknown
example_loadtxt    000000000040423C  Unknown               Unknown  Unknown
example_loadtxt    00000000004041CD  Unknown               Unknown  Unknown
libc.so.6          00007F854EA29D90  Unknown               Unknown  Unknown
libc.so.6          00007F854EA29E40  __libc_start_main     Unknown  Unknown
example_loadtxt    00000000004040E5  Unknown               Unknown  Unknown

Expected Behaviour

Test reliably not failing.

Version of stdlib

master

Platform and Architecture

CI: Mostly ubuntu-latest, gcc-12, cmake, but also with other combinations, e.g. ifort

chuckyvt commented 4 weeks ago

Note the following thread on the Fortran discourse has some similarities to this issues, however not sure they are related.

https://fortran-lang.discourse.group/t/why-am-i-getting-an-error-with-list-directed-read/8562

perazz commented 1 week ago

One possible explanation is that the loadtxt formats always require one space (1x) to be present after each entry:

https://github.com/fortran-lang/stdlib/blob/c663dc1c03b55c81aab6927bf13abab8fdb13f91/src/stdlib_io.fypp#L150

this may trigger end-of-record or end-of-file exceptions i.e. if there is no such last space