Re: Array subsetting



Michel Olagnon wrote:
L.Spadavecchia@xxxxxxxxxxxxxx wrote:
Hello all,

I am running into difficulties using the WHERE function to subset
arrays. I am currently writing a program which needs to apply a
threshold to a real array of dimension (nx,ny). Lets call this array1.
I then have a second real array - lets call that array2- (I understand
all the arrays in the where statement must be of the same type?) which
will store the result as a binary value. It too has dimension (nx,ny).
Heres the way it appears in the program.

INTEGER,PARAMETER :: nx,ny
REAL :: threshold
REAL,DIMENSION(:,:),ALLOCATABLE :: array1,array2

ALLOCATE(array1(nx,ny))
ALLOCATE(array2(nx,ny))

WHERE (array1 > threshold)
array2 = 1.0
ELSE WHERE
array2 = 0.0
END WHERE

On trying to run this, I always get a stack overflow. I can't figure it
out, because the arrays are of the same rank, size and type. It may be
important that array1 actually sits in a global data module, whereas
array2 is local to the subroutine which thresholds the data.


It is not really a Fortran issue. Increase stack size when you run
it (something like "limit stacksize unlimited" on Unix), the program
is probably using temporary arrays to carry out the WHERE assignment.
You might also try to use a higher level of optimization, that might
get rid of the temporaries.

As Michel indicates, WHERE often produces a temporary logical array. If you are using a Windows or similar system, you may need to specify a stack size at link time, or use a utility to modify the stack limit in your .exe.
.



Relevant Pages

  • Array subsetting
    ... threshold to a real array of dimension. ... Lets call this array1. ... all the arrays in the where statement must be of the same type?) ... important that array1 actually sits in a global data module, ...
    (comp.lang.fortran)
  • Re: Array subsetting
    ... threshold to a real array of dimension. ... Lets call this array1. ... I then have a second real array - lets call that array2- (I understand ... all the arrays in the where statement must be of the same type?) ...
    (comp.lang.fortran)
  • Re: Help requested troubleshooting code
    ... all are arrays and all arrays are the same size. ... There is no distinction made between temporaries which really are ... local to either the predictor loop or the corrector loop and between ...
    (comp.lang.fortran)
  • Re: intersection of two vectors (different sizes)
    ... A delightful solution! ... For huge arrays, this might get stuck because large ... temporaries are created. ...
    (comp.lang.fortran)
  • Re: Help: IFC stack overflow
    ... or similar (google). ... If the arrays are large, also temporaries ... generated by the compiler can be a problem, and these might be hard to ...
    (comp.lang.fortran)