OpenMP no threading in subroutine

此生再无相见时 提交于 2019-12-12 18:04:54

问题


I'm writing a matrix multiplication subroutine in Fortran. I'm using the Intel Fortran compiler. I've written a simple static scheduled parallel do-loop. Unfortunately, it's running on only one thread. Here's the code:

      SUBROUTINE MATMULT(A,B,C,L,M,N)
      REAL*8 A,B,C
      INTEGER NCORES, CHUNK, TID
      DIMENSION A(L,N),B(L,M),C(M,N)
      PARAMETER (NCORES=8)
      CHUNK=(L/(NCORES+1))+1
      TID=0
!$OMP PARALLELDO SHARED(A,B,C,L,M,N,CHUNK) PRIVATE(I,J,K,TID)
!$OMP+DEFAULT(NONE) SCHEDULE(STATIC,CHUNK)
      DO I=1,L
         TID = OMP_GET_THREAD_NUM()
         PRINT *, "THREAD ", TID, " ON I=", I
         DO K=1,N
            DO J=1,M
               A(I,K) = A(I,K) + B(I,J)*C(J,K)
            END DO
         END DO
      END DO
!$OMP END PARALLELDO
      RETURN
      END

Note:

  • There are no parallel directives in the main program that calls the routine
  • The arrays A,B,C are initialized serially in the main program. A is initialized to zeros
  • I am enforcing the Fortran fixed source form during compilation

I have confirmed the following:

  • Another example program works fine with 8 threads (so no hardware issue)
  • I have used the -openmp compiler argument
  • OMP_GET_NUM_PROCS() and OMP_GET_MAX_THREADS() both return 0
  • TID is 0 for every iteration over I (which shouldn't be the case)

I am unable to diagnose my mistake. I'd appreciate any inputs on this.


回答1:


The identifier OMP_GET_THREAD_NUM is not explicitly declared. The default implicit typing rules mean it will be of type real. That's not consistent with the declaration in the OpenMP spec for the function of that name.

Adding USE OMP_LIB would fix that issue. Further, not using implicit typing (IMPLICIT NONE) would avoid this and a multitude of similar problems.



来源:https://stackoverflow.com/questions/12646504/openmp-no-threading-in-subroutine

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!