Two block constructs in a PARALLEL region

I’d be grateful for some advice. Consider the following code:

program test
implicit none

!$OMP PARALLEL
block

end block
block

end block
!$OMP END PARALLEL

end program

Intel fortran (ifort and ifx) and GFortran versions 8 - 11 compile the code fine.

However, GFortran versions 14 and 15 yield:

> gfortran -fopenmp test.f90

test.f90:12:18:

12 | !$OMP END PARALLEL
   |                  1
Error: Unexpected !$OMP END PARALLEL statement at (1)

This only happens when there are two blocks in the same PARALLEL region.

Is this somehow non-complaint OpenMP or a compiler bug?

1 Like

OpenMP 6.0 adds blocks as parallel scopes (screenshot taken from this presentation)

But I’m not sure if this is the issue here.

GCC 12 added support for OpenMP strictly structured blocks, from OpenMP 5.2 spec, page 3:

and page 52:

Perhaps this can be used as a workaround?

!$OMP PARALLEL
block
  block

  end block 
  block

  end block
end block

Edit: link to compiler explorer: Compiler Explorer

1 Like

Thanks @ivanpribec your workaround works.

However, I’ve since found that inserting a line of anything before the first block also fixes the problem:

program test
implicit none
integer i

!$OMP PARALLEL
i=1
block

end block
block

end block
!$OMP END PARALLEL

end program

I think this may be a compiler bug.

@ivanpribec
GCC 12 added support for OpenMP strictly structured blocks, from OpenMP 5.2 spec, page 3:

I think you’re correct. I submitted a bug report here and the first comment indicated that the two block code is valid in OpenMP 5.0 but not in 5.1. Your workaround was also suggested.

A somewhat confusing change.

Anyway, thanks again.