I have a performance-critical peice of code that currently sits in a nested loop, e.g.:
do kk=1,k_max do jj=1,j_max do ii=1,i_max function_with_11_inputs_4_outputs enddo enddo enddo
For readability, I'd like this to appear in a separate subroutine. (This gets rid of all of the array indices and makes things look much cleaner.) Assuming that I do this, to achieve maximum performance, do I need to create a subroutine with 15 arguments and only operate on the direct inputs and outputs? Or, can I do something like the following and count on the compiler to get rid of the intermediate steps?
real :: inputs(11), outputs(4) do kk=1,k_max do jj=1,j_max do ii=1,i_max inputs(1) = varA inputs(2) = varB inputs(3) = varC ... function(inputs, outputs) varX = outputs(1) varY = outputs(2) varZ = outputs(3) ... enddo enddo enddo
(Presumably, there would be a similar translation inside the function, itself.) Alternatively, is there any other "cleaner" way to efficiently pass a lot of arguments to a subroutine and still achieve maximum performance?