yingfashi 发表于 2012-9-16 13:17:28

feapv 程序 就是R.LTaylor写的那个,数组内存管理问题


feapv数组内存管理没懂,明白的指教下,下面文字来自feapv开发手册上的。

integer num_nps , num_ups
parameter (num_nps = 400 , num_ups = 200)
integer np , up
common /pointer/ np(num_nps) , up(num_ups)

Each pointer is an offset relative to the address of a REAL*8 array hr(1) or an INTEGER

array mr(1) defined in a blank common
real*8 hr
integer mr
common hr(1),mr(1)

说是hr,mr,记录地址的偏移,感觉他是把所有的数组写在一个内存空白区域hr(real*8),mr(integer),然后记录每个生成数组在空白区域的位置,并且用字典把数组名来记录下来。
他还举了个得到节点坐标的数组的例子
For example, if a development requires the nodal coordinate
data the call
integer xpoint, xlen, xpre
logical flag
....
call pgetd ('X ',xpoint,xlen,xpre,flag)
x1 = hr(xpoint)
For example y1 is located at hr(xpoint+1)
这么看来hr存的是具体的内容,而非地址。
但他在头文件中把hr,mr大小定义好了,都是1,hr(xpoint+1)岂不是会数组越界..


penultimate 发表于 2012-9-16 13:59:34

必须是哑元/公用区传递
hr(1)中的1只起了个hr定义为数组的作用
这事fortran中传递数组指针的经典方法

penultimate 发表于 2012-9-16 14:01:19

好处是:一次申请一块大的内存,然后分区使用
这种方法利用内存的效率最高,
高效利用内存是fortran提高计算速度的关键

yingfashi 发表于 2012-9-16 14:47:56

本帖最后由 yingfashi 于 2012-9-16 15:08 编辑

penultimate 发表于 2012-9-16 13:59 static/image/common/back.gif
必须是哑元/公用区传递
hr(1)中的1只起了个hr定义为数组的作用
这事fortran中传递数组指针的经典方法 ...
他的开发手册上说,The arrays 'hr' and 'mr' are used to establish addresses only and not to physically store
data. 可我怎么觉得hr就是一大块空白内存还有个问题是他在头文件中声明了 hr(1),在实际中如何修改hr大小,这些都是fortran77的,现在书都没讲这些,讲的是allocateble,module可以代换吧

penultimate 发表于 2012-9-17 10:14:45

hr是一段指定内存区域的起始位置,也就是指针
大小通过使用时给他预留的空间决定,不需要分配
注意,这段区域是一次性分配一块大内存中的一部分/或全部,用ALLOCATE
仔细看一下使用数组时,内存片段大小布局的代码片段,应该不难搞清楚

pasuka 发表于 2012-9-17 16:31:12

yingfashi 发表于 2012-9-16 14:47 static/image/common/back.gif
他的开发手册上说,The arrays 'hr' and 'mr' are used to establish addresses only and not to physical ...

这类F77的common块古老语法能够看懂就行,没特殊情况就别深入研究
真要搞数值计算要么一步到位C/C++,要么过渡到F90/95、F03

zhangsen 发表于 2013-12-10 11:48:16

楼主我也觉得有你说的这个问题现在看了feap两个多月 能交流一下吗
页: [1]
查看完整版本: feapv 程序 就是R.LTaylor写的那个,数组内存管理问题