From: fj on
On 15 déc, 15:07, alex-lurk <alex.l...(a)googlemail.com> wrote:
> On 13 Dez., 23:02, Tim Prince <tpri...(a)computer.org> wrote:
>
> > DO loops will not be parallelized without the OMP DO directive.
>
> Hi Tim,
>
> thanks for your hint.
> I thought using the PARALLEL directive alone is enough.

Usually no ! When a part of a code is located between !$OMP PARALLEL
and !$OMP END PARALLEL then this part is executed by each thread, the
number of threads being usually defined by the environment variable
OMP_NUM_THREADS.

It is possible to program with that technique in knowing the thread
index and the number of active threads ... but this is rather unusual.

> Now I have added the DO directive and it works.
> In the following you can find the source code (as example only the
> first section):
> ----------------------------------------
> ...
> ...
> ...
>       PRINT *, '***** 1. Section Start'

Sorry by this is not a section as defined in the OpenMP formalism . A
"!$OMP SECTIONS" opens a code part where each section defined inside
will be executed by its own thread.

Here this is simply an OpenMP DO loop which, in addition, has a
mistake : you must declare PRIVATE few variables :

!$OMP PARALLEL DO PRIVATE(J1,I1)
....
!$OMP END PARALLEL DO

In fact, there is a third private variable : K1 but OpenMP is able to
detect it. If you omit to declare J1 and I1 private, then the result
is unpredictable.

> !$OMP PARALLEL
> !$OMP DO
>       DO K1 = 1, O1
>         DO J1 = 1, N1
>           DO I1 = 1, M1
>             IF ((A1(I1,J1,K1).GT.0.0).AND.(A2(I1,J1,K1).GT.0.0)) THEN
>               A3(I1,J1,K1) = (SQRT((A1(I1,J1,K1)/A2(I1,J1,K1))))
>      1                     * (SQRT((A2(I1,J1,K1)/A1(I1,J1,K1))))
>             ELSE
>               A3(I1,J1,K1) = (SQRT((A1(I1,J1,K1)*A2(I1,J1,K1))))
>      1                     * (SQRT((A1(I1,J1,K1)*A2(I1,J1,K1))))
>             ENDIF
>           ENDDO
>         ENDDO
>       ENDDO
> !$OMP END DO
> !$OMP END PARALLEL
>       PRINT *, '***** 1. Section End'
> ...
> ...
> ...
> ----------------------------------------