Skip to content

[flang][OpenMP] Implement better FIRSTPRIVATE/LASTPRIVATE diagnostics #145420

@eugeneepshteyn

Description

@eugeneepshteyn
Contributor

Please consider implementing better FIRSTPRIVATE/LASTPRIVATE diagnostics based on comments in #143764 (comment)

In case Fujitsu fixes the tests mentioned in the above issue, here are their sources that caused the issue to be filed in the first place:

0521_0030.f90:

INTEGER :: i
i=1
i0=1
i1=1
j=2
!$OMP PARALLEL default(firstprivate)
!$OMP SECTIONS
!$OMP parallel private(i)
i=100
!$OMP END parallel
!$OMP parallel firstprivate(i0)
i0=100
!$OMP END parallel
!$OMP parallel do lastprivate(i1)
do ii=1,1
i1=100
end do
!$OMP END parallel do
!$OMP parallel shared(j)
j=200
!$OMP END parallel
!$OMP END SECTIONS
!$OMP END PARALLEL
if (i.ne.1) print *,'err var i=',i
if (i0.ne.1) print *,'err var i0=',i0
if (i1.ne.100) print *,'err var i1=',i1
if (j.ne.2) print *,'err var j=',j
print *,'pass'

END 

0686_0024.f90:

module mod0
       integer::i,ii,iii,iiii
      end module

      module mod1
       use mod0
       integer::j,jj,jjj,jjjj
       integer::k=0
      end module

      program ompv2
      use mod1
      common /com/ m,mm,mmm,mmmm

!$omp parallel num_threads(10)

!$omp do reduction(+:k),lastprivate(i,ii,iii,iiii),firstprivate(j,jj,jjj,jjjj)
      do i=1,10
      do ii=1,10
      do iii=1,10
      do iiii=1,10
        k=k+1
      enddo
      enddo
      enddo
      enddo

!$omp do reduction(+:i,ii,iii),lastprivate(j,jj,jjj,jjjj),firstprivate(m,mm,mmm,mmmm)
      do j=1,iiii-1
      do jj=1,iiii-1
      do jjj=1,iiii-1
      do jjjj=1,iiii-1
        i=i+1
        ii=ii+1
        iii=iii+1
      enddo
      enddo
      enddo
      enddo

!$omp do reduction(+:j,jj,jjj),lastprivate(m,mm,mmm,mmmm)
      do m=1,jjjj-1
      do mm=1,jjjj-1
      do mmm=1,jjjj-1
      do mmmm=1,jjjj-1
        j=j+1
        jj=jj+1
        jjj=jjj+1
      enddo
      enddo
      enddo
      enddo

!$omp end parallel
      if (k/=10000) print *,k
      if (i/=10011.or.ii/=10011.or.iii/=10011.or.iiii/=11) print *,i,ii,iii,iiii
      if (j/=10011.or.jj/=10011.or.jjj/=10011.or.jjjj/=11) print *,j,jj,jjj,jjjj
      if (m/=11.or.mm/=11.or.mmm/=11.or.mmmm/=11) print *,m,mm,mmm,mmmm

      print *,'pass'

      end

Activity

added
flangFlang issues not falling into any other category
on Jun 23, 2025
added and removed
flangFlang issues not falling into any other category
on Jun 23, 2025
luporl

luporl commented on Jun 24, 2025

@luporl
Contributor

Thanks for filing this issue. I agree that some invalid uses of FIRSTPRIVATE/LASTPRIVATE/REDUCTION could be detected and diagnosed by Flang in 0686_0024.f90, as done by other compilers, such as GFortran (15.1.0).

But for 0521_0030.f90, I don't think diagnostics can be improved. The problem is just a wrong expectation in this line:
if (i1.ne.100) print *,'err var i1=',i1
It seems to be expecting i1 to behave as shared, or parallel do lastprivate(i1) to update the outmost i1 variable, instead of that in the enclosing scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @luporl@eugeneepshteyn@llvmbot

        Issue actions

          [flang][OpenMP] Implement better FIRSTPRIVATE/LASTPRIVATE diagnostics · Issue #145420 · llvm/llvm-project