Scientific Programming / 2015 / Article / Lst 8

Research Article

High-Performance Design Patterns for Modern Fortran

Listing 8

function df_dx(this)
  class(tensor), intent(in):: this
  type(local_tensor):: df_dx
  integer:: i, nx, me, east, west
  real:: dx
  real:: local_tensor_data(local_grid_size)
    nx = local_grid_size
    dx = 2. pi/(real(nx)   num_images())
    me = this_image()
    if (me == 1) then
      west = num_images()
      east = merge(1, 2, num_images() == 1)
    else if (me == num_images()) then
      west = me − 1
      east = 1
    else
      west = me − 1
      east = me + 1
    end if
    local_tensor_data() = 0.5 (this%global_f() − this%global_f(nx)[west])/dx
    local_tensor_data(nx) = 0.5 (this%global_f()[east] − this%global_f(nx – 1))/dx
    do concurrent(i = 2 : nx − 1)
      local_tensor_data(i) = 0.5 (this%global_f(i + 1) − this%global_f(i − 1))/dx
    end do
    df_dx = local_tensor_data
end function

We are committed to sharing findings related to COVID-19 as quickly as possible. We will be providing unlimited waivers of publication charges for accepted research articles as well as case reports and case series related to COVID-19. Review articles are excluded from this waiver policy. Sign up here as a reviewer to help fast-track new submissions.