子程序中OpenMP无线程 [英] OpenMP no threading in subroutine
问题描述
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ B,C(M,N)
参数(NCORES = 8)B,
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 (I,K)= A(I,I),I(I,K)= I, K)+ B(I,J)* C(J,K)
END DO
END DO
END DO
!$ OMP END PARALLELDO
RETURN
END
注意:
I已确认以下内容:
- 另一个示例程序在8个线程中正常工作(所以没有硬件问题)
- 我已经使用了-openmp编译器参数
- OMP_GET_NUM_PROCS()和OMP_GET_MAX_THREADS()都返回0
- 对于I上的每次迭代,TID都为0 (不应该是这种情况)
我无法诊断我的错误。我会很感激任何输入。
标识符OMP_GET_THREAD_NUM未明确声明。默认的隐式键入规则意味着它将是真实类型。这与OpenMP规范中关于该名称功能的声明不一致。
加入 USE OMP_LIB
可以解决这个问题。此外,不使用隐式键入( IMPLICIT NONE
)可以避免这种情况和许多类似的问题。
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.
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.
这篇关于子程序中OpenMP无线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!