Examples of OpenMP* Usage

The following examples show how to use the OpenMP* feature.

A Simple Difference Operator

This example shows a simple parallel loop where each iteration contains different number of instructions. To get good load balancing, dynamic scheduling is used. The end do has a nowait because there is an implicit barrier at the end of the parallel region.

       subroutine do_1 (a,b,n)
  real a(n,n), b(n,n)
c$omp parallel
c$omp&   shared(a,b,n)
c$omp&   private(i,j)
c$omp do schedule(dynamic,1)
   do i = 2, n
       do j = 1, i
          b(j,i) = ( a(j,i) + a(j,i-1) ) / 2
       enddo
   enddo
c$omp end do nowait
c$omp end parallel
end

Two Difference Operators

This example shows two parallel regions fused to reduce fork/join overhead. The first end do has a nowait because all the data used in the second loop is different than all the data used in the first loop.

       subroutine do_2 (a,b,c,d,m,n)
  real a(n,n), b(n,n), c(m,m), d(m,m)
c$omp parallel
c$omp&   shared(a,b,c,d,m,n)
c$omp&   private(i,j)
c$omp do schedule(dynamic,1)
   do i = 2, n
       do j = 1, i
           b(j,i) = ( a(j,i) + a(j,i-1) ) / 2
       enddo
   enddo
c$omp end do nowait
c$omp do schedule(dynamic,1)
   do i = 2, m
       do j = 1, i
           d(j,i) = ( c(j,i) + c(j,i-1) ) / 2
       enddo
   enddo
c$omp end do nowait
c$omp end parallel
end