由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Fortran 90 中稀疏矩阵读取,什么样的数据结构实现最快
相关主题
问个c调用fortran函数的问题How to read binary(data) file generated by Fortran in C/C++ (转载)
C++ Q93 - Q95 (转载)如何在fortran中定义一个动态的数组?
请问:稀疏矩阵运算有什么好的C++库?[合集] C help(urgent)!!! thanks a lot!!
sparse linear Ax = b , 有什么好办法解 x ?[合集] 弱问:C++ 里的Vector在Java里用什么替代比较好?
Matlab中,如何沿着某个方向读取二维矩阵中的数据Why do I need to use "plain" pointer?
数据存储的问题一个简单的小问题
C 语言,初学者问题(4),读取字符指针内容请问可以这样定义struct吗?
what does this mean? how to do it ?=======Problem – coding in c++
相关话题的讨论汇总
话题: pointer话题: type话题: 矩阵话题: 读取话题: integer
进入Programming版参与讨论
1 (共1页)
s******u
发帖数: 179
1
在fortran 90中,我将一个稀疏矩阵存成下面的数据格式:
TYPE:: rsm !Real sparse matrix
integer:: numbers !number of nonzero value in the matrix
integer,dimension(:),pointer::rows
integer,dimension(:),pointer::columns
real ,dimension(:),pointer::values
END TYPE rsm
然后用指针读取这个矩阵
TYPE:: rsmptr
type(rsm),pointer::p
END TYPE rsmptr
每次读取都是从第一个到后一个顺序读取。后面的程序中要对这个矩阵多次重复的读取(且是在内存中)
,这样的存法,读取的效率不怎么高。我也试过把一个矩阵中的元素存成一个node的数
据结构:
type:: node
integer :: rows
integer
O******e
发帖数: 734
2
The meaning of the terminology "pointer" is different
in Fortran 9x and C.
In C, a pointer refers directly to an address.
In F9x, a pointer is actually a complicated data structure.
This is the essence of your problem--misuse of the F9x "pointer".
Before I get into all the details, how well do you understand the
following F9x concepts:
1. array subsection
2. copy-in and copy-out of actual array arguments
3. argument passing by reference in F9x, or passing by pointer in C

【在 s******u 的大作中提到】
: 在fortran 90中,我将一个稀疏矩阵存成下面的数据格式:
: TYPE:: rsm !Real sparse matrix
: integer:: numbers !number of nonzero value in the matrix
: integer,dimension(:),pointer::rows
: integer,dimension(:),pointer::columns
: real ,dimension(:),pointer::values
: END TYPE rsm
: 然后用指针读取这个矩阵
: TYPE:: rsmptr
: type(rsm),pointer::p

l**t
发帖数: 64
3
直接定义三个数组不就行了,把lenght设大点,怕浪费就每次改成numbers大小
搞计算的都很直接,一般不会搞像你这样的复杂数据结构
integer numbers
integer rows(LENGTH)
integer cols(LENGTH)
real value(LENGTH)

【在 s******u 的大作中提到】
: 在fortran 90中,我将一个稀疏矩阵存成下面的数据格式:
: TYPE:: rsm !Real sparse matrix
: integer:: numbers !number of nonzero value in the matrix
: integer,dimension(:),pointer::rows
: integer,dimension(:),pointer::columns
: real ,dimension(:),pointer::values
: END TYPE rsm
: 然后用指针读取这个矩阵
: TYPE:: rsmptr
: type(rsm),pointer::p

s******u
发帖数: 179
4
谢谢你的回复。对指针,无论是C里的还是fortran里的,我想最少有一点是相通的,用
指针赋值要比直接传值快,这就是我在我的fortran程序里大量使用指针的原因,因为
我要频繁把这些值取出来操作。在我测试的时候发现,把这些值取出花费了比我想象得
多得多的时间。
至于您提到的三个问题,第一个array subsection是指对大矩阵的一部分进行操作么?
在fortran中,指针能令对部分矩阵元素操作更便捷,比如定义一个指针数组,指向某
一个大矩阵的部分元素,那么对这个指针数组的操作要比对原矩阵操作更有效和快速。
第二个问题,矩阵赋值,用指针也能够比直接赋值要快吧,毕竟只需要把地址传过去就
行了。
第三个问题,我对c没怎么深究过,不清楚具体怎么回事。但是fortran中好像不能对地
址进行操作,在fortran中得不到一个数组的地址,我也想过把这些数据存在一个连续
空间中,然后安地址一个一个往后读,但是不知道怎么在fortran中得到这个数据的地
址。
谢谢您的回复,感激涕零.

【在 O******e 的大作中提到】
: The meaning of the terminology "pointer" is different
: in Fortran 9x and C.
: In C, a pointer refers directly to an address.
: In F9x, a pointer is actually a complicated data structure.
: This is the essence of your problem--misuse of the F9x "pointer".
: Before I get into all the details, how well do you understand the
: following F9x concepts:
: 1. array subsection
: 2. copy-in and copy-out of actual array arguments
: 3. argument passing by reference in F9x, or passing by pointer in C

s******u
发帖数: 179
5
您这种方法我要试一试,由于是在原有程序上修改的,原先这么定义,我也就接着这么
用,以为这样更快捷。谢谢,我会试一试。

【在 l**t 的大作中提到】
: 直接定义三个数组不就行了,把lenght设大点,怕浪费就每次改成numbers大小
: 搞计算的都很直接,一般不会搞像你这样的复杂数据结构
: integer numbers
: integer rows(LENGTH)
: integer cols(LENGTH)
: real value(LENGTH)

b****p
发帖数: 10
6
There are lots of different storage formats for the sparse matrix. I
know there is a package called SPARSKIT. Although you do not necessarily
use the package, at least you should take a look before you develop your
own data structure. Basically you should work more on the index array
but not simply use row and column ID as the index.

【在 s******u 的大作中提到】
: 在fortran 90中,我将一个稀疏矩阵存成下面的数据格式:
: TYPE:: rsm !Real sparse matrix
: integer:: numbers !number of nonzero value in the matrix
: integer,dimension(:),pointer::rows
: integer,dimension(:),pointer::columns
: real ,dimension(:),pointer::values
: END TYPE rsm
: 然后用指针读取这个矩阵
: TYPE:: rsmptr
: type(rsm),pointer::p

1 (共1页)
进入Programming版参与讨论
相关主题
how to do it ?=======Problem – coding in c++Matlab中,如何沿着某个方向读取二维矩阵中的数据
is smart_ptr really that good?数据存储的问题
[合集] pointer in CC 语言,初学者问题(4),读取字符指针内容
pointer overflowwhat does this mean?
问个c调用fortran函数的问题How to read binary(data) file generated by Fortran in C/C++ (转载)
C++ Q93 - Q95 (转载)如何在fortran中定义一个动态的数组?
请问:稀疏矩阵运算有什么好的C++库?[合集] C help(urgent)!!! thanks a lot!!
sparse linear Ax = b , 有什么好办法解 x ?[合集] 弱问:C++ 里的Vector在Java里用什么替代比较好?
相关话题的讨论汇总
话题: pointer话题: type话题: 矩阵话题: 读取话题: integer