|
All
|
program wave_mw
C Learn number of tasks and taskid
call initialize task
call get task identification and information
|
|
Manager
|
C Get program parameters
if (taskid .eq. MANAGER) then
read tpoints, nsteps
C Manager broadcasts total points, time steps
call send two numbers to all Workers
|
|
Workers
|
else
C Workers receive total points, time steps
call all Workers receive two numbers
end if
|
|
Manager
|
if (taskid .eq. MANAGER) then
do i = 1, tpoints
read(10) values(i)
end do
C Manager sends chunks to Workers
do i = 1, nproc-1
C Send first point and number of points handled to Worker
call send two numbers
C Send chunk of array to Worker
call send chunk of array
end do
|
|
Workers
|
else
C Receive first point and number of points
call receive two numbers
C Receive chunk of array
call receive chunk of array
end if
|
|
All
|
C Update values along the wave for nstep time steps
do t = 1, nsteps
C Send to left, receive from right
call send left endpoint to left neighbor
call receive left endpoint from right neighbor
C Send to right, receive from left
call send right endpoint to right neighbor
call receive right endpoint from left neighbor
C Update points along line
do i = 1, npoints
newval(i) = (2.0 * values(i)) - oldval(i) + & (sqtau * (values(i-1) - (2.0
* values(i)) + values(i+1)))
end do
end do
|
|
Manager
|
C Manager collects results from Workers and prints
if (taskid .eq. MANAGER) then
do i = 1, nproc - 1
C Receive first point and number of points
call receive two numbers
C Receive results
call receive chunk of results
C Write out results
write results(i)
|
|
Workers
|
else
C Send first point and number of points handled to Manager
call send two numbers
C Send results to Manager
call send results
end if
|
|
All
|
call terminate parallel environment
end
|