On Apr 27, 6:27 am, Charles Coldwell <coldw...@[EMAIL PROTECTED]
> wrote:
> Sebastian Hanigk <han...@[EMAIL PROTECTED]
> writes:
> > jomarbue...@[EMAIL PROTECTED]
writes:
>
> >> Can someone clue me on how to call external subroutines from within a
> >> parallel construct? As I understand, the OpenMP standard states that
> >> all variables local to subroutines and functions within a parallel
> >> construct are private.
>
> > Essentially your called routines should be thread-safe (reentrant),
> > i.e. no external state, global data access secured with mutexes, ...
>
> > Write those routines like you would write subprograms in a functional
> > language (no side effects, result depends only on passed arguments, no
> > argument modification) and you get reentrancy for free.
>
> There's a concept in Fortran 90 that's closely related: pure
> functions. All pure functions are reentrant. Not all reentrant
> functions are pure, however. Pure functions are the only kind you
> write in a purely functional programming language, like Haskell. If
> you think you need to save state for some reason, you have to learn
> about monads.
>
> Chip
>
> --
> Charles M. "Chip" Coldwell
> "Turn on, log in, tune out"
> GPG Key ID: 852E052F
> GPG Key Fingerprint: 77E5 2B51 4907 F08A 7E92 DE80 AFA9 9A8F 852E 052F
Hi Chip,
Thank you for your answer. The main problem I'm having is with
subroutines, not with functions. The object of the subroutines is to
do an in-place calculation and thus they modify at least one of the
arrays passed as arguments. However, the output array depends strictly
on the input arguments. There is no state to keep track off. In the
parallel ****tion, I tried making private copies of the array that the
subroutines change. I also tried making private copies of all arrays
the subroutines use. Neither approach worked.
Thank you again for your answer,
Jomar


|