Fortran Coder

查看: 9767|回复: 8
打印 上一主题 下一主题

[数值问题] 存储矩阵的非零元素的问题

[复制链接]

130

帖子

10

主题

0

精华

大师

F 币
617 元
贡献
372 点

贡献勋章管理勋章帅哥勋章元老勋章星光勋章规矩勋章

楼主
发表于 2017-8-16 12:59:37 | 显示全部楼层
"困难户"row-major, ""vvt"column-major

130

帖子

10

主题

0

精华

大师

F 币
617 元
贡献
372 点

贡献勋章管理勋章帅哥勋章元老勋章星光勋章规矩勋章

沙发
发表于 2017-8-16 21:12:09 | 显示全部楼层
li913 发表于 2017-8-16 11:29
1、实数不用 相等 或 不等 来判断;
2、代码完全混乱。

Hi, li913

看到你 Allocation: Fortran 2003 Enhancements 的"SOURCE"語法
ALLOCATE( na, SOURCE=PACK(ma,ma/=0) )

巧妙的避開assignment之前, 要先allocate的困擾
ALLOCATE( na(?) ) ! unknown size
na = PACK(ma,ma/=0)

F2003也支援"Automatic Reallocation"的語法
(F95, for omponents only, deep copy的extension)
i.e., 之前的 "ALLOCATE( na(?) )"都可免了

INTEGER, ALLOCATABLE :: a(:)
a = [(i,i=1,10)] ! ALLOCATE(a(10)) automatically
a = [(i,i=1,100)] ! deallocate-and-then-reallocate automatically

------------------------------------

跟你請教一下:
我是挺杞人憂天的, 這樣flixible的背後會隱藏多少"人"的logical errors

same shape (rank及extent都要相同), 方可進行array assignment, 安全性很高
如今, 對於allocatable array做assignment, extent不同就自動deallocate/reallocate

這有極大的機會非程式員的本意
程式員很可能只是不小心把"extent"coding錯了, 沒有要reallocate的意思

這樣的誤會, 是不容易檢查出來的, 你會這麼擔心嗎?

130

帖子

10

主题

0

精华

大师

F 币
617 元
贡献
372 点

贡献勋章管理勋章帅哥勋章元老勋章星光勋章规矩勋章

板凳
发表于 2017-8-17 13:42:32 | 显示全部楼层
蒐了一下:

to disables this automatic (re-)allocation
/nostandard-realloc-lhs, by Intel
-fno-realloc-lhs, by GNU
PGI/NAG有嗎?

One can always suppress the (re-)allocation checks/actions of an array in modern code by using an array section
array(:) = ...
array(:,:) = ...
In this case, array (if allocatable) must be allocated
這主意 似乎不錯!

F90允許zero-sized array, 我疑神疑鬼了好多年 好像沒受害過, 可有經驗?
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-15 19:10

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表