Fortran

Guide To Learn

Type-bound methods for the Field type

It’s now a good time to start planning for the type-bound methods for our Field type, as shown in the following listing.

Listing 8.7 Type-bound components to be defined for the Field type

type :: Field
  ...
contains
  procedure, pass(self) :: gather              ❶
  procedure, pass(self) :: init_gaussian       ❷
  procedure, pass(self) :: sync_edges          ❸
  procedure, pass(self) :: write               ❹
end type Field

❶ Gathers data on one image

❷ Initializes a bell-shaped blob

❸ Synchronizes data between tiles

❹ Writes data to file

Each of the methods in listing 8.7 has a specific purpose. Recall that in the previous version of the tsunami simulator, we were carrying each of these operations explicitly in the main program. In the derived type approach, these tasks can be defined inside the type-bound methods and invoked when needed, analogous to the setup tasks that we carried out in the custom Field constructor. Specifically, here’s what each of the methods does:

  • gather–Applies the gather parallel pattern to make the whole array (across all parallel images) available on a single image. We already explored this pattern in chapter 7 when we gathered the whole weather buoy time series array on a single image to find the maximum value. In the tsunami simulator, we’ll use this method prior to writing data to a file.
  • init_gaussian–Sets the values of Field % data to a bell-shaped gaussian blob centered at a desired index pair.
  • sync_edges–Updates the outer edges of Field % data to be in sync with the values on neighboring tiles.
  • write–Writes the data values into a file.

For brevity, I won’t go into the implementation details of each of these methods here. However, I encourage you to explore the code and study how they work. These methods are defined in tsunami/src/ch08/mod_field.f 90.

Finally, in the next subsection, we’ll look into access control for type components and methods.

Type-bound methods for the Field type

Leave a Reply

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

Scroll to top