[Omp] On the implicit barrier
Greg Bronevetsky
greg at bronevetsky.com
Sun Mar 18 11:48:58 PDT 2007
Probably the simplest way would be to use the no_wait directive. It
removes the implicit barrier at the end of the loop. You can then compare
the running time of the original loop vs the one without the implicit
barrier. Note that in the barrier-free version we have to measure the
running time of each thread individually and add a do-nothing loop after
the parallel do to make sure that all threads are done executing before
we move on to the second do loop. As such your code will become (forgive
any Fortran mistakes):
!$omp parallel
startTime[omp_get_thread_num()] = time()
!$omp do default(shared) private(i,j,k)
do k = 1, d3
do j = 1, d2
do i = 1, d1
u1(i,j,k) = u0(i,j,k)*ex(t*indexmap(i,j,k))
end do
end do
end do nowait
end timing
endTime[omp_get_thread_num()] = time()
do q = 1, 10000000000
end do
!$omp barrier
compute average of elapsed times
startTime = time()
!$omp do default(shared) private(i,j,k)
do k = 1, d3
do j = 1, d2
do i = 1, d1
u1(i,j,k) = u0(i,j,k)*ex(t*indexmap(i,j,k))
end do
end do
end do
endTime = time()
elapsed time = endTime-startTime
!$omp end parallel
return
end
Greg Bronevetsky
On Sun, 18 Mar 2007, Eugene Loh wrote:
> Shengyan Hong wrote:
>
> >Every Openmp member,
> > In the parallel loop of Fortran, there is an implicit barrier.
> > !$omp parallel do default(shared) private(i,j,k)
> > do k = 1, d3
> > do j = 1, d2
> > do i = 1, d1
> > u1(i,j,k) = u0(i,j,k)*ex(t*indexmap(i,j,k))
> > end do
> > end do
> > end do
> >
> > return
> > end
> >
> > How can I test the idle time in the implicit barrier?
> >
> >
> It depends on what tools you have available. For example, with the Sun
> Studio software suite, you can use the Sun Performance Analyzer. Set
> the environment variable "SUNW_MP_THR_IDLE" to "SPIN" before you execute
> your program. Then execute the program and look at the performance
> profile. You should see "<OMP-implicit_barrier>" time. Specifically,
> you can see the breakdown of this implicit-barrier time by loop and by
> thread. Alternatively, the time-line viewer will give you a graphical
> picture of all this. You can write me off-line if you'd like some help
> with this.
>
> If you want to insert some timers or other instrumentation into the
> source code, I guess you have to insert them right before and after that
> last "END DO" statement. I forget: did you have one thread per "DO
> K=1,D3" iteration? If so, I think you could capture one timestamp per
> "K" iteration right before the last "END DO" statement and one timestamp
> for all threads right after that "END DO".
>
> On Mar 12, Henry Jin showed another way in this email thread of
> capturing barrier time by converting the implicit barrier to an explicit
> one.
> _______________________________________________
> Omp mailing list
> Omp at openmp.org
> http://openmp.org/mailman/listinfo/omp
>
More information about the Omp
mailing list