Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

A quick question regarding fortran pointers

Wentao_Z_
Beginner
619 Views

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!
 

0 Kudos
1 Solution
Steven_L_Intel1
Employee
619 Views

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.

View solution in original post

0 Kudos
3 Replies
Steven_L_Intel1
Employee
620 Views

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.

0 Kudos
Wentao_Z_
Beginner
619 Views

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!

0 Kudos
Steven_L_Intel1
Employee
619 Views

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.

0 Kudos
Reply