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

Thread Control (continued) 

Critical


!     Fortran example

the_max = 0.0
!$omp parallel private(myid, istart, iend)
call myrange(myid, nthreads, global_start, global_end, istart, iend)
call compute_a(a(istart:iend))
!$omp critical
the_max = max( maxval(a(istart:iend), the_max )
!$omp end critical
call more_work_on_a(a)
!$omp end parallel


/* C/C++ Example */

the_max = 0.0;
#pragma omp parallel private(myid, istart, iend)
{
myrange(myid, nthreads, global_start, global_end, &istart, &iend);
nvals = iend-istart+1;
compute_a(a[istart],nvals);
#pragma omp critical
the_max = max( maxval(a[istart],nvals), the_max );
#pragma omp end critical
call more_work_on_a(a)
}
 
Sections/Section


! Fortran example

!$omp parallel
!$omp sections

!$omp section
call init_field(field)

!$omp section
call check_grid(grid)

!$omp end sections
!$omp end parallel

/* C/C++ example */

#pragma omp parallel
{
#pragma omp sections
{
#pragma omp section
init_field(field);

#pragma omp section
check_grid(grid);
}
}






Previous Top Next


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