the following code hangs using more than 1 thread and -O2 (or more) -mp optimation flag.
The same problem occurr in a “real life” fortran 95 code:
pgf90 10.3-0 64-bit target on x86-64 Linux -tp gh-64
Copyright 1989-2000, The Portland Group, Inc. All Rights Reserved.
Copyright 2000-2010, STMicroelectronics, Inc. All Rights Reserved.
REAL FUNCTION FN1(I)
FN1 = I * 2.0
END FUNCTION FN1
REAL FUNCTION FN2(A, B)
REAL A, B
FN2 = A + B
END FUNCTION FN2
use omp_lib !INCLUDE “omp_lib.h” ! or USE OMP_LIB
INTEGER IAM, NEIGHBOR
!$OMP PARALLEL PRIVATE(IAM, NEIGHBOR) SHARED(WORK, ISYNC)
IAM = OMP_GET_THREAD_NUM() + 1
ISYNC(IAM) = 0
! Do computation into my portion of work array WORK(IAM) = FN1(IAM)
! Announce that I am done with my work.
! The first flush ensures that my work is made visible before
! synch. The second flush ensures that synch is made visible.
ISYNC(IAM) = 1