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

lastprivate problem OpenMP clause

danielsue
Beginner
1,115 Views

Hi All,

I have a section of OpenMP parallel loop as follow. 

#ifdef OPENMP
    !$omp parallel                                                    &
    !$omp num_threads(numofthreads_global)       &
    !$omp default(shared)                                       &
    !$omp private(ivol)                                             &    
    !$omp lastprivate(param2, param3)
    !$omp do schedule(static)
#endif   
         do ivol=1,nn           
           call subroutineX(param(ivol), param2, param3)
         end do
#ifdef OPENMP
    !$omp end do
    !$omp end parallel
#endif

error #5082: Syntax error, found 'LASTPRIVATE' when expecting one of: PRIVATE REDUCTION FIRSTPRIVATE NUM_THREADS COPYIN SHARED DEFAULT

So I modified the codes as follows,

#ifdef OPENMP
    !$omp parallel                                                    &
    !$omp num_threads(numofthreads_global)      &
    !$omp default(shared)                                       &
    !$omp private(ivol)                                             &   
    !$omp firstprivate(param2, param3)                  &
    !$omp lastprivate(param2, param3)
    !$omp do schedule(static)
#endif   
         do ivol=1,nn           
           call subroutineX(param(ivol), param2, param3)
         end do
#ifdef OPENMP
    !$omp end do
    !$omp end parallel
#endif

But this time I will get one more error

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

I was confused on the error tips. The syntax is simple and seems correct.

Any suggestion?

Thanks and regards,

Daniel

0 Kudos
1 Reply
pbkenned1
Employee
1,115 Views

Hello,

The compiler diagnostic is correct -- the 'plain' PARALLEL directive does not accept the LASTPRIVATE clause.  This is not a legal OMP program:

subroutine foo
implicit none
integer param2,param3

!$omp parallel lastprivate(param2, param3)
!$omp end parallel

end subroutine foo

You have to apply LASTPRIVATE to a worksharing construct such as DO/PARALLEL DO, or SECTIONS/PARALLEL SECTIONS.

Just append your lastprivate clause to the !$omp do, and all will be fine:

subroutine foo
implicit none
integer ivol, numofthreads_global,param2,param3,nn
integer, dimension(:), allocatable :: param

nn = 10
numofthreads_global = 4

allocate (param(nn))

    !$omp parallel                              &
    !$omp num_threads(numofthreads_global)      &
    !$omp default(shared)                       &
    !$omp private(ivol)                         &
    !$omp firstprivate(param2, param3)

    !$omp do schedule(static) lastprivate(param2, param3)

         do ivol=1,nn
           call subroutineX(param(ivol), param2, param3)
         end do

    !$omp end do
    !$omp end parallel

end subroutine foo

C:\ISN_Forums\U489451>ifort -Qopenmp -c openmp_sub_fix.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.2.176 Build 20140130

Patrick

0 Kudos
Reply