Research Article

High-Performance Design Patterns for Modern Fortran

Listing 6

pure function add(lhs, rhs) result(total)
class(local_tensor), intent(in):: lhs, rhs
type(local_tensor):: total
 total%f = 1hs%f + rhs%f
end function
pure subroutine assign_local(lhs, rhs)
class(local_tensor), intent(inout):: lhs
real, intent(in):: rhs(:)
 lhs%f = rhs
end subroutine
pure function state(this) result(my_data)
class(local_tensor), intent(in):: this
real:: my_data(local_grid_size)
 my_data = this%f
end function
pure function subtract(lhs, rhs) &
result(difference)
class(local_tensor), intent(in):: lhs, rhs
type(local_tensor):: difference
 difference%f = 1hs%f − rhs%f
end function