- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Hi
I get a stackoverflow when adding two allocated arrays, so it seems to make a temporary array on the stack:
program main
integer :: n=160000
integer*8, dimension(:), pointer :: a,b,c
allocate(a(n))
allocate(b(n))
allocate(c(n))
a(:)=1
b(:)=2
c = a+b ! forrtl: severe (170): Program Exception - stack overflow
end program
It does not fail if I make a loop and add one element at the time.
Is there a better way to avoid this?
Link kopiert
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
I realized that I can use the compiler flag /heap-arrays[:size]
Is there any drawbacks of using this flag and how big should size be?
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
The size should be zero (i.e. /heap-arrays:0).
Why are your arrays pointers? Do they need to be? The compiler often has to assume that things that can be aliased (pointers and targets) are aliased (i.e. perhaps `c` is the same things as `a` or `b`)- the creation of temporaries is one of the consequences of this.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Thank you @IanH for the reply.
Is there any overhead when using /heap-arrays:0
I think the reason for using pointers instead of allocatable was that the arrays are declared in a type, and previous compilers did not like that.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
/heap-arrays means that storage for temporaries will be on the heap. Setting aside that storage is typically slower than setting aside storage on the stack.
Allocatable components are commonly supported and are a much better solution if you don't need the reference semantics of pointers.
- RSS-Feed abonnieren
- Thema als neu kennzeichnen
- Thema als gelesen kennzeichnen
- Diesen Thema für aktuellen Benutzer floaten
- Lesezeichen
- Abonnieren
- Drucker-Anzeigeseite