Skip to content

Commit

Permalink
Merge pull request #73 from antoine-morvan/am/omp_num_thread_update
Browse files Browse the repository at this point in the history
Add semantic for reading thread count from $OMP_NUM_THREADS
  • Loading branch information
reuterbal authored Mar 21, 2024
2 parents dcaeba1 + b4102ed commit 4e8ada0
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ The different prototype variants of the dwarf create different binaries that
all behave similarly. The basic three arguments define (in this order):

- Number of OpenMP threads
- 1 : single thread mode, skip multithread MPI init; default value;
- 2 or higher : force OpenMP thread count, enables multithread MPI;
- 0 or negative : read OMP_NUM_THREADS variable if present or defaults to CPU count (`omp_get_max_threads()`);
- Size of overall working set in columns
- Block size (NPROMA) in columns

Expand Down
8 changes: 8 additions & 0 deletions src/cloudsc_c/dwarf_cloudsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ int main( int argc, char *argv[] ) {
omp_threads = atoi( argv[1] );
ngptot = atoi( argv[2] );
nproma = atoi( argv[3] );
if (omp_threads <= 0) {
#ifdef _OPENMP
omp_threads = omp_get_max_threads();
#else
// if arg is 0 or negative, and OpenMP disabled; defaults to 1
omp_threads = 1;
#endif
}
cloudsc_driver(omp_threads, ngptot, nproma);
}
else {
Expand Down
8 changes: 8 additions & 0 deletions src/cloudsc_cuda/dwarf_cloudsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ int main( int argc, char *argv[] ) {
omp_threads = atoi( argv[1] );
ngptot = atoi( argv[2] );
nproma = atoi( argv[3] );
if (omp_threads <= 0) {
#ifdef _OPENMP
omp_threads = omp_get_max_threads();
#else
// if arg is 0 or negative, and OpenMP disabled; defaults to 1
omp_threads = 1;
#endif
}
cloudsc_driver(omp_threads, ngptot, nproma);
}
else {
Expand Down
16 changes: 14 additions & 2 deletions src/cloudsc_fortran/dwarf_cloudsc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ PROGRAM DWARF_CLOUDSC
USE YOMCST , ONLY : YRCST
USE YOETHF , ONLY : YRTHF

#ifdef _OPENMP
USE OMP_LIB
#endif

IMPLICIT NONE

CHARACTER(LEN=20) :: CLARG
Expand All @@ -45,8 +49,16 @@ PROGRAM DWARF_CLOUDSC

! Get the number of OpenMP threads to use for the benchmark
if (IARGS >= 1) then
CALL GET_COMMAND_ARGUMENT(1, CLARG, LENARG)
READ(CLARG(1:LENARG),*) NUMOMP
CALL GET_COMMAND_ARGUMENT(1, CLARG, LENARG)
READ(CLARG(1:LENARG),*) NUMOMP
if (NUMOMP <= 0) then
#ifdef _OPENMP
NUMOMP = OMP_GET_MAX_THREADS()
#else
! if arg is 0 or negative, and OpenMP disabled; defaults to 1
NUMOMP = 1
#endif
end if
end if

! Initialize MPI environment
Expand Down
16 changes: 14 additions & 2 deletions src/cloudsc_gpu/dwarf_cloudsc_gpu.F90
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ PROGRAM DWARF_CLOUDSC
USE CLOUDSC_DRIVER_GPU_SCC_FIELD_MOD, ONLY: CLOUDSC_DRIVER_GPU_SCC_FIELD
#endif

#ifdef _OPENMP
USE OMP_LIB
#endif

IMPLICIT NONE

CHARACTER(LEN=20) :: CLARG
Expand All @@ -71,8 +75,16 @@ PROGRAM DWARF_CLOUDSC

! Get the number of OpenMP threads to use for the benchmark
if (IARGS >= 1) then
CALL GET_COMMAND_ARGUMENT(1, CLARG, LENARG)
READ(CLARG(1:LENARG),*) NUMOMP
CALL GET_COMMAND_ARGUMENT(1, CLARG, LENARG)
READ(CLARG(1:LENARG),*) NUMOMP
if (NUMOMP <= 0) then
#ifdef _OPENMP
NUMOMP = OMP_GET_MAX_THREADS()
#else
! if arg is 0 or negative, and OpenMP disabled; defaults to 1
NUMOMP = 1
#endif
end if
end if

! Initialize MPI environment
Expand Down
16 changes: 14 additions & 2 deletions src/cloudsc_loki/dwarf_cloudsc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ PROGRAM DWARF_CLOUDSC
#endif
USE EC_PMON_MOD, ONLY: EC_PMON

#ifdef _OPENMP
USE OMP_LIB
#endif

IMPLICIT NONE

CHARACTER(LEN=20) :: CLARG
Expand All @@ -44,8 +48,16 @@ PROGRAM DWARF_CLOUDSC

! Get the number of OpenMP threads to use for the benchmark
if (IARGS >= 1) then
CALL GET_COMMAND_ARGUMENT(1, CLARG, LENARG)
READ(CLARG(1:LENARG),*) NUMOMP
CALL GET_COMMAND_ARGUMENT(1, CLARG, LENARG)
READ(CLARG(1:LENARG),*) NUMOMP
if (NUMOMP <= 0) then
#ifdef _OPENMP
NUMOMP = OMP_GET_MAX_THREADS()
#else
! if arg is 0 or negative, and OpenMP disabled; defaults to 1
NUMOMP = 1
#endif
end if
end if

! Initialize MPI environment
Expand Down

0 comments on commit 4e8ada0

Please sign in to comment.