Different Behavior Between POINTER and ALLOCATABLE

Different Behavior Between POINTER and ALLOCATABLE

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

Allen
3 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

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.

Steve - Intel Developer Support

Got it. Thanks, Steve.

Allen

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui