- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi: I'm not a Fortran expert so I was hoping someone could explain the difference in behavior between these two snippits of code:
real(8), POINTER :: a(:,:), b(:,:)
allocate( a(4,500000), b(4,500000) )
a = 1
b = a
and
real(8), ALLOCATABLE :: a(:,:), b(:,:)
allocate( a(4,500000), b(4,500000) )
a = 1
b = a
I compiled both snippits with ifort 13.1.3 20130607 with just "-g". The first snippit, with POINTER, segfaults in my default bash shell due to a stack overflow, as if the a array is being copied onto the stack before being copied into b. If I increase the stack size limit to something over 16MB (=4*500,000*8bytes/double), then the former code works OK. The second snippit, with ALLOCATABLE, works OK with a regular size stack (~10MB on RHEL 6 anyway). Is this the expected behavior for POINTER variables or a quirk of ifort?
Thanks,
Allen
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With ALLOCATABLE, the compiler knows that there is no overlap between b and a. With POINTER, it doesn't know and conservatively makes a copy of the right side before assigning to the left. In general you should use ALLOCATABLE unless you specifically need POINTER semantics.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Got it. Thanks, Steve.

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