Skip to content

Commit

Permalink
Disable OpenMP library function with a fall back to serial since the …
Browse files Browse the repository at this point in the history
…OpenMP support is currently optional. Fix linking of HDF5 code _FOUND needs to be all upper case.
  • Loading branch information
cianciosa committed Feb 5, 2024
1 parent fda34b0 commit 9d1a939
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/spack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ jobs:
- name: Show Cache
if: failure()
shell: bash
working-directory: ${{runner.workspace}}/KORC/build/
working-directory: ${{runner.workspace}}/KORC
run: |
pwd
ls -la
cat CMakeCache.txt
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ target_link_libraries (korc_depends
$<$<BOOL:${OpenMP_Fortran_FOUND}>:OpenMP::OpenMP_Fortran>
$<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>
$<$<BOOL:${MPI_Fortran_FOUND}>:MPI::MPI_Fortran>
$<$<BOOL:${HDF5_Found}>:hdf5::hdf5_fortran>
$<$<BOOL:${HDF5_FOUND}>:hdf5::hdf5_fortran>
$<$<BOOL:${USE_FIO}>:${FIO_LIBRARIES}>
$<$<BOOL:${USE_FIO}>:${M3DC1_LIBRARIES}>
$<$<BOOL:${USE_FIO}>:${NIMFIO_LIBRARIES}>
Expand Down
10 changes: 9 additions & 1 deletion src/korc_hpc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,23 @@ subroutine initialize_communications(params)
endif

!$OMP PARALLEL SHARED(params)
#if defined(_OPENMP)
params%num_omp_threads = OMP_GET_NUM_THREADS()
#else
params%num_omp_threads = 1
#endif
!$OMP END PARALLEL

if (params%mpi_params%rank.EQ.0) then
write(output_unit_write,'(/,"* * * * * * * OMP SET-UP * * * * * * *")')
!$OMP PARALLEL
!$OMP MASTER
write(output_unit_write,'(/,"OMP threads per MPI process: ",I3)') OMP_GET_NUM_THREADS()
write(output_unit_write,'(/,"OMP threads per MPI process: ",I3)') params%num_omp_threads
#if defined(_OPENMP)
write(output_unit_write,'(/,"Cores available per MPI process: ",I3)') OMP_GET_NUM_PROCS()
#else
write(output_unit_write,'(/,"Cores available per MPI process: ",I3)') 1
#endif
!$OMP END MASTER
!$OMP END PARALLEL
#ifdef GNU
Expand Down
5 changes: 4 additions & 1 deletion src/korc_interp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4011,8 +4011,11 @@ subroutine get_fio_magnetic_fields(prtcls, F, params)
!$OMP& FIRSTPRIVATE(Btmp)
do pp = 1, SIZE(prtcls%hint)

#if defined(_OPENMP)
thread_num = OMP_GET_THREAD_NUM()

#else
thread_num = 0
#endif
if (prtcls%flagCon(pp) .EQ. 1_is) then
x(1) = prtcls%Y(pp,1)*params%cpp%length
x(2) = prtcls%Y(pp,2)
Expand Down
26 changes: 25 additions & 1 deletion src/korc_ppusher.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5244,7 +5244,11 @@ subroutine adv_GCinterp_fio_top(params,spp,P,F)

do pp=1_idef,spp(ii)%ppp,pchunk

#if defined(_OPENMP)
thread_num = OMP_GET_THREAD_NUM()
#else
thread_num = 0
#endif

!write(6,*) thread_num,'3Y_R',spp(ii)%vars%Y(pp,1)*params%cpp%length
!write(6,*) thread_num,'3(p/mc)',spp(ii)%vars%V(pp,1)
Expand Down Expand Up @@ -5435,7 +5439,11 @@ subroutine adv_GCinterp_psiwE_top(params,spp,P,F)

do pp=1_idef,spp(ii)%ppp,pchunk

#if defined(_OPENMP)
thread_num = OMP_GET_THREAD_NUM()
#else
thread_num = 0
#endif

! write(output_unit_write,'("pp: ",I16)') pp

Expand Down Expand Up @@ -5618,7 +5626,11 @@ subroutine adv_GCinterp_psiwE_top(params,spp,P,F)

do pp=1_idef,spp(ii)%pRE,pchunk

#if defined(_OPENMP)
thread_num = OMP_GET_THREAD_NUM()
#else
thread_num = 0
#endif

if ((spp(ii)%pRE-pp).lt.pchunk) then
achunk=spp(ii)%pRE-pp+1
Expand Down Expand Up @@ -6529,7 +6541,11 @@ subroutine advance_GCinterp_fio_vars(vars,pp,tt,params,Y_R,Y_PHI,Y_Z, &
INTEGER :: thread_num


#if defined(_OPENMP)
thread_num = OMP_GET_THREAD_NUM()
#else
thread_num = 0
#endif


dt=params%dt
Expand Down Expand Up @@ -7861,7 +7877,11 @@ subroutine GCEoM1_p(pchunk,tt,P,F,params,RHS_R,RHS_PHI,RHS_Z,RHS_PLL,RHS_MU, &
INTEGER :: thread_num


#if defined(_OPENMP)
thread_num = OMP_GET_THREAD_NUM()
#else
thread_num = 0
#endif

!$OMP SIMD
! !$OMP& aligned(gradB_R,gradB_PHI,gradB_Z,curlb_R,curlb_Z, &
Expand Down Expand Up @@ -8108,7 +8128,11 @@ subroutine GCEoM1_fio_p(tt,P,F,params,RHS_R,RHS_PHI,RHS_Z,RHS_PLL,RHS_MU, &

pchunk=params%pchunk

#if defined(_OPENMP)
thread_num = OMP_GET_THREAD_NUM()
#else
thread_num = 0
#endif

! !$OMP SIMD
! do cc=1_idef,pchunk
Expand Down Expand Up @@ -8344,4 +8368,4 @@ end subroutine GCEoM1_fio_p

#endif FIO

end module korc_ppusher
end module korc_ppusher
16 changes: 16 additions & 0 deletions src/korc_random.f90
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,21 @@ SUBROUTINE initialize_random(seed)
INTEGER :: num_threads
INTEGER :: thread_num

#if defined(_OPENMP)
num_threads = OMP_GET_MAX_THREADS()
#else
num_threads = 1
#endif
IF (.NOT. ALLOCATED(states)) THEN
ALLOCATE(states(0:num_threads - 1))
END IF

!$OMP PARALLEL PRIVATE(thread_num)
#if defined(_OPENMP)
thread_num = OMP_GET_THREAD_NUM()
#else
thread_num = 0
#endif
states(thread_num) = random_construct_U(seed + thread_num)
!$OMP END PARALLEL
END SUBROUTINE initialize_random
Expand Down Expand Up @@ -151,7 +159,11 @@ FUNCTION get_random()

REAL(rp) :: get_random

#if defined(_OPENMP)
get_random = random_get_number(states(OMP_GET_THREAD_NUM()))
#else
get_random = random_get_number(states(0))
#endif
END FUNCTION get_random

FUNCTION get_random_U()
Expand Down Expand Up @@ -195,7 +207,11 @@ SUBROUTINE set_random_dist(low, high)
REAL(rp), INTENT(IN) :: high

!$OMP PARALLEL DEFAULT(SHARED)
#if defined(_OPENMP)
CALL random_set_dist(states(OMP_GET_THREAD_NUM()), low, high)
#else
CALL random_set_dist(states(0), low, high)
#endif
!$OMP END PARALLEL

END SUBROUTINE set_random_dist
Expand Down

0 comments on commit 9d1a939

Please sign in to comment.