modprocs.F90 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. module Agrif_Procs
  2. !
  3. implicit none
  4. !
  5. type Agrif_Proc
  6. integer :: pn !< Proc index in coarse grid
  7. integer :: pi !< Proc index in x-direction (informative only, could be removed)
  8. integer :: pj !< Proc index in y-direction (informative only, could be removed)
  9. integer, dimension(3) :: imin
  10. integer, dimension(3) :: imax
  11. integer :: nb_seqs = 0 !< Number of integration sequences the proc is attached to.
  12. integer :: grid_id = 0 !< Grid id the proc is attached to.
  13. end type Agrif_Proc
  14. !
  15. type Agrif_Proc_p
  16. type(Agrif_Proc), pointer :: proc => NULL() !< Pointer to the actual proc structure
  17. type(Agrif_Proc_p), pointer :: next => NULL() !< Next proc in the list
  18. end type Agrif_Proc_p
  19. !
  20. type Agrif_Proc_List
  21. integer :: nitems = 0 !< Number of elements in the list
  22. type(Agrif_Proc_p), pointer :: first => NULL() !< First proc in the list
  23. type(Agrif_Proc_p), pointer :: last => NULL() !< Last proc inserted in the list
  24. end type Agrif_Proc_List
  25. !
  26. contains
  27. !
  28. !===================================================================================================
  29. subroutine Agrif_pl_append ( proclist, proc )
  30. !---------------------------------------------------------------------------------------------------
  31. type(Agrif_Proc_List), intent(inout) :: proclist
  32. type(Agrif_Proc), pointer, intent(in) :: proc
  33. !
  34. type(Agrif_Proc_p), pointer :: new_pp
  35. !
  36. allocate( new_pp )
  37. !
  38. new_pp % proc => proc
  39. new_pp % next => NULL()
  40. !
  41. if ( associated(proclist % last) ) then
  42. ! the list is not empty, let 'proc' be the next after the last (ie. the last one).
  43. proclist % last % next => new_pp
  44. else
  45. ! the list has just been initialized. Let 'proc' be the first one.
  46. proclist % first => new_pp
  47. endif
  48. ! anyway, for next time 'proc' will be the last one.
  49. proclist % last => new_pp
  50. proclist % nitems = proclist % nitems + 1
  51. !---------------------------------------------------------------------------------------------------
  52. end subroutine Agrif_pl_append
  53. !===================================================================================================
  54. !
  55. !===================================================================================================
  56. subroutine Agrif_pl_print_array ( proclist )
  57. !---------------------------------------------------------------------------------------------------
  58. type(Agrif_Proc_List), intent(in) :: proclist
  59. !
  60. type(Agrif_Proc_p), pointer :: pp
  61. type(Agrif_Proc), pointer :: proc
  62. !
  63. pp => proclist % first
  64. !
  65. write(*,'("/-------+-----+-----+------+------+------+------+------\")')
  66. write(*,'("| iproc | ipx | ipy | imin | imax | jmin | jmax | grid |")')
  67. write(*,'("|-------+-----+-----+------+------+------+------+------|")')
  68. do while ( associated(pp) )
  69. proc => pp % proc
  70. write(*,'("|",i6," |",i4," |",i4," |",i5," :",i5," |",i5," :",i5," | ",i4," |")') &
  71. proc % pn, proc % pi, proc % pj, proc % imin(1), proc % imax(1), proc % imin(2), proc % imax(2), &
  72. proc % grid_id
  73. pp => pp % next
  74. enddo
  75. write(*,'("\-------+-----+-----+------+------+------+------+------/")')
  76. !---------------------------------------------------------------------------------------------------
  77. end subroutine Agrif_pl_print_array
  78. !===================================================================================================
  79. !
  80. !===================================================================================================
  81. subroutine Agrif_pl_print ( proclist )
  82. !---------------------------------------------------------------------------------------------------
  83. type(Agrif_Proc_List), intent(in) :: proclist
  84. !
  85. type(Agrif_Proc_p), pointer :: pp
  86. !
  87. pp => proclist % first
  88. do while ( associated(pp) )
  89. write(*,'(i0,",")',advance='no') pp % proc % pn
  90. pp => pp % next
  91. enddo
  92. write(*,*)
  93. !---------------------------------------------------------------------------------------------------
  94. end subroutine Agrif_pl_print
  95. !===================================================================================================
  96. !
  97. !===================================================================================================
  98. subroutine Agrif_pl_copy ( proclist, copy )
  99. !
  100. !< Carries out a copy of 'proclist' into 'copy'
  101. !---------------------------------------------------------------------------------------------------
  102. type(Agrif_Proc_List), intent(in) :: proclist
  103. type(Agrif_Proc_List), intent(out) :: copy
  104. !
  105. type(Agrif_Proc_p), pointer :: pp
  106. !
  107. call Agrif_pl_clear(copy)
  108. !
  109. pp => proclist % first
  110. do while ( associated(pp) )
  111. call Agrif_pl_append( copy, pp % proc )
  112. pp => pp % next
  113. enddo
  114. !---------------------------------------------------------------------------------------------------
  115. end subroutine Agrif_pl_copy
  116. !===================================================================================================
  117. !
  118. !===================================================================================================
  119. subroutine Agrif_pl_deep_copy ( proclist, copy )
  120. !
  121. !< Carries out a deep copy of 'proclist' into 'copy'
  122. !---------------------------------------------------------------------------------------------------
  123. type(Agrif_Proc_List), intent(in) :: proclist
  124. type(Agrif_Proc_List), intent(out) :: copy
  125. !
  126. type(Agrif_Proc_p), pointer :: pp
  127. type(Agrif_Proc), pointer :: new_proc
  128. !
  129. call Agrif_pl_clear(copy)
  130. !
  131. pp => proclist % first
  132. do while ( associated(pp) )
  133. allocate( new_proc )
  134. new_proc = pp % proc
  135. call Agrif_pl_append( copy, new_proc )
  136. pp => pp % next
  137. enddo
  138. !---------------------------------------------------------------------------------------------------
  139. end subroutine Agrif_pl_deep_copy
  140. !===================================================================================================
  141. !
  142. !===================================================================================================
  143. subroutine Agrif_pl_clear ( proclist )
  144. !---------------------------------------------------------------------------------------------------
  145. type(Agrif_Proc_List), intent(inout) :: proclist
  146. !
  147. type(Agrif_Proc_p), pointer :: pp, ppd
  148. !
  149. pp => proclist % first
  150. !
  151. do while( associated(pp) )
  152. ppd => pp
  153. pp => pp % next
  154. deallocate(ppd)
  155. enddo
  156. proclist % first => NULL()
  157. proclist % last => NULL()
  158. proclist % nitems = 0
  159. !---------------------------------------------------------------------------------------------------
  160. end subroutine Agrif_pl_clear
  161. !===================================================================================================
  162. !
  163. !===================================================================================================
  164. subroutine Agrif_pl_to_array ( proclist, procarray )
  165. !---------------------------------------------------------------------------------------------------
  166. type(Agrif_Proc_List), intent(in) :: proclist
  167. type(Agrif_Proc), dimension(:), allocatable, intent(out) :: procarray
  168. !
  169. type(Agrif_Proc_p), pointer :: pp
  170. !
  171. allocate( procarray(1:proclist % nitems) )
  172. !
  173. pp => proclist % first
  174. do while ( associated(pp) )
  175. procarray(pp%proc%pn+1) = pp % proc
  176. pp => pp % next
  177. enddo
  178. !---------------------------------------------------------------------------------------------------
  179. end subroutine Agrif_pl_to_array
  180. !===================================================================================================
  181. !
  182. !===================================================================================================
  183. function Agrif_pl_search_proc ( proclist, rank ) result ( proc )
  184. !---------------------------------------------------------------------------------------------------
  185. type(Agrif_Proc_List), intent(in) :: proclist
  186. integer, intent(in) :: rank
  187. !
  188. type(Agrif_Proc_p), pointer :: pp
  189. type(Agrif_Proc), pointer :: proc
  190. logical :: found
  191. !
  192. found = .false.
  193. proc => NULL()
  194. pp => proclist % first
  195. do while ( .not.found .and. associated(pp) )
  196. if ( pp % proc % pn == rank ) then
  197. proc => pp % proc
  198. return
  199. else
  200. pp => pp % next
  201. endif
  202. enddo
  203. !---------------------------------------------------------------------------------------------------
  204. end function Agrif_pl_search_proc
  205. !===================================================================================================
  206. !
  207. end module Agrif_Procs