concept image in category fortran

appears as: image, images, images, n image, image
Modern Fortran: Building efficient parallel applications

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

Listing 1.1. Example data exchange between parallel images. Each image executes the same program; however, not all images will execute all segments of the program.
language="fortran" linenumbering="unnumbered">program hello_coarrays

  implicit none

  integer :: a[*] #1
  integer :: i

  a = this_image() #2

  if (this_image() == 1) then #3
    do i = 1, num_images() #4
      print *, 'Value on image', i, 'is', a[i] #5
    end do
  end if

end program hello_coarrays
Figure  7.5. The flow of the serial weather_stats program. “Image 1” here refers to a single serial core or CPU.
ch07 buoys serial

So far, we’ve used this_image and num_images to instruct each image to tell us who they are and how many total images there are. This is useful information, but we still haven’t done anything with it yet. How can we use this information to split the weather buoy data between images? Recall from listing 7.1 that we define the list of data files by specifying the array of buoy IDs:

ids = ['42001', '42002', '42003', '42020', '42035',&
  '42036', '42039', '42040', '42055']

To break down the data, we need to split this array into nearly equal pieces and assign each piece to an image. For example, if we work with two images, image 1 should have ids = ['42001', '42002', '42003', '42020', '42035'], and image 2 should have ids = ['42036', '42039', '42040', '42055']. For three images, each should have three buoy IDs total. You get the idea.

Looking back at figure 7.9, it’s obvious who the neighbors are for each image. For image 1, the left and right neighbors are images 3 and 2, respectively. For image 2, they’re images 1 and 3. And for image 3, they’re images 2 and 1. Let’s generalize this rule so that it works for any number of images. Try to implement it as an external function! It’s a necessary ingredient for getting the parallel tsunami simulator to work, so you can also skip ahead and use it out of the box. I defined it in the mod_parallel module in src/ch07/mod_parallel.f90.