Research Article
High-Performance Design Patterns for Modern Fortran
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 |
|