Text-only Table of Contents (frame/ no frame)
(10) OpenMP Clauses Previous Top Next

Other OpenMP Clauses

firstprivate


Example of  firstprivate clause
!     Fortran example

j = jstart
!$omp parallel do firstprivate(j)
do i = 1, n
if(i == 1 .or. i == n) then
j = j + 1
endif
a(i) = a(i) + j
enddo


/* C/C++ Example */

j = jstart;
#pragma omp parallel for firstprivate(j)
{
for(i=1; i<=n; i++){
if(i == 1 || i == n)
j = j + 1;
a[i] = a[i] + j;
}
}


lastprivate

Example of  lastprivate clause

! Fortran example

!$omp parallel do lastprivate(x)
do i = 1, n
x = sin(pi*dx*real(i))
a(i) = exp(x)
enddo
lastx = x

/* C/C++ example */

#pragma omp parallel for lastprivate(x)
{
for(i=1; i<=n; i++){
x = sin( pi * dx * (float)i );
a[i] = exp(x);
}
}
lastx = x;


ordered
! Fortran example

!$omp parallel do private(myval) ordered
do i = 1, n
myval = do_lots_of_work(i)
!$omp ordered
print*, i, myval
!$omp end ordered
enddo

lastx = x
/* C/C++ example */

#pragma omp parallel for private(myval) ordered
{
for(i=1; i<=n; i++){
myval = do_lots_of_work(i);
#pragma omp ordered
{
printf("%d %d\n", i, myval);
}
}
}





Previous Top Next


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