Reputation: 60018
Consider the following Fortran + OpenMP program.
use ieee_exceptions
implicit none
integer, parameter :: n = 100
real :: nom(n)
integer :: denom(n)
logical :: saved_fpe_mode(size(ieee_all))
integer :: i
nom = 1
denom = 0
call ieee_set_halting_mode(ieee_overflow, .true.)
call ieee_set_halting_mode(ieee_invalid, .true.)
call ieee_set_halting_mode(ieee_divide_by_zero, .true.)
!$omp parallel
print *,"hello from a thread"
!$omp end parallel
call ieee_get_halting_mode(ieee_all, saved_fpe_mode)
call ieee_set_halting_mode(ieee_all, .false.)
!$omp parallel do
do i = 1, n
nom(i) = nom(i) / denom(i)
end do
!$omp end parallel do
nom = min(max(0., nom), 1.)
!$omp parallel
call ieee_set_halting_mode(ieee_all, saved_fpe_mode)
!$omp end parallel
print *, nom
end
Is this code conforming to the joint combination of the Fortran standard and the OpenMP specifications? If yes, is this code supposed to halt or not when executed with multiple threads?
Upvotes: 3
Views: 126
Reputation: 900
% gfcx -o z -fopenmp -g b.f90 && ./z
hello from a thread
hello from a thread
hello from a thread
hello from a thread
hello from a thread
hello from a thread
hello from a thread
hello from a thread
Floating exception (core dumped)
% gdb131 ./z z.core
...
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./z...
[New LWP 842524]
[New LWP 570543]
[New LWP 842525]
[New LWP 842526]
[New LWP 842527]
[New LWP 842528]
[New LWP 842529]
[New LWP 842530]
warning: Unexpected size of section `.reg-xstate/842524' in core file.
warning: Could not load shared library symbols for [vdso].
Do you need "set solib-search-path" or "set sysroot"?
--Type <RET> for more, q to quit, c to continue without paging--
Core was generated by `./z'.
Program terminated with signal SIGFPE, Arithmetic exception.
warning: Unexpected size of section `.reg-xstate/842524' in core file.
#0 0x0000000000400f64 in MAIN__::MAIN__._omp_fn.1 () at b.f90:28
28 nom(i) = nom(i) / denom(i)
[Current thread is 1 (LWP 842524)]
(gdb) bt
#0 0x0000000000400f64 in MAIN__::MAIN__._omp_fn.1 () at b.f90:28
#1 0x000000024210501e in gomp_thread_start (xdata=<optimized out>)
at ../../../gccx/libgomp/team.c:129
#2 0x0000000244b38a75 in thread_start (curthread=0x1676c0612700)
at /usr/src/lib/libthr/thread/thr_create.c:290
#3 0x0000000000000000 in ?? ()
If the code is modified to
!$omp parallel
call ieee_get_halting_mode(ieee_all, saved_fpe_mode)
call ieee_set_halting_mode(ieee_all, .false.)
print *,"hello from a thread"
!$omp end parallel
It compiles and executes. So, setting the fpu state seems to be thread specific. Probably still worth a bug report.
Upvotes: 1