- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am quite new to fortran and have some simple questions regarding fortran pointer. The code piece is shown below:
- subroutine pointer_test(p_in)
- Implicit None
- !…Incoming varibale
- real(kind=8), pointer :: p_in
- !…Local variable
- real(kind=8), pointer :: p_local(:,:,:)
- p_local => p_in
- end subroutine
My questions are:
If p_in points to a 3D-array of size 10*20*30, does p_in contain only one (the initial) address of the 3D-array or 6000 addresses for all the floating point numbers?
What's the data movement in p_local => p_in (line 10) ? I am just moving one address from p_in into p_local or I am moving 6000 addresses?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The code you show is not legal and won't compile. You can't point a rank-3 pointer to a rank-1 array. But in general, pointer assignment at most moves one address and some other "descriptor" information - it doesn't move data. Even in a multidimensional array case, it moves the address and bounds, not data.
There are other ways to get this sort of rank remapping - are you sure you need to pass pointers around? In modern Fortran, pointers have very limited applicability.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The code you show is not legal and won't compile. You can't point a rank-3 pointer to a rank-1 array. But in general, pointer assignment at most moves one address and some other "descriptor" information - it doesn't move data. Even in a multidimensional array case, it moves the address and bounds, not data.
There are other ways to get this sort of rank remapping - are you sure you need to pass pointers around? In modern Fortran, pointers have very limited applicability.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve Lionel (Intel) wrote:
The code you show is not legal and won't compile. You can't point a rank-3 pointer to a rank-1 array. But in general, pointer assignment at most moves one address and some other "descriptor" information - it doesn't move data. Even in a multidimensional array case, it moves the address and bounds, not data.
There are other ways to get this sort of rank remapping - are you sure you need to pass pointers around? In modern Fortran, pointers have very limited applicability.
Hi Steve,
Thanks for your reply. Your explanations truly help me a lot. I am sorry that in line 5 it should be p_in(:,:,:) rather than p_in.
This is quite a big code that I just start learning. We will consider changing the data structure for improving performance.
Many thanks for your kind suggestions!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok. In that case, it is as I said - just one address and some bounds information is copied. There is only one data pointer anyway, not one for each element.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page