Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Issue with !$OMP CANCEL construct

OP1
New Contributor III
33 Views

Using the latest ifx compiler (2026.0.0) on Windows 11 in Debug mode, the following code hangs fairly regularly (even when running with a modest number of threads):

PROGRAM P
USE OMP_LIB
IMPLICIT NONE (TYPE, EXTERNAL)

INTEGER :: I, SUM, VERSION


! Check if the cancellation feature is activated (a requirement for the CANCEL construct to work).

IF (.NOT. OMP_GET_CANCELLATION()) THEN
    WRITE(*, *) 'The CANCEL feature is not activated. Set the environment variable OMP_CANCELLATION to true.'
    STOP
END IF


! This will fail (that is, the code will hang) randomly, when running the code 
! multiple times.

!$OMP PARALLEL

    WRITE(*, *) OMP_GET_THREAD_NUM(), '/', OMP_GET_NUM_THREADS()

    !$OMP DO REDUCTION(+:SUM)
        DO I = 1, 10000
            SUM = SUM + I
            !$OMP CANCEL DO IF (I == 5)
        END DO
    !$OMP END DO

!$OMP END PARALLEL

WRITE(*, *) SUM

END PROGRAM P

I do not see any restrictions associated with the use of the REDUCTION clause with CANCEL constructs in the OpenMP specification. It does look like a bug.

0 Kudos
0 Replies
Reply