I encountered the following situation when using the optional Fortran attribute for the intended array of forms and trying to find the best (in terms of performance) solution. I would be very happy if someone could give me a good hint. Please note that I am interested in every performance increase I can get, since my arrays are large, and the number of loops and their loops are even greater.
I have a situation where the calculation is performed either using an optional argument, or if it is absent, it uses another array in its place.
subroutine compute(tmat,av,av2)
implicit none
complex,intent(out) :: tmat(:)
complex,intent(in) :: av(:)
complex,intent(in),optional :: av2(:)
if(present(av2)) then
tmat = av *av2
else
tmat = av *av
end if
end subroutine compute_transition_matrices_bosonic
. , .
, ( ), .
:
if(present(av2)) then
tmat = "function"(av,av2)
else
tmat = "function"(av,av)
end if
"" (, ""). ,
if, . , av2
, , () .
, . -,
complex, :: phi_tmp(:)
if(present(av2)) then
phi_tmp = av2
else
phi_tmp = av
end if
tmat = "function"(av,phi_tmp)
. COPY , .
complex,intent(in),target :: av(:)
complex,intent(in),optional,target :: av2(:)
complex,pointer :: phi_tmp(:)
if(present(av2)) then
phi_tmp => av2
else
phi_tmp => av
end if
tmat = "function"(av,phi_tmp)
TARGET av av2. , ,
, av av2 , INTENT(IN)
. , , , ,
TARGET? ( !)
- ?
"" ? ( )
?