Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

11.1.089 firstprivate lastprivate

Hans_J_
Beginner
517 Views
Hi All,
When I try to compile a f90 code with a OpenMP FIRSTPRIVATE LASTPRIVATE construct I get
$ ifort -openmp OpenMP_test.f -lpthread
OpenMP_test.f(28): error #5082: Syntax error, found 'LASTPRIVATE' when expecting one of: PRIVATE FIRSTPRIVATE REDUCTION COPYIN NUM_THREADS SHARED IF DEFAULT , ...
!$OMP PARALLEL PRIVATE(id) FIRSTPRIVATE(a) LASTPRIVATE(a) SHARED(b,junk)
-------------------------------------------^
OpenMP_test.f(28): error #6761: An entity cannot appear explicitly in more than one clause per directive except that an entity can be specified in both a FIRSTPRIVATE and LASTPRIVATE clause.
!$OMP PARALLEL PRIVATE(id) FIRSTPRIVATE(a) LASTPRIVATE(a) SHARED(b,junk)
----------------------------------------^
compilation aborted for OpenMP_test.f (code 1)
OpenMP_test.f(28): error #5082: Syntax error, found 'LASTPRIVATE' when expecting one of: PRIVATE FIRSTPRIVATE REDUCTION COPYIN NUM_THREADS SHARED IF DEFAULT , ...!$OMP PARALLEL PRIVATE(id) FIRSTPRIVATE(a) LASTPRIVATE(a) SHARED(b,junk)-------------------------------------------^OpenMP_test.f(28): error #6761: An entity cannot appear explicitly in more than one clause per directive except that an entity can be specified in both a FIRSTPRIVATE and LASTPRIVATE clause. !$OMP PARALLEL PRIVATE(id) FIRSTPRIVATE(a) LASTPRIVATE(a) SHARED(b,junk)----------------------------------------^compilation aborted for OpenMP_test.f (code 1)
ifort contradicts itself.
The code is below. If I remove the LASTPRIVATE(a) (hence the stupid if (id .EQ. 0) then junk ... code for id=0 to get a's value for id=0) then it compiles and works. Except of course, at the end of the parallel region a does not equal itsvalue for thread id 0, which s the whole point of theLASTPRIVATE(a)
Any ideas?
Thanks, Hans
program OpenMP_test
USE OMP_LIB
implicit none
integer,parameter :: r8=SELECTED_REAL_KIND(12)
real(KIND=r8),allocatable,dimension(:) :: a,b
real(KIND=r8),dimension(5) :: c,d,junk
integer :: nthreads,id,i
allocate(a(5),b(5))
a = 1.0_r8
b = 2.0_r8
c = 1.0_r8
d = 2.0_r8
junk = 0.0_r8
write(6,*) ' '
do i = 1,5
write(6,*) c(i)
end do
write(6,*) ' '
nthreads = omp_get_max_threads()
write(6,*) 'OMP_NUM_THREADS:',nthreads
!$OMP PARALLEL PRIVATE(id) FIRSTPRIVATE(a) LASTPRIVATE(a) SHARED(b,junk)
id = omp_get_thread_num()
a = REAL(id,kind=r8)*a+b
!$OMP CRITICAL
write(6,*) ' '
write(6,*) 'I am : ',id
do i = 1,5
write(6,*) a(i)
end do
write(6,*) ' '
!$OMP END CRITICAL
if (id .EQ. 0) then
junk(1:5) = a(1:5)
end if
!$OMP END PARALLEL
write(6,*) ' and in the end ...'
do i = 1,5
write(6,*) junk(i)
end do
write(6,*) ' '
deallocate(a,b)
stop
end program OpenMP_test
0 Kudos
1 Reply
jimdempseyatthecove
Honored Contributor III
517 Views
!$OMP PARALLEL PRIVATE(id) FIRSTPRIVATE(a) LASTPRIVATE(a) SHARED(b,junk)
...
!$OMP END PARALLEL

Has no "last-ness". IOW there is no last interation of a parallel DO, no last section.

LASTPRIVATE

Use the LASTPRIVATE clause on the DO, SECTIONS, PARALLEL DO, and PARALLEL SECTIONS directives to provide a superset of the PRIVATE clause functionality.

For kicks, dummy up a


!$OMP PARALLEL DO PRIVATE(id) FIRSTPRIVATE(a) LASTPRIVATE(a) SHARED(b,junk)
DO I=1,100
... set in value for a
END DO
!$OMP END PARALLEL

and

!$OMP PARALLELSECTIONS PRIVATE(id) FIRSTPRIVATE(a) LASTPRIVATE(a) SHARED(b,junk)
...
!$OMP SECTION
... set in last value
!$OMP END PARALLEL SECTIONS


*** try to code in a manner such that compiler does not optimize out your statement(s) for updating a

Jim Dempsey

0 Kudos
Reply