0

I would like to ask whether openMP is capable of parallelizing fortran arrays with the same shape and size using simple notation. I did some research but I am not capable to find or figure out whether it is possible.

I refer as simple notation the following form:

a = b + c * 1.1

Find below a full example:

PROGRAM Parallel_Hello_World

USE OMP_LIB

implicit none

integer, parameter :: ILEN = 1000
integer :: a(ILEN,ILEN), b(ILEN,ILEN), c(ILEN,ILEN), d(ILEN,ILEN)
integer :: i, j

a = 1
b = 2

!$OMP PARALLEL SHARED(a, b, c, d)

    !$OMP DO
    DO i=1,ILEN
      DO j=1, ILEN
        c(j,i) = a(j,i) + b(j,i) * 1.1
      ENDDO
    END DO
    !$OMP END DO

    # is this loop parallel?
    d = a + b * 1.1

!$OMP END PARALLEL
write (*,*) "Total C: ", c(1:5, 1)
write (*,*) "Total D: ", d(1:5, 1)
write (*,*) "C same D? ", all(c == d)

END

Is the d loop parallelized with openMP with the current notation?

rgrun
  • 178
  • 3
  • 14
  • 1
    try `!$omp workshare` – Gilles Mar 31 '21 at 15:16
  • 1
    The assignment fro `d` is not executing in parallel the way you desire. Every thread is executing that assignment concurrently as each of the encounters the statement w/o a worksharing construct. So, Gilles is correct that you will need to wrap the statement in `!$omp workshare` construct. Because the `d` assignement does not depend on the earlier loop, you can also get rid of the barrier at the of the `do` construct, by using `!$omp end do nowait`. – Michael Klemm Mar 31 '21 at 15:32

1 Answers1

0

As commented by @Gilles the answer to the question is to wrap it with the workshare clause:

  !$OMP WORKSHARE
  d = a + b * 1.1
  !$OMP END WORKSHARE

Find more info here

rgrun
  • 178
  • 3
  • 14