Fortran意图(inout)是否传递值的副本或指向RAM地址的指针/引用? [英] Does Fortran intent(inout) pass a copy of the value, or pointer/reference to RAM address?

查看:335
本文介绍了Fortran意图(inout)是否传递值的副本或指向RAM地址的指针/引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为标题状态,我希望知道Fortran intent(inout)传递值的副本,还是指向RAM地址的指针?我需要知道的原因是我需要传递一个(相对)大的数据矩阵。如果它创建一个会导致我问题的本地副本。谢谢!

解决方案

Fortran并未详细说明如何传递函数和子例程参数,但它确实需要如果一个过程修改一个 intent(out) intent(inout)参数,然后这些修改在调用程序之后可以看到回报。编译器通过引用参数来实现这个要求是很常见的,但这不是唯一的可能 - 复制/复制是主要选择。



你通常可以依靠编译器来实现最快的行为,它可以确定是正确的,这通常是通过引用。然而,有些情况下无法工作,例如将非连续的数组部分传递给假定大小的伪参数,并且有时候复制/复制速度更快的情况(可能在某些大型多处理器系统上分段内存架构)。

最重要的是,尽管你提出了一个很好的问题,但没有一个普遍的答案。通常情况下,您最好先让它工作,然后在需要时加快速度。将数组复制问题保留在脑后,但不要过多担心,直到您能够进行测试。


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!

解决方案

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.

这篇关于Fortran意图(inout)是否传递值的副本或指向RAM地址的指针/引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆