• Does OpenMP (5.1) Invalidate this code?

    From Ev. Drikos@21:1/5 to All on Tue Apr 26 14:53:53 2022
    Hello,

    Possibly I miss some details with a new OpenMP-5.1 feature.

    An OpenMP End Statement becomes optional if the opening statement
    of an OpenMP construct is followed by a block-construct. An example
    is given in the second program below which can be found at: https://www.openmp.org/wp-content/uploads/openmp-examples-5-2.pdf

    Does this new feature invalidate my code (the first program below),
    or the block I wrote isn't strictly structured, or what I miss here?

    Thanks in advance,
    Ev. Drikos


    ----------------------------------------------------
    $ cat my-code-4.5.f90 && gfc my-code-4.5.f90
    program main
    use omp_lib
    implicit none
    integer,parameter :: NT = 2, chunks=3

    !$omp parallel num_threads(NT)
    strictly_structured : block
    print *, "chunks=", chunks
    end block strictly_structured
    print *, NT
    !$omp end parallel
    end
    $
    ----------------------------------------------------


    macbook:examples-5.1 suser$ cat directive_syntax_F_block.2.f90
    program main

    use omp_lib
    implicit none

    !$omp parallel num_threads(2)
    if( omp_get_thread_num() == 0 ) &
    print*, "Loosely structured block -- end required."
    block ! BLOCK Fortran 2008
    if( omp_get_thread_num() == 0 ) &
    print*, " --"
    end block
    !$omp end parallel

    !$omp parallel num_threads(2)
    block
    if( omp_get_thread_num() == 0 ) &
    print*, "Strictly structured block -- end not required."
    end block
    !!$omp end parallel !is optional for strictly structured block

    print*, "Sequential part"

    !$omp parallel num_threads(2) !outer parallel
    if( omp_get_thread_num() == 0 ) &
    print*, "Outer, loosely structured block."
    !$omp parallel num_threads(2) !inner parallel
    block
    if( omp_get_thread_num()==0)&
    print*, "Inner, strictly structured block."
    end block
    !$omp end parallel
    !$omp end parallel

    ! Two end directives are required here.
    ! A single "!$omp end parallel" terminator will fail.
    ! 1st end directive is assumed to be for inner parallel construct.
    ! 2nd end directive applies to outer parallel construct.

    end program

    macbook:examples-5.1 suser$

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ev. Drikos@21:1/5 to Ev. Drikos on Fri Apr 29 07:33:13 2022
    On 26/04/2022 14:53, Ev. Drikos wrote:

    ...
    An OpenMP End Statement becomes optional if the opening statement
    of an OpenMP construct is followed by a block-construct. An example
    is given in the second program ...

    Does this new feature invalidate my code (the first program below),
    or the block I wrote isn't strictly structured, or what I miss here?
    ...

    Silence! Possibly, I've missed some details but I hope to eventually get
    the point, which shall normally be genius. On the hand, if older code is
    indeed invalidated, the chances are that such cases would be rare.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to Ev. Drikos on Thu Apr 28 21:59:44 2022
    On Thursday, April 28, 2022 at 9:33:20 PM UTC-7, Ev. Drikos wrote:

    (snip)

    Silence! Possibly, I've missed some details but I hope to eventually get
    the point, which shall normally be genius. On the hand, if older code is indeed invalidated, the chances are that such cases would be rare.

    OK, note that it says that some are optional.

    If an optional OpenMP END closes your block, then the actual
    END statement that you supply would be an error. It should
    diagnose that error, which would tell you that the block was
    already closed.

    It looks to me like the "strict" case is when the BLOCK directly
    follows the !$ OMP Parallel statement. Since your does, it
    looks to me that the block ends at the END BLOCK, and so has
    already ended before the !$ OMP END.

    In the case of nested blocks, there is an ambiguity with the
    optional END. If you put just one, it could be the real one following
    the omitted optional, or the actual optional one.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ev. Drikos@21:1/5 to All on Fri Apr 29 17:05:44 2022
    On 29/04/2022 07:59, gah4 wrote:
    ...

    If an optional OpenMP END closes your block, then the actual
    END statement that you supply would be an error...

    This is also what I'd understood, yet it's valid with older compilers,
    ie gfortran-4.8.5 (I think OMP-3.0 or so) accepts my example as valid.

    ...
    In the case of nested blocks, there is an ambiguity with the
    optional END. If you put just one, it could be the real one following
    the omitted optional, or the actual optional one.


    Thank you. I'd not yet reached that point. In this case there might
    be another issue with the END directives that contain arguments, ie:

    !$OMP END SINGLE [clause...] or
    !$OMP END WROKSHARE [NOWAIT]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)