I am totally ignorant about this topic, so what I am going to say/ask may be wrong or make little sense.
I just read that heap-allocated arrays might not be thread-safe, because “data stored in Heap-memory are visible to all threads”. This sounds like a rather obscure claim, and I do not know whether it is valid.
It seems to me that gfortran saves arrays on the heap by default, although I have not found the official documentation about this aspect. ifort has an option -heap-arrays to do so. The gfortran counterpart of -heap-arrays seems to be -fno-stack-arrays. Thanks for correcting me if I am wrong.
If the abovementioned claim is valid, does it mean that Fortran code compiled with gfortran without any option or ifort with -heap-arrays is generally not thread-safe? That would be very concerning, isn’t it? Thus I doubt whether the claim is true and I hope not.
Something that might be related: When I compile a program involving large automatic arrays with gfortran -fmax-stack-var-size=64 in order to avoid stack overflows, the following message is emitted:
Error: Array ‘XXX’ at (1) is larger than limit set by ‘-fmax-stack-var-size=’, moved from stack to static
storage. This makes the procedure unsafe when called recursively, or concurrently from multiple threads.
Consider increasing the ‘-fmax-stack-var-size=’ limit (or use ‘-frecursive’, which implies unlimited
‘-fmax-stack-var-size’) - or change the code to use an ALLOCATABLE array. If the variable is never
accessed concurrently, this warning can be ignored, and the variable could also be declared with the
SAVE attribute. [-Werror=surprising]