tiki
tiki

Reputation: 429

openmp barrier not allowed inside do loop

I have a following type of openmp do loop in fortran:

!$OMP PARALLEL PRIVATE(i,j) DEFAULT(SHARED)
!$OMP DO
      do i=1,5
         do j=1,5
            A(i,j)=i+j
         enddo
!$OMP BARRIER
      enddo
!$OMP END DO
!$OMP END PARALLEL

I am getting illegal context for barrier error... Is there any other way of putting some sort of barrier at the end of inner do loop? Thanks.

Upvotes: 0

Views: 296

Answers (1)

What are you trying to achieve? Putting barrier there, if it was allowed would mean you want all threads stop and wait for each other at the and of the iteration. What would you like to happen if you have smaller number of threads, than 5? Wouldn't it be necessarily a deadlock?

What you could do is to parallelize just the inner loop, you would get an implied barrier there then. Or you could use the ordered clause to force some important part of the iteration to be executed in the right order according to the order of the indexing.

Maybe your real case is more complex and has a different structure, but you have to post the real problem then. In your example there is no sense in a barrier there.

Upvotes: 3

Related Questions