decompmodule.f90
来自「CCSM Research Tools: Community Atmospher」· F90 代码 · 共 1,293 行 · 第 1/3 页
F90
1,293 行
! !USES: IMPLICIT NONE!! !INPUT PARAMETERS: INTEGER, INTENT( IN ) :: NPEsX ! Number of PEs in X INTEGER, INTENT( IN ) :: NPEsY ! Number of PEs in Y INTEGER, INTENT( IN ) :: Xdist(:) ! Distribution in X INTEGER, INTENT( IN ) :: Ydist(:) ! Distribution in Y!! !OUTPUT PARAMETERS: TYPE(DecompType), INTENT( OUT ) :: Decomp ! Decomp information!!! !DESCRIPTION:! Creates a variable block-block decomposition for a regular ! 2-D grid. The decomposition is given through the Xdist and ! Ydist distributions, which contain the number of entries on ! each PE in that dimension. This routine thus defines! a rectangular "checkerboard" distribution.!! !SYSTEM ROUTINES:! ALLOCATE!! !REVISION HISTORY:! 98.01.19 Sawyer Creation! 98.01.22 Sawyer Corrections, TESTED! 98.05.11 Sawyer Removed Perm from arglist -- see DecompPermute! 00.07.07 Sawyer Removed use of DimSizes(:) array!! !BUGS:! This routine makes the assumption that the sum of the! distribution in each dimension adds up to the total ! number of entries in that dimension. It will cause! problems if the actual local arrays are over- or ! under-allocated. For example, if the local array is! allocated statically for the maximum size of the! array on any processor, problems will occur on those! PEs which have less than the maximum.!!EOP!------------------------------------------------------------------------!BOC!! !LOCAL VARIABLES: INTEGER :: TruePE, I, J, K, Counter1, Counter2, SizeX, SizeY! CPP_ENTER_PROCEDURE( "DECOMPREGULAR2D" )!! Some sanity checks! CPP_ASSERT_F90( NPEsX .EQ. SIZE( Xdist ) ) CPP_ASSERT_F90( NPEsY .EQ. SIZE( Ydist ) )!! The head contains NPEs pointers to the tag lists.! SizeX = SUM(Xdist) SizeY = SUM(Ydist) Decomp%GlobalSize = SizeX * SizeY ALLOCATE( Decomp%NumEntries( NPEsX*NPEsY ) ) ALLOCATE( Decomp%Head( NPEsX*NPEsY ) ) Counter1 = 0 DO J = 1, NPEsY DO I = 1, NPEsX!! WARNING!!!! The definition of the PE is Row-major ordering! TruePE = ( J-1 ) * NPEsX + I !! The number of entries is the product of the local X, Y, Z allotment! Decomp%NumEntries(TruePE) = Xdist(I)*Ydist(J)!! For each Y there is a separate run! NULLIFY( Decomp%Head(TruePE)%StartTags ) NULLIFY( Decomp%Head(TruePE)%EndTags ) ALLOCATE( Decomp%Head(TruePE)%StartTags(Ydist(J)) ) ALLOCATE( Decomp%Head(TruePE)%EndTags(Ydist(J)) ) Counter2 = Counter1 DO K = 1, Ydist(J)!! Since this is a regular distribution the definition of! tags is dictated by Xdist(I), and appears Ydist(J) times!! Decomp%Head(TruePE)%StartTags(K) = Counter2 + 1 Decomp%Head(TruePE)%EndTags(K) = Counter2 + Xdist(I) Counter2 = Counter2 + SizeX ENDDO Counter1 = Counter1 + Xdist(I) ENDDO!! Align the counter such that it points to the start of the next ! block. (Ydist(J)-1) since already one layer has been added in.! Implicit assumption that SizeX = SUM( Xdist )! Counter1 = Counter1 + SizeX*(Ydist(J)-1) ENDDO CPP_LEAVE_PROCEDURE( "DECOMPREGULAR2D" ) RETURN!EOC END SUBROUTINE DecompRegular2D!------------------------------------------------------------------------!------------------------------------------------------------------------!BOP! !IROUTINE: DecompRegular3D --- Create a decomposition for a 3-D grid!! !INTERFACE: SUBROUTINE DecompRegular3D ( NPEsX, NPEsY, NPEsZ, & & Xdist, Ydist, Zdist, Decomp )! !USES: IMPLICIT NONE!! !INPUT PARAMETERS: INTEGER, INTENT( IN ) :: NPEsX ! Number of PEs in X INTEGER, INTENT( IN ) :: NPEsY ! Number of PEs in Y INTEGER, INTENT( IN ) :: NPEsZ ! Number of PEs in Z INTEGER, INTENT( IN ) :: Xdist(:) ! Distribution in X INTEGER, INTENT( IN ) :: Ydist(:) ! Distribution in Y INTEGER, INTENT( IN ) :: Zdist(:) ! Distribution in Z!! !OUTPUT PARAMETERS: TYPE(DecompType), INTENT( OUT ) :: Decomp ! Decomp information!!! !DESCRIPTION:! Creates a decomposition for a regular 3-D grid. The! decomposition is given through the Xdist, Ydist, and Zdist! distributions, which contain the number of entries on ! each PE in that dimension. This routine thus defines! a parallelopiped (SOMA-block) distribution.!! !SYSTEM ROUTINES:! ALLOCATE!! !REVISION HISTORY:! 98.01.19 Sawyer Creation! 98.05.11 Sawyer Removed Perm from arglist -- see DecompPermute! 00.07.07 Sawyer Removed use of Sizes(:) array!! !BUGS:! This routine makes the assumption that the sum of the! distribution in each dimension adds up to the total ! number of entries in that dimension. It will cause! problems if the actual local arrays are over- or ! under-allocated. For example, if the local array is! allocated statically for the maximum size of the! array on any processor, problems will occur on those! PEs which have less than the maximum.!! Currently untested (98.05.11)!EOP!------------------------------------------------------------------------!BOC!! !LOCAL VARIABLES: INTEGER :: TruePE, Counter1, Counter2, Counter3 INTEGER :: I, J, K, L, M, N, SizeX, SizeY, SizeZ! CPP_ENTER_PROCEDURE( "DECOMPREGULAR3D" )!! Some sanity checks!! CPP_ASSERT_F90( NPEsX .EQ. SIZE( Xdist ) ) CPP_ASSERT_F90( NPEsY .EQ. SIZE( Ydist ) ) CPP_ASSERT_F90( NPEsZ .EQ. SIZE( Zdist ) ) CPP_ASSERT_F90( .NOT. ASSOCIATED( Decomp%Head ) )!! The head contains NPEs pointers to the tag lists.! SizeX = SUM(Xdist) SizeY = SUM(Ydist) SizeZ = SUM(Zdist) Decomp%GlobalSize = SizeX * SizeY * SizeZ ALLOCATE( Decomp%NumEntries( NPEsX*NPEsY*NPEsZ ) ) ALLOCATE( Decomp%Head( NPEsX*NPEsY*NPEsZ ) ) Counter1 = 0 DO K = 1, NPEsZ DO J = 1, NPEsY DO I = 1, NPEsX!! WARNING!!!! The definition of the PE is Row-major ordering! TruePE = (K-1)*NPEsX*NPEsY + (J-1)*NPEsX + I NULLIFY( Decomp%Head(TruePE)%StartTags ) NULLIFY( Decomp%Head(TruePE)%EndTags )!! The number of entries is the product of the local X, Y, Z allotment! Decomp%NumEntries(TruePE) = Xdist(I)*Ydist(J)*Zdist(K)!! For each Z there are Y separate runs! ALLOCATE( Decomp%Head(TruePE)%StartTags(Ydist(J)*Zdist(K)) ) ALLOCATE( Decomp%Head(TruePE)%EndTags(Ydist(J)*Zdist(K)) ) Counter2 = Counter1 L = 0 DO N = 1, Zdist(K) Counter3 = Counter2 DO M = 1, Ydist(J)!! Since this is a regular distribution the definition of! tags is dictated by Xdist(I), and appears Ydist(J) times!! L = L + 1 Decomp%Head(TruePE)%StartTags(L) = Counter3 + 1 Decomp%Head(TruePE)%EndTags(L) = Counter3 + Xdist(I) Counter3 = Counter3 + SizeX ENDDO Counter2 = Counter2 + SizeX*SizeY ENDDO Counter1 = Counter1 + Xdist(I) ENDDO!! Align the counter such that it points to the start of the next ! block. (Ydist(J)-1) since already one X layer has been added in.! Implicit assumption that SizeX = SUM( Xdist )! Counter1 = Counter1 + SizeX*(Ydist(J)-1) ENDDO!! Align the counter such that it points to the start of the next ! block. (Zdist(K)-1) since already one X-Y layer has been added in.! Implicit assumption that SizeY = SUM( Ydist )! Counter1 = Counter1 + SizeX*SizeY*(Zdist(K)-1) ENDDO CPP_LEAVE_PROCEDURE( "DECOMPREGULAR3D" ) RETURN!EOC END SUBROUTINE DecompRegular3D!------------------------------------------------------------------------!------------------------------------------------------------------------!BOP! !IROUTINE: DecompRegular3Dorder --- Create a decomposition for a 3-D grid!! !INTERFACE: SUBROUTINE DecompRegular3Dorder( Order, NPEsX, NPEsY, NPEsZ, & & Xdist, Ydist, Zdist, Decomp )! !USES: IMPLICIT NONE!! !INPUT PARAMETERS: CHARACTER(3), INTENT( IN ) :: Order ! Dim. ordering INTEGER, INTENT( IN ) :: NPEsX ! Number of PEs in X INTEGER, INTENT( IN ) :: NPEsY ! Number of PEs in Y INTEGER, INTENT( IN ) :: NPEsZ ! Number of PEs in Z INTEGER, INTENT( IN ) :: Xdist(:) ! Distribution in X INTEGER, INTENT( IN ) :: Ydist(:) ! Distribution in Y INTEGER, INTENT( IN ) :: Zdist(:) ! Distribution in Z!! !OUTPUT PARAMETERS: TYPE(DecompType), INTENT( OUT ) :: Decomp ! Decomp information!! !DESCRIPTION:! Creates a variable block-block-block decomposition for a regular ! 3-D grid, where the ordering of the PEs can be explicitly given! (see next paragraph). The decomposition is given through the ! Xdist, Ydist, and Zdist distributions, which contain the number ! of entries on each PE in that dimension. This routine thus defines! a parallelopiped (SOMA-block) distribution.!! With the string argument Order, the order of counting in the! 3d PE space can be specified. There are six possible values:! "xyz", "xzy", "yxz", "yzx", "zxy", and "zyx". !! The same as DecompRegular3Dorder could also be achieved by! using DecompRegular3D and then permuting the PE ownership! with DecompPermute.!! !SYSTEM ROUTINES:! ALLOCATE!! !REVISION HISTORY:! 01.03.20 Sawyer Creation from DecompRegular3Dzy, added ordering!! !BUGS:! Not yet tested!!EOP!---------------------------------------------------------------------!BOC! !LOCAL VARIABLES: INTEGER :: TruePE, Counter1, Counter2, Counter3 INTEGER :: I, J, K, L, M, N, SizeX, SizeY, SizeZ INTEGER :: Imult, Jmult, Kmult! CPP_ENTER_PROCEDURE( "DECOMPREGULAR3DORDER" )!! Some sanity checks!! CPP_ASSERT_F90( NPEsX .EQ. SIZE( Xdist ) ) CPP_ASSERT_F90( NPEsY .EQ. SIZE( Ydist ) ) CPP_ASSERT_F90( NPEsZ .EQ. SIZE( Zdist ) ) CPP_ASSERT_F90( .NOT. ASSOCIATED( Decomp%Head ) ) IF ( Order=="xyz" ) THEN! Looks like: TruePE = (K-1)*NPEsX*NPEsY + (J-1)*NPEsX + (I-1) + 1 Imult = 1 Jmult = NPEsX Kmult = NPEsX*NPEsY ELSE IF ( Order=="xzy" ) THEN! Looks like: TruePE = (J-1)*NPEsX*NPEsZ + (K-1)*NPEsX + (I-1) + 1 Imult = 1 Jmult = NPEsX*NPEsZ Kmult = NPEsX ELSE IF ( Order=="yxz" ) THEN! Looks like: TruePE = (K-1)*NPEsY*NPEsX + (I-1)*NPEsY + (J-1) + 1 Imult = NPEsY Jmult = 1 Kmult = NPEsX*NPEsY ELSE IF ( Order=="yzx" ) THEN! Looks like: TruePE = (I-1)*NPEsY*NPEsZ + (K-1)*NPEsY + (J-1) + 1 Imult = NPEsY*NPEsZ Jmult = 1 Kmult = NPEsY ELSE IF ( Order=="zxy" ) THEN! Looks like: TruePE = (J-1)*NPEsX*NPEsZ + (I-1)*NPEsZ + (K-1) + 1 Imult = NPEsZ Jmult = NPEsX*NPEsZ Kmult = 1 ELSE IF ( Order=="zyx" ) THEN! Looks like: TruePE = (I-1)*NPEsY*NPEsZ + (J-1)*NPEsZ + (K-1) + 1 Imult = NPEsY*NPEsZ Jmult = NPEsZ Kmult = 1 ELSE ! Looks like: TruePE = (K-1)*NPEsX*NPEsY + (J-1)*NPEsX + (I-1) + 1 print *, "Warning: DecompCreate3Dorder", Order, "not supported" print *, " Continuing with XYZ ordering" Imult = 1 Jmult = NPEsX Kmult = NPEsX*NPEsY ENDIF!! The head contains NPEs pointers to the tag lists.! SizeX = SUM(Xdist) SizeY = SUM(Ydist) SizeZ = SUM(Zdist) Decomp%GlobalSize = SizeX * SizeY * SizeZ ALLOCATE( Decomp%NumEntries( NPEsX*NPEsY*NPEsZ ) ) ALLOCATE( Decomp%Head( NPEsX*NPEsY*NPEsZ ) ) Counter1 = 0 DO K = 1, NPEsZ DO J = 1, NPEsY DO I = 1, NPEsX!! WARNING!!!! The definition of the PE is Row-major ordering! TruePE = (I-1)*Imult + (J-1)*Jmult + (K-1)*Kmult + 1 !! The number of entries is the product of the local X, Y, Z allotment! Decomp%NumEntries(TruePE) = Xdist(I)*Ydist(J)*Zdist(K)!! For each Z there are Y separate runs! ALLOCATE( Decomp%Head(TruePE)%StartTags(Ydist(J)*Zdist(K)) ) ALLOCATE( Decomp%Head(TruePE)%EndTags(Ydist(J)*Zdist(K)) ) Counter2 = Counter1 L = 0 DO N = 1, Zdist(K) Counter3 = Counter2 DO M = 1, Ydist(J)!! Since this is a regular distribution the definition of! tags is dictated by Xdist(I), and appears Ydist(J) times!! L = L + 1 Decomp%Head(TruePE)%StartTags(L) = Counter3 + 1 Decomp%Head(TruePE)%EndTags(L) = Counter3 + Xdist(I) Counter3 = Counter3 + SizeX ENDDO Counter2 = Counter2 + SizeX*SizeY ENDDO Counter1 = Counter1 + Xdist(I) ENDDO!! Align the counter such that it points to the start of the next ! block. (Ydist(J)-1) since already one X layer has been added in.! Implicit assumption that SizeX = SUM( Xdist )! Counter1 = Counter1 + SizeX*(Ydist(J)-1) ENDDO!! Align the counter such that it points to the start of the next ! block. (Zdist(K)-1) since already one X-Y layer has been added in.! Implicit assumption that SizeY = SUM( Ydist )! Counter1 = Counter1 + SizeX*SizeY*(Zdist(K)-1) ENDDO CPP_LEAVE_PROCEDURE( "DECOMPREGULAR3DORDER" ) RETURN!EOC END SUBROUTINE DecompRegular3DOrder!------------------------------------------------------------------------!------------------------------------------------------------------------!BOP! !IROUTINE: DecompCreateIrr --- Decomposition for an irregular mesh!! !INTERFACE: SUBROUTINE DecompCreateIrr( NPEs, Pe, TotalPts, Decomp )! !USES: IMPLICIT NONE!! !INPUT PARAMETERS: INTEGER, INTENT( IN ) :: NPEs ! Number of PEs INTEGER, INTENT( IN ) :: Pe(:) ! Processor location INTEGER, INTENT( IN ) :: TotalPts ! Number of points!! !OUTPUT PARAMETERS: TYPE(DecompType), INTENT( OUT ) :: Decomp ! Decomp information!
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?