goto


Home

Free Source Code

Module fthreads

Fact Sheet

Email us


Purple Sage Computing Solutions, Inc.

fthreads Barriers

Home --> Free Source Code --> fthreads --> fthreads Usage --> fthreads Barriers

fthreads Barriers

This page describes the use of the fthreads barriers. Links to the individual routines are listed below.

Back to the Top

Introduction to Barriers

A barrier is a synchronization object. A thread must, in general, synchronize itself with other threads to properly execute a multithreaded program. In the fthreads system, a barrier object is declared to be a variable of type barrier_t, and must be initialized with a call to barrier_init() before it may be used. When a program is finished using a barrier, it may delete the barrier with a call to barrier_del(). The maximum number of barriers which may be used by a program is set by the max_barriers argument on the call to fthreads_init().

A barrier has a property call its height, which is a positive integer. Threads synchronize at a barrier by calling barrier_sync(). The barrier keeps a count of how many threads have called barrier_sync(). When the barrier is initialized by calling barrier_init(), the count is zero. Each call to barrier_sync() increments the count by one. The threads are suspended at the barrier until the count reaches the height, at which time the count is reset to zero and all the supended threads resume execution.

The programmer places a call to barrier_sync() at any point in the program where all threads must have finish executing up to the barrier before any of them can proceed beyond the barrier.

Back to the Top

Barrier Routines

barrier_init()

The barrier_init() routine initializes a new barrier synchronization object.

interface
   subroutine barrier_init( b, tm, name, &
              trace_v, flag)
      type( barrier_t), intent( out) :: b
      type( team_t), optional, &
                     intent( in) :: tm
      character( len= *), optional, &
                 intent( in) :: name
      type( trace_t), optional, &
            intent( inout) :: trace_v
      integer, optional, &
               intent( out) :: flag
   end subroutine barrier_init
end interface
			

The barrier_init() routine returns a type barrier_t barrier variable b. The barrier height is the number of members of optional type team_t variable tm, or the team of all worker threads. The optional character variable provides a barrier name. The optional type trace variable trace_v and the optional integer variable flag provide tracing and feedback.

Back to the Top

barrier_del()

The barrier_del() routine deletes a barrier synchronization object.

interface
   subroutine barrier_del( b, trace_v, &
                              flag)
      type( barrier_t), intent( out) :: b
      type( trace_t), optional, &
            intent( inout) :: trace_v
      integer, optional, &
               intent( out) :: flag
   end subroutine barrier_del
end interface
			

The barrier_del() routine deletes a type barrier_t barrier variable b. The optional type trace_t variable trace_v and the optional integer variable flag provide tracing and feedback.

Back to the Top

barrier_sync()

The barrier_sync() routine synchronizes a thread at a barrier.

interface
   subroutine barrier_sync( b, th, &
                            trace_v, flag)
      type( barrier_t), intent( out) :: b
      type( thread_t), optional, &
                       intent( in) :: th
      type( trace_t), optional, &
            intent( inout) :: trace_v
      integer, optional, &
               intent( out) :: flag
   end subroutine barrier_sync
end interface
			

The barrier_sync() routine synchronizes the calling thread at the barrier indicated by the type barrier_t barrier variable b. If the optional type thread_t variable th is present, the calling thread will be check for membership in the barrier's team. The optional type trace_t variable trace_v and the optional integer variable flag provide tracing and feedback.

Back to the Top

barrier_id()

The barrier_id() return the barrier id.

interface
   integer function barrier_id( b)
      type( barrier_t), intent( in) :: b
   end function barrier_id
end interface
			

The integer function barrier_id() returns the barrier id. The barrier id is a unique positive integer from one through the number of barriers.

Back to the Top

barrier_status()

The barrier_status() routine returns a barrier's statistics.

interface
   subroutine barrier_status( b, name, &
                      number, synced, &
                      trace_v, flag)
      type( barrier_t), intent( in) :: b
      character( len= *), optional, &
                 intent( out) :: name
      integer, optional, &
               intent( out) :: number
      integer, optional, &
               intent( out) :: synced
      type( trace_t), optional, &
            intent( inout) :: trace_v
      integer, optional, &
               intent( out) :: flag
   end subroutine barrier_status
end interface
			

The barrier_status() routine returns the barrier statistics of the barrier indicated by the type barrier_t barrier variable b. The optional character variable name returns the barrier's name. The optional integer variable number returns the barrier's height. The optional integer synced returns the number of times a thread has synchronized at the barrier. The optional type trace_t variable trace_v and the optional integer variable flag provide tracing and feedback.

Back to the Top


Home - Fact Sheet - Free Source Code - Fortran Links - Email us

Back to the Top