Skip to content

Commit

Permalink
Draft: Fix max thread capping issue (#170)
Browse files Browse the repository at this point in the history
* Try adding a task wait to the end of mm loop

* Only force a wait if you know the threads are capped

* Try CI for thread cap

* Fix indenting

* Double check if the CI will catch

* Maybe the name was missing

* Have to export from the matrix

* mpich -> openmpi

* Maybe I can trigger the error on a mac

* Re-integrate the fix
  • Loading branch information
william-dawson authored Sep 4, 2021
1 parent d1c47d5 commit 19e9248
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
matrix:
name: [mac, ubuntu-mpich, ubuntu-standard, ubuntu-debug,
ubuntu-nogather]
ubuntu-nogather, mac-thread-cap]
include:
- name: ubuntu-standard
os: ubuntu-latest
Expand All @@ -16,6 +16,7 @@ jobs:
debug: 0
noalligather: 0
mpich: 0
threadoff: 0
- name: ubuntu-debug
os: ubuntu-latest
testos: LINUX
Expand All @@ -24,6 +25,7 @@ jobs:
debug: 1
noalligather: 0
mpich: 0
threadoff: 0
- name: ubuntu-nogather
os: ubuntu-latest
testos: LINUX
Expand All @@ -32,6 +34,7 @@ jobs:
debug: 0
noalligather: 1
mpich: 0
threadoff: 0
- name: ubuntu-mpich
os: ubuntu-latest
testos: LINUX
Expand All @@ -40,6 +43,16 @@ jobs:
debug: 0
noalligather: 0
mpich: 1
threadoff: 0
- name: mac-thread-cap
os: macos-latest
testos: OSX
maketest: "ctest -R Regression111"
testexamples: 0
debug: 0
noalligather: 0
mpich: 0
threadoff: 1
- name: mac
os: macos-latest
testos: OSX
Expand All @@ -49,6 +62,7 @@ jobs:
noalligather: 0
mpich: 0
lint: 1
threadoff: 0
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
Expand All @@ -71,6 +85,7 @@ jobs:
env:
MAKETEST: ${{ matrix.maketest }}
TESTOS: ${{ matrix.testos }}
THREADOFF: ${{ matrix.threadoff }}
- name: check examples
run: |
bash -l UnitTests/check_examples.sh
Expand Down
7 changes: 6 additions & 1 deletion Source/Fortran/ProcessGridModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ MODULE ProcessGridModule
& WriteHeader, WriteListElement
USE NTMPIModule
#ifdef _OPENMP
USE omp_lib, ONLY : omp_get_num_threads
USE omp_lib, ONLY : omp_get_num_threads, omp_get_max_threads
#endif
IMPLICIT NONE
PRIVATE
Expand Down Expand Up @@ -51,6 +51,8 @@ MODULE ProcessGridModule
INTEGER, DIMENSION(:,:), ALLOCATABLE, PUBLIC :: blocked_within_slice_comm
!> blocked communicator between slices.
INTEGER, DIMENSION(:,:), ALLOCATABLE, PUBLIC :: blocked_between_slice_comm
!> The maximum number of openmp threads.
INTEGER :: omp_max_threads
END TYPE ProcessGrid_t
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> The default process grid.
Expand Down Expand Up @@ -246,9 +248,11 @@ SUBROUTINE ConstructNewProcessGrid_full(grid, world_comm_, process_rows_, &
!! threads.
#if defined NOBLOCK
grid%block_multiplier = 1
grid%omp_max_threads = 1
#elif defined _OPENMP
!$omp PARALLEL
num_threads = omp_get_num_threads()
grid%omp_max_threads = omp_get_max_threads()
!$omp end PARALLEL
grid%block_multiplier = num_threads/&
& (column_block_multiplier+row_block_multiplier)
Expand Down Expand Up @@ -357,6 +361,7 @@ SUBROUTINE CopyProcessGrid(old_grid, new_grid)
new_grid%block_multiplier = old_grid%block_multiplier
new_grid%number_of_blocks_columns = old_grid%number_of_blocks_columns
new_grid%number_of_blocks_rows = old_grid%number_of_blocks_rows
new_grid%omp_max_threads = old_grid%omp_max_threads

!! Allocate Blocks
ALLOCATE(new_grid%blocked_row_comm(old_grid%number_of_blocks_rows))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@
END SELECT
END DO
END DO
!! Prevent deadlock in the case where the number of tasks is capped.
IF (matA%process_grid%omp_max_threads .EQ. 1) THEN
!$OMP taskwait
END IF
END DO
!$OMP END MASTER
!$OMP END PARALLEL
Expand Down
5 changes: 5 additions & 0 deletions UnitTests/run_ci_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ if [[ "$TESTOS" == "LINUX" ]]; then
conda activate ntpoly-conda
fi

if [[ "$THREADOFF" == "1" ]]; then
export OMP_NUM_THREADS=1
echo "Setting threads to 1"
fi

cd Build
export CTEST_OUTPUT_ON_FAILURE=1
eval "$MAKETEST"
Expand Down

0 comments on commit 19e9248

Please sign in to comment.