查找FORTRAN阵列位置,4维阵列 [英] Finding FORTRAN array location, 4-dimensional array

查看:194
本文介绍了查找FORTRAN阵列位置,4维阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我有一个问题。
如果在FORTRAN中给出了一个四维数组,并且被告知找到它的某个部分的位置(起始位置为200,每个整数4个字节)。如果以行主要和列主要的顺序存储,是否有公式来查找位置?



基本给出的数组A(x:X,y:Y,z:Z,q:q)并告诉我们在A(a,b,c, d)寻找位置的公式是什么

解决方案

,调用MPI例程尝试发送特定的Fortran阵列子集。



Fortran是 row-major,或更有用,第一个索引移动速度最快。也就是说,A(1,2,3,4)在内存中的线性顺序之后的项是A(2,2,3,4)。所以在你上面的例子中,增加一个就是在数组中跳转1个索引; b跳过1对应于(X-x + 1)的跳跃; (x-x + 1)x(y-y + 1)的跳跃,并且d中的跳跃为1是(X-x + 1)x(Y-y 1)×(Z-Z + 1)。在基于C的语言中,情况恰恰相反;在d索引中跳转1会使您在内存中移动1个索引;如果你有m个指标,并且n i ,那么在c中的跳跃将是(Q-q + 1)是从左边开始的第i个索引中的(从零开始的)索引,并且该索引具有N i 的范围,则来自(从零开始的)索引起始位置是这样的:





如果上面的索引小于下面的索引,那么产品为1。要从数组的开头找到字节数,可以将其乘以对象的大小,例如32位整数的4个字节。


Hey guys, I have a question. If given a four dimensional array in FORTRAN, and told to find a location of a certain part of it (with a starting location of 200 and 4 bytes per integer). Is there a formula to find the location if is stored in row-major and column-major order.

Basiically given array A(x:X, y:Y, z:Z, q:q) and told to find the location at A(a,b,c,d) what is the formula for finding the location

解决方案

This comes up all the time when using C libraries with Fortran -- eg, calling MPI routines trying to send particular subsets of Fortran arrays.

Fortran is row-major, or more usefully, the first index moves fastest. That is, the item after A(1,2,3,4) in linear order in memory is A(2,2,3,4). So in your example above, an increase in a by one is a jump of 1 index in the array; a jump in b by one corresponds to a jump of (X-x+1); a jump in c by one corresponds to a jump of (X-x+1)x(Y-y+1), and a jump in d by one is a jump of (X-x+1)x(Y-y+1)x(Z-z+1). In C-based languages, it would be just the opposite; a jump of 1 in the d index would move you 1 index in memory; a jump in c would be a jump of (Q-q+1), etc.

If you have m indicies, and ni is the (zero-based) index in the ith index from the left, and that index has a range of Ni, then the (zero-based) index from the starting position is something like this:

where the product is 1 if the upper index is less than the lower index. To find the number of bytes from the start of the array, you'd multiply that by the size of the object, eg 4 bytes for 32-bit integers.

这篇关于查找FORTRAN阵列位置,4维阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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