[Beowulf] Threaded code (& Fortran)

James Cownie jcownie at etnus.com
Wed Aug 18 06:45:02 PDT 2004

RGB wrote :-
> Sorry, I don't do fortran.  At least not unless somebody holds my dog
> hostage or threatens to torch my car.
> However, in C using threads is simply a matter of linking in the correct
> thread library:
>   LIBS = -lpthread -lmenu -lpanel -lcurses -lxml2 -lm
> (from a threaded app I wrote). 

It may not be that simple in Fortran since you need to be careful about
which variables are allocated on the stack (and therefore exist
separately in each thread), and which ones are statically allocated (and
are therefore shared between all threads).

As well as common blocks and module variables (which will certainly be
shared) according to the standard Fortran compilers are free to allocate
local variables statically in all except recursive
subroutines/functions. Whether your compiler uses this freedom can
depend not only the compiler, version and compile flags, but also the
size of the object, the phase of the moon and other such
non-deterministic factors.

Fundamentally you must have a way of telling the compiler that your code
is to be run in a threaded environment, which likely means that you need
to use OpenMP. Otherwise you'll be relying on properties of the compiler
which could change with the next release and are _likely_ to change if
you move to a new compiler or new machine.

-- Jim
James Cownie	<jcownie at etnus.com>
Etnus, LLC.     +44 117 9071438

More information about the Beowulf mailing list