@@ -43,6 +43,16 @@ MODULE TSSubs
4343! ! real array) of the simulated velocity (wind/water speed). It returns
4444! ! values FOR ONLY the velocity components that use the IEC method for
4545! ! computing spatial coherence; i.e., for i where SCMod(i) == CohMod_IEC
46+ ! !
47+ ! ! OpenMP: This is a cludgy mess. The TRH array ends up used as SHARED
48+ ! ! despite declaring it as PRIVATE with some compilers. So I have to
49+ ! ! cheat the system a bit and do extra allocations of a temporary, then
50+ ! ! point to it for OMP instances. But all those allocations would kill
51+ ! ! performance on single thread, so more crappy logic around that mess.
52+ ! ! It's ugly, but maybe, just maybe it will work ok.
53+ ! ! One other little issue though - if the MKL decides to go parallel
54+ ! ! in the LAPACK routine, it could be amess. So another statement to
55+ ! ! stop that from happening (somehow).
4656SUBROUTINE CalcFourierCoeffs_IEC ( p , U , PhaseAngles , S , V , TRH_in , ErrStat , ErrMsg )
4757
4858TYPE (TurbSim_ParameterType), INTENT (IN ) :: p ! < TurbSim parameters
@@ -801,12 +811,8 @@ SUBROUTINE Coh2H( p, IVec, IFreq, TRH, S, ErrStat, ErrMsg )
801811
802812
803813integer :: Indx, J, I, NPts
804-
814+ integer :: old_max_levels ! maximum nesting levels for OPENMP
805815
806- #ifdef _OPENMP
807- call omp_set_max_active_levels(1 ) ! disallow the LAPACK_pptrf to use OMP parallelization (this kills performance)
808- #endif
809-
810816
811817 ! -------------------------------------------------------------
812818 ! Calculate the Cholesky factorization for the coherence matrix
@@ -820,7 +826,14 @@ SUBROUTINE Coh2H( p, IVec, IFreq, TRH, S, ErrStat, ErrMsg )
820826 NPts = p% grid% NPoints
821827 END IF
822828
829+ #ifdef _OPENMP
830+ old_max_levels = omp_get_max_active_levels()
831+ call omp_set_max_active_levels(1 ) ! don't allow additional OPENMP parallelization here
832+ #endif
823833 CALL LAPACK_pptrf( ' L' , NPts, TRH(Indx:), ErrStat, ErrMsg ) ! 'L'ower triangular 'TRH' matrix (packed form), of order 'NPoints'; returns Stat
834+ #ifdef _OPENMP
835+ call omp_set_max_active_levels(old_max_levels)
836+ #endif
824837
825838 IF ( ErrStat /= ErrID_None ) THEN
826839 IF (ErrStat < AbortErrLev) then
0 commit comments