Text-only Table of Contents (frame/ no frame)
(12) Thread Control Previous Top Next

Thread Control

Barrier

Each thread wait at the barrier until all threads reach the barrier.

!     Fortran example

!$omp parallel private(myid,istart,iend)
call myrange(myid, nthreads, istart, iend)
do i = istart, iend
a(i) = a(i) - b(i)
enddo
!$omp barrier
call dowork(a)
!$omp end parallel


/* C/C++ Example */

#pragma omp parallel private(myid, istart, iend)
{
myrange(myid, nthreads, &istart, &iend);
for(i=istart; i<=iend; i++){
a[i] = a[i] - b[i];
}
#pragma omp barrier
dowork(a);
}
 
Master

A section of code that runs only on the master (thread with rank=0)

! Fortran example

!$omp parallel private(myid, istart, iend)
call myrange(myid, nthreads, global_start, global_end, istart, iend)
do i = istart, iend
a(i) = b(i)
enddo
!$omp barrier
!$omp master
write(21) a
!$omp end master
call do_work(istart, iend)
!$omp end parallel

/* C/C++ example */

#pragma omp parallel private(myid, istart, iend)
{
myrange(myid, nthreads, global_start, global_end, &istart, &iend);
for(i=istart; i<=iend; i++){
a[i] = b[i];
}
#pragma omp barrier
#pragma omp master
{
n = global_end - global_start + 1;
write_size = fwrite(a, 1, n, file_pointer);
}
do_work(istart, iend);
}

Single

Similar to Master except runs only on the first thread to reach it





Previous Top Next


thread_control.src  last modified Mar 23, 2009 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College