concept parallel tsunami simulator in category fortran

appears as: parallel tsunami simulator
Modern Fortran: Building efficient parallel applications

This is an excerpt from Manning's book Modern Fortran: Building efficient parallel applications.

If you got the exercise right, great! Otherwise, no worries, you can take a look at my implementation in the “Answer key” section near the end of the chapter. This function is also a necessary ingredient for the parallel tsunami simulator, so we’ll reuse it there. Right now, let’s see how we can use it to distribute the buoy data between images, as the following listing demonstrates.

Listing 7.7. The main time loop of the parallel tsunami simulator
language="fortran" linenumbering="unnumbered">time_loop: do n = 1, num_time_steps

  h(ime)[left] = h(ils)  #1
  h(ims)[right] = h(ile) #1
  sync all               #2

  u = u - (u * diff(u) + g * diff(h)) / dx * dt #3

  sync all #4

  u(ime)[left] = u(ils)  #5
  u(ims)[right] = u(ile) #5
  sync all               #6

  h = h - diff(u * (hmean + h)) / dx * dt #7

  gather(is:ie)[1] = h(ils:ile) #8
  sync all                      #8
  if (this_image() == 1) print *, n, gather #8
end do time_loop