Fortran中多维数组的索引线性 [英] Linear Indexing of Multi-Dimension Arrays in Fortran
问题描述
设A是DIMENSION(M,N,P)的多维数组。是一个线性索引(使用一个索引)允许用Fortran?如果是这样,什么是线性指标和多维指数之间的对应关系?
Let A be a multi-dimensional array of DIMENSION(m,n,p). Is linear indexing of A (using a single index) allowed in Fortran? If so, what is correspondence between the linear index and the multi-dimensional index?
在换句话说,就是A(一)允许的,哪些元素做了(我)对应于(其中依次是尺寸遍历)?
In other words, is A(i) allowed, and which element does A(i) correspond to (in which order are the dimensions traversed)?
推荐答案
的http:// www.obliquity.com/computer/fortran/array.html 的解释数组存储在列为主的形式,从而使最左边的索引的最迅速的变化,其次是第二到最左边的等(这是C的对面,我相信)。它似乎很不明智的索引多维数组,就好像是一维的,但上面的链接页面说明,你的编译器将产生code,它就是这样做的(因此是非常快)的只要你嵌套你的循环以正确的顺序的
http://www.obliquity.com/computer/fortran/array.html explains that arrays are stored in "column-major" form, so that the left most index changes the most quickly, followed by the second to leftmost, etc. (this is the opposite of C, I believe). It seems quite unwise to try to index a multidimensional array as though it were one-dimensional, but as the above-linked page explains, your compiler will produce code that does just that (and is therefore very fast) as long as you nest your loops in the right order.
这篇关于Fortran中多维数组的索引线性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!