A quick question regarding fortran pointers

A quick question regarding fortran pointers

Hi,

I am quite new to fortran and have some simple questions regarding fortran pointer. The code piece is shown below:

  1. subroutine pointer_test(p_in)
  2.   Implicit None
  3.   
  4.   !…Incoming varibale
  5.   real(kind=8), pointer :: p_in
  6.  
  7.   !…Local variable
  8.   real(kind=8), pointer :: p_local(:,:,:)
  9.  
  10.   p_local => p_in
  11.  
  12. 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!
 

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

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.

Retired 12/31/2016

Quote:

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!

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.

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today