Synchronization (theory) A barrier is a synchronization statement that forces ev
ID: 3764139 • Letter: S
Question
Synchronization (theory)
A barrier is a synchronization statement that forces every one of a group of processes that executes the statement to wait until they know that all other processes in the group have reached the barrier. Barrier statements are sometimes, but not always, provided in hardware. Describe an algorithm that uses point to point messages (such as the M function in problem 2) to implement a barrier. How does your algorithm scale with numberof processes N? (That is, how does the time it takes increase as a function of N). Justify your answer.
Explanation / Answer
Given are the algorithm that uses point to point messages-
!$OMP END DO
use NOWAIT because there will be another barrier
!$OMP END SINGLE
use NOWAIT because there is a barrier at the END SINGLE at the beginning
!$OMP END SINGLE
To ensure THAT a(i, j) is completely generated AND updated before using
!$OMP END DO NOWAIT
The explicit !$OMP BARRIER before the SINGLE section ensures correctness
!$OMP END SINGLE
Need to NOWAIT because no thread may check msing until it is set inside the SINGLE construct.
!$OMP END DO
!$OMP END SINGLE
!$OMP END DO NOWAIT
If the particle simulation is run on a system with more than n processors, it would be beneficial to combine the i and j loops because through looping it will make easy to obtain O(n2 ) in parallel work. By restructuring the code and introducing the appropriate directives algorithm scale with number of processes N. Hence the scale algorithm is :
pt = 0.0
kn = 0.0
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(i, k, m)
do m = 1, 3*n
i = (m - 1)/3 + 1
j = modulo(m-1, 3) + 1
f(k, i) = 0.0
end do
!$OMP END PARALLEL DO
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(i, j, k, m, rij, d) &
!$OMP& REDUCTION(+: pt)
do m = 1, n*n
i = (m - 1)/n + 1
j = modulo(m-1, n) + 1
if (i .ne. j) then
call dist(p(1, i), p(1, j), rij, d)
pt = pt + 0.5*v(d)
k = 1, 3
f(k, i) = f(k, i) - rij(k)*dv(d)/d
end do
end if
end do
!$OMP END PARALLEL DO
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(i) REDUCTION(+: kn)
do i = 1, n
kn = kn + dot(v(1, i), v(1, i))
end do
!$OMP END PARALLEL DO
kn = kn*0.5*mass
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.