Fortran

Guide To Learn

Allocating the coarrays

To allocate the water height and velocity as coarrays over appropriate sections, we need to know their start and end indices on each image. Sounds familiar? We already did this in section 7.3 and exercise 1! All we have to do here is properly call that function and store the start and end indices in local variables. I called the function tile_indices, and you can find it both in the “Answer key” for Exercise 1 near the end of this chapter and in the tsunami repository in src/lib/mod_parallel.f 90.

The following listing provides the relevant section of src/app/tsunami.f 90 that calculates the start and end indices on each image and allocates the coarrays accordingly.

Listing 7.6 Allocating the coarrays with the correct start and end indices

integer(int32), parameter :: grid_size = 100     ❶
...
real(real32), allocatable :: h(:)[:], u(:)[:]    ❷
real(real32), allocatable :: gather(:)[:]        ❸
real(real32), allocatable :: hmean(:)
...
integer(int32) :: indices(2)                     ❹
integer(int32) :: is, ie                         ❺
integer(int32) :: ils, ile                       ❻
integer(int32) :: ims, ime                       ❼
...
indices = tile_indices(grid_size)                ❽
is = indices(1)                                  ❽
ie = indices(2)                                  ❽
 
tile_size = grid_size / num_images()
ils = 1                                          ❾
ile = tile_size                                  ❾
ims = ils - 1                                    ❿
ime = ile + 1                                    ❿
 
allocate(h(ims:ime)[*])                          ⓫
allocate(u(ims:ime)[*])                          ⓫
allocate(hmean(ims:ime))
 
allocate(gather(grid_size)[*])                   ⓫

❶ Global array size

❷ Declares water height and velocity as allocatable coarrays

❸ Will be used to gather and write water height data to screen

❹ Temporary array to store tile indices

❺ Global indices

❻ Local indices, excluding halo

❼ Local memory indices, including halo

❽ Calculates global indices

❾ Calculates local indices

❿ Calculates memory indices, including halo cells

⓫ Allocates water height and velocity over local memory indices

⓫ Allocates over full domain size

There’s an important distinction between local start and end indices ils and ile and memory indices ims and ime. The former are the indices over each image that will compute and update the solution at each step. The latter include the halo points and are the indices that each image must have in memory to do the computation over the ils:ile range. Let’s see how exactly that works out in the implementation of our main time loop.

Allocating the coarrays

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top