Suppose that I have a subroutine that revises arrays
B by some intensive computation:
subroutine foo(A, B) real, intent(inout) :: A(:, :), B(:, :) ! Do something intensive to revise A, B end subroutine foo
Now, I would like to define a derived type
DT consisting of
B and rewrite
bar as follows.
subroutine bar(D) type(DT), intent(inout) :: D ! Do something intensive to revise D%A, D%B end subroutine bar
Here comes a problem. The calculation that revises
B is truly intensive. So it would be cumbersome to write always
D%B. To solve this problem, we may define temporary arrays
B=D%B, work on
B, and then set
D%B=B before the end of the subroutine. However, if
B are huge, this would not be ideal. So, what is the best practice in this situation?