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
|
|