distributed_grids.F90 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. !
  2. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  3. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  4. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  5. !
  6. #include "tm5.inc"
  7. !-----------------------------------------------------------------------------
  8. ! TM5 !
  9. !-----------------------------------------------------------------------------
  10. !BOP
  11. !
  12. ! !MODULE: TM5_DISTGRID
  13. !
  14. ! !DESCRIPTION: hold, initialize, and finalize the distributed grid objects
  15. ! for each region of the model.
  16. !\\
  17. !\\
  18. ! !INTERFACE:
  19. !
  20. MODULE TM5_DISTGRID
  21. !
  22. ! !USES:
  23. !
  24. USE GO, ONLY : gol, goPr, goErr
  25. USE partools, ONLY : npes, myid
  26. USE dims, ONLY : nregions_all
  27. USE domain_decomp
  28. IMPLICIT NONE
  29. !
  30. ! !PUBLIC DATA MEMBERS:
  31. !
  32. TYPE(DIST_GRID), ALLOCATABLE :: DGRID(:) ! Distributed grid object for each regions
  33. !
  34. ! !PRIVATE DATA MEMBERS:
  35. !
  36. CHARACTER(len=*), PARAMETER, PRIVATE :: mname = 'TM5_DistGrid'
  37. !
  38. ! !REVISION HISTORY:
  39. ! 18 Jan 2012 - P. Le Sager - v0
  40. !
  41. ! !REMARKS:
  42. !
  43. ! (1) TM5_DGRID_INIT, TM5_DGRID_DONE are public life cycle method
  44. ! (2) inherits all public routines from DOMAIN_DECOMP (and keep them public)
  45. !EOP
  46. !------------------------------------------------------------------------
  47. CONTAINS
  48. !--------------------------------------------------------------------------
  49. ! TM5 !
  50. !--------------------------------------------------------------------------
  51. !BOP
  52. !
  53. ! !IROUTINE: dgrid_Init
  54. !
  55. ! !DESCRIPTION:
  56. !\\
  57. !\\
  58. ! !INTERFACE:
  59. !
  60. SUBROUTINE TM5_DGRID_INIT( rcfile, status )
  61. !
  62. ! !USES:
  63. !
  64. use GO, only : TrcFile, Init, Done, ReadRc
  65. use dims, only : okdebug
  66. USE partools, ONLY : TM5_MPI_INIT2
  67. !
  68. ! !INPUT PARAMETERS:
  69. !
  70. character(len=*), intent(in) :: rcfile
  71. !
  72. ! !OUTPUT PARAMETERS:
  73. !
  74. integer, intent(out) :: status
  75. !
  76. ! !REVISION HISTORY:
  77. ! 18 Jan 2012 - P. Le Sager -
  78. !
  79. !EOP
  80. !------------------------------------------------------------------------
  81. !BOC
  82. character(len=*), parameter :: rname = mname//'/TM5_DGrid_Init'
  83. integer :: id, n, npe_lon, npe_lat
  84. type(TrcFile) :: rcF
  85. ! distributed grids
  86. allocate(dgrid(nregions_all))
  87. ! get nprocs on each direction from rcfile
  88. ! ---------------------------------------
  89. call Init( rcF, rcfile, status )
  90. IF_NOTOK_RETURN(status=1)
  91. call ReadRc( rcF, 'par.nx', npe_lon, status )
  92. IF_NOTOK_RETURN(status=1)
  93. call ReadRc( rcF, 'par.ny', npe_lat, status )
  94. IF_NOTOK_RETURN(status=1)
  95. call Done( rcF, status )
  96. IF_NOTOK_RETURN(status=1)
  97. ! Sanity check (temporary: npes will be entirely determined by par.nx
  98. ! and par.ny in the future, when submit script reads them)
  99. if (npes /= npe_lat*npe_lon) then
  100. status=1
  101. write(gol,'("ERROR : total #proc (",i3,") .NE. Xproc*Yproc (",i3,"*",i3,")")') &
  102. npes, npe_lat, npe_lon; call goErr
  103. IF_NOTOK_RETURN(status=1)
  104. endif
  105. ! finish initialization of communicators
  106. ! ---------------------------------------
  107. call TM5_MPI_INIT2( npe_lon, npe_lat, status )
  108. IF_NOTOK_RETURN(status=1)
  109. ! initialize distributed grid objects
  110. ! ---------------------------------------
  111. do n=1,nregions_all
  112. CALL INIT_DISTGRID( dgrid(n), n, myid, npe_lon, npe_lat, halo=2, status=status )
  113. IF_NOTOK_RETURN(status=1)
  114. if (okdebug) then
  115. ! Test MPI domain decomposition communications
  116. call testcomm( dgrid(n), 0, status)
  117. IF_NOTOK_RETURN(status=1)
  118. call testcomm( dgrid(n), 1, status)
  119. IF_NOTOK_RETURN(status=1)
  120. call testcomm( dgrid(n), 2, status)
  121. IF_NOTOK_RETURN(status=1)
  122. call print_distgrid( dgrid(n) )
  123. end if
  124. end do
  125. status = 0
  126. END SUBROUTINE TM5_DGRID_INIT
  127. !EOC
  128. !--------------------------------------------------------------------------
  129. ! TM5 !
  130. !--------------------------------------------------------------------------
  131. !BOP
  132. !
  133. ! !IROUTINE: DGRID_DONE
  134. !
  135. ! !DESCRIPTION:
  136. !\\
  137. !\\
  138. ! !INTERFACE:
  139. !
  140. SUBROUTINE TM5_DGRID_DONE( status )
  141. !
  142. ! !OUTPUT PARAMETERS:
  143. !
  144. integer, intent(out) :: status
  145. !
  146. ! !REVISION HISTORY:
  147. ! 18 Jan 2012 - P. Le Sager -
  148. !
  149. !EOP
  150. !------------------------------------------------------------------------
  151. !BOC
  152. character(len=*), parameter :: rname = mname//'/TM5_DGrid_Done'
  153. integer :: n
  154. do n=1,nregions_all
  155. call Done_DistGrid( dgrid(n), status )
  156. IF_NOTOK_RETURN(status=1)
  157. end do
  158. deallocate( dgrid )
  159. status = 0
  160. END SUBROUTINE TM5_DGRID_DONE
  161. !EOC
  162. END MODULE TM5_DISTGRID