Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Fortran intent(inout) pass a copy of the value, or pointer/reference to RAM address?

As title states I wish to know does Fortran intent(inout) pass a copy of the value, or a pointer/reference to RAM address? The reason I need to know this is I need to pass a (relatively) big data matrix. If it creates a local copy that would cause me problems. Thank you!

like image 338
Jason Lee Avatar asked Mar 18 '23 17:03

Jason Lee


1 Answers

Fortran does not specify details of how function and subroutine arguments are passed, but it does require that if a procedure modifies an intent(out) or intent(inout) argument then the changes will be visible to the caller after the procedure returns. It is common for compilers to implement this requirement by passing arguments by reference, but that is not the only possibility -- copy in / copy out is the main alternative.

You can normally rely on the compiler to implement the fastest behavior it can be certain is correct, which is usually pass by reference. There are cases where that cannot work, however, such as passing a non-contiguous array section to an assumed-size dummy argument, and there are sometimes cases where copy-in / copy-out is faster (maybe on certain large multiprocessor systems with segmented memory architectures).

The bottom line is that although you pose a good question, there is no general answer. As is often the case, you are best off to make it work first, and then make it faster if needed. Keep the array-copying question in the back of your head, but don't worry too much about it until you are in a position to test.

like image 178
John Bollinger Avatar answered Apr 25 '23 18:04

John Bollinger