- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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 kopiert
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Got it. Thanks, Steve.

- RSS-Feed abonnieren
- Thema als neu kennzeichnen
- Thema als gelesen kennzeichnen
- Diesen Thema für aktuellen Benutzer floaten
- Lesezeichen
- Abonnieren
- Drucker-Anzeigeseite