Fortran multi-user thread safe DLL?

Without any fancy OpenMP or MPI code, we have basically a F77 calculation that has a C++ wrapper for a JNI call from an EJB. I’m trying to get a better picture of what is going on and what to look for when more than one user clicks on Compute at the same time? The calculation takes about a minute so there is plenty of opportunity for more than one thread at the same time. There are lots of arrays past in and out. Some local arrays have been allocated others are “automatic”.

Just for discussion, I’ve put a little psydo-code at the bottom of this post. We’ve checked the obvious like don’t use common blocks. Any other ideas/suggestions/experience or internal understanding of what’s going on? Does each thread get it’s own stack/heap/data?

The java program uses static loadLibrary(“DLL”); so there is one and only one copy of the DLL, right?

How does Fortran allocate memory for each type of array?
What effect does a save command have?
Is there a Thread safe for dummies reference I should read?
I’m sure we need to do more than use multi-threaded libraries in the compiler project settings.

subroutine Compute(a, n, x, filename, output, out)
real a(n)
real out(n)
character*256 filename
save
do timeloop=1,maxtime
Calculate something…
open (filename, read-only, share, deny none)
read
close
end do
end subroutine

Hi Darrell,

You’ll want to stay away from SAVE. This causes a variable’s value to be stored in the .data section and all threads would shared the same memory location.

Even though you don’t use OpenMP, I would suggest compiling with “-mp”. The compiler will then allocate all local variables on the stack. Each thread has it’s own stack space but share the heap and data.

  • Mat