Parallel Programming Guide for HP-UX Systems

Parallel synchronization
Synchronization tools
Chapter 8 141
The form of the wait functions is shown in Table 8-6.
where (in Fortran)
barrier
is a barrier variable of the indicated type and
nthr
is
the number of threads calling the routine.
where (in C/C++)
barrier_p
is a pointer of the indicated type and
nthr
is a pointer
referencing the number of threads calling the routine.
You can use a barrier variable in multiple calls to the
wait function, if you ensure that two such barriers are
not simultaneously active. You must also verify that
nthr
reflects the correct number of threads.
sync_routine
Among the most basic optimizations performed by the HP compilers is
code motion. This optimization moves code across routine calls. If the
routine call is to a synchronization function that the compiler cannot
identify as such, and the code moved must execute on a certain side of it,
this movement may result in wrong answers.
The compiler is aware of all synchronization functions and does not move
code across them when they appear directly in code. However, if the
synchronization function is hidden in a user-defined routine, the
compiler has no way of knowing about it and may move code across it.
Any time you call synchronization functions indirectly using your own
routines, you must identify your routines with a sync_routine directive
or pragma.
Table 8-6 Form of wait functions
Language Form
Fortran INTEGER FUNCTION WAIT_BARRIER(barrier,nthr)
C/C++ int wait_barrier(barrier_t *barrier_p,const int *nthr);