Line data Source code
1 : !-------------------------------------------------------------------------------- 2 : ! Copyright (c) 2023 Peter Grünberg Institut, Forschungszentrum Jülich, Germany 3 : ! This file is part of FLEUR and available as free software under the conditions 4 : ! of the MIT license as expressed in the LICENSE file in more detail. 5 : !-------------------------------------------------------------------------------- 6 : 7 : MODULE m_types_parallelLoop 8 : 9 : TYPE t_parallelLoop 10 : INTEGER :: overallMinIndex 11 : INTEGER :: overallMaxIndex 12 : INTEGER :: bunchMinIndex 13 : INTEGER :: bunchMaxIndex 14 : CONTAINS 15 : PROCEDURE :: t_parallelLoop_init 16 : GENERIC :: init => t_parallelLoop_init 17 : END TYPE t_parallelLoop 18 : 19 : PUBLIC :: t_parallelLoop 20 : 21 : CONTAINS 22 : 23 392856 : SUBROUTINE t_parallelLoop_init(this, iBunch, numBunches, overallMinIndex, overallMaxIndex) 24 : 25 : IMPLICIT NONE 26 : 27 : CLASS(t_parallelLoop), INTENT(INOUT) :: this 28 : INTEGER, INTENT(IN) :: iBunch, numBunches 29 : INTEGER, INTENT(IN) :: overallMinIndex, overallMaxIndex 30 : 31 : INTEGER :: chunkSize, leftoverSize, length 32 : 33 392856 : this%overallMinIndex = overallMinIndex 34 392856 : this%overallMaxIndex = overallMaxIndex 35 : 36 392856 : length = overallMaxIndex - overallMinIndex + 1 37 392856 : chunkSize = length / numBunches 38 392856 : leftoverSize = MODULO(length, numBunches) 39 392856 : IF (iBunch < leftoverSize) THEN 40 147381 : this%bunchMinIndex = iBunch*(chunkSize + 1) + overallMinIndex 41 147381 : this%bunchMaxIndex = (iBunch + 1)*(chunkSize + 1) + overallMinIndex - 1 42 : ELSE 43 245475 : this%bunchMinIndex = leftoverSize*(chunkSize + 1) + overallMinIndex + (iBunch - leftoverSize)*chunkSize 44 245475 : this%bunchMaxIndex = (this%bunchMinIndex + chunkSize) - 1 45 : ENDIF 46 392856 : END SUBROUTINE t_parallelLoop_init 47 : 48 1392 : SUBROUTINE calcNumberComputationBunches(minIndex, maxIndex, maxBunchSize, numBunches) 49 : 50 : IMPLICIT NONE 51 : 52 : INTEGER, INTENT(IN) :: minIndex 53 : INTEGER, INTENT(IN) :: maxIndex 54 : INTEGER, INTENT(IN) :: maxBunchSize 55 : INTEGER, INTENT(OUT) :: numBunches 56 : 57 : REAL :: length 58 : 59 1392 : length = maxIndex - minIndex + 1 60 1392 : numBunches = CEILING(length/(REAL(maxBunchSize))) 61 : 62 1392 : END SUBROUTINE calcNumberComputationBunches 63 : 64 1392 : INTEGER FUNCTION getNumberOfThreads() 65 : !$ use omp_lib 66 : IMPLICIT NONE 67 : INTEGER :: numThreads 68 1392 : numThreads = 1 69 1392 : !$omp parallel shared(numThreads) 70 : !$ numThreads = omp_get_num_threads() 71 : !$omp end parallel 72 1392 : getNumberOfThreads = numThreads 73 1392 : END FUNCTION getNumberOfThreads 74 : 75 0 : END MODULE m_types_parallelLoop