dstmodel.F90 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. ! Math and Computer Science Division, Argonne National Laboratory !
  3. !-----------------------------------------------------------------------
  4. ! CVS dstmodel.F90,v 1.8 2006-10-17 21:47:56 jacob Exp
  5. ! CVS MCT_2_8_0
  6. !BOP -------------------------------------------------------------------
  7. !
  8. ! !MODULE: dstmodel -- generic model for sequential climate model
  9. !
  10. ! !DESCRIPTION:
  11. ! init run and finalize methods for destination model
  12. !
  13. ! !INTERFACE:
  14. !
  15. module dstmodel
  16. !
  17. ! !USES:
  18. !
  19. ! Get the things needed from MCT by "Use,only" with renaming:
  20. !
  21. !---Domain Decomposition Descriptor DataType and associated methods
  22. use m_GlobalSegMap,only: GlobalSegMap
  23. use m_GlobalSegMap,only: GlobalSegMap_init => init
  24. use m_GlobalSegMap,only: GlobalSegMap_lsize => lsize
  25. use m_GlobalSegMap,only: GlobalSegMap_clean => clean
  26. !---Field Storage DataType and associated methods
  27. use m_AttrVect,only : AttrVect
  28. use m_AttrVect,only : AttrVect_init => init
  29. use m_AttrVect,only : AttrVect_lsize => lsize
  30. use m_AttrVect,only : AttrVect_clean => clean
  31. use m_AttrVect,only : AttrVect_copy => copy
  32. use m_AttrVect,only : AttrVect_indxR => indexRA
  33. use m_AttrVect,only : AttrVect_importRAttr => importRAttr
  34. use m_AttrVectcomms,only : AttrVect_gather => gather
  35. ! Get things from MPEU
  36. use m_inpak90 ! Resource files
  37. use m_stdio ! I/O utils
  38. use m_ioutil
  39. ! Get utilities for this program.
  40. use mutils
  41. implicit none
  42. private
  43. ! except
  44. ! !PUBLIC MEMBER FUNCTIONS:
  45. !
  46. public dstinit
  47. public dstrun
  48. public dstfin
  49. ! module variables
  50. character(len=*), parameter :: modelname='dstmodel.F90'
  51. integer :: rank, lcomm
  52. !EOP -------------------------------------------------------------------
  53. contains
  54. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. ! Math and Computer Science Division, Argonne National Laboratory !
  56. !BOP -------------------------------------------------------------------
  57. !
  58. ! !IROUTINE: dstinit - Destination model initialization
  59. subroutine dstinit(GSMap,IMPORT,EXPORT,comm,compid)
  60. ! !INPUT PARAMETERS:
  61. type(GlobalSegMap),intent(inout) :: GSMap ! decomposition
  62. type(AttrVect),intent(inout) :: IMPORT,EXPORT ! state data
  63. integer,intent(in) :: comm ! MPI communicator
  64. integer,intent(in) :: compid ! component ID
  65. !
  66. !EOP ___________________________________________________________________
  67. ! local variables
  68. ! parameters for this model
  69. integer :: nxa ! number of points in x-direction
  70. integer :: nya ! number of points in y-direction
  71. integer :: i,j,k,idx
  72. integer :: nprocs, root, ier
  73. ! GlobalSegMap variables
  74. integer,dimension(:),pointer :: lindex
  75. ! AttrVect variables
  76. integer :: avsize
  77. character*2, ldecomp
  78. call MPI_COMM_RANK(comm,rank, ier)
  79. call MPI_COMM_SIZE(comm,nprocs,ier)
  80. ! save local communicator
  81. lcomm=comm
  82. if(rank==0) then
  83. write(6,*) modelname, ' init start'
  84. write(6,*) modelname,' MyID ', compid
  85. write(6,*) modelname,' Num procs ', nprocs
  86. endif
  87. ! Get configuration
  88. call i90_LoadF('dst.rc',ier)
  89. call i90_label('nx:',ier)
  90. nxa=i90_gint(ier)
  91. call i90_label('ny:',ier)
  92. nya=i90_gint(ier)
  93. if(rank==0) write(6,*) modelname, ' x,y ', nxa,nya
  94. call i90_label('decomp:',ier)
  95. call i90_Gtoken(ldecomp, ier)
  96. if(rank==0) write(6,*) modelname, ' decomp ', ldecomp
  97. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  98. ! Initialize a Global Segment Map
  99. call get_index(ldecomp,nprocs,rank,nxa,nya,lindex)
  100. call GlobalSegMap_init(GSMap,lindex,comm,compid,gsize=nxa*nya)
  101. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  102. if(rank==0) write(6,*) modelname, ' GSMap ',GSMap%ngseg,GSMap%gsize
  103. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  104. ! Initialize import and export Attribute vectors
  105. ! size is the number of grid points on this processor
  106. avsize = GlobalSegMap_lsize(GSMap,comm)
  107. if(rank==0) write(6,*) modelname, ' localsize ', avsize
  108. ! initialize Avs with two real attributes.
  109. call AttrVect_init(IMPORT,rList="field3:field4",lsize=avsize)
  110. call AttrVect_init(EXPORT,rList="field5:field6",lsize=avsize)
  111. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  112. if(rank==0) write(6,*) modelname, ' init done'
  113. end subroutine dstinit
  114. !!! END OF INIT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  115. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  116. ! RUN PHASE
  117. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  118. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119. ! Math and Computer Science Division, Argonne National Laboratory !
  120. !BOP -------------------------------------------------------------------
  121. !
  122. ! !IROUTINE: dstrun - Destination model run method
  123. subroutine dstrun(IMPORT,EXPORT)
  124. ! !INPUT PARAMETERS:
  125. type(AttrVect),intent(inout) :: IMPORT,EXPORT ! Input and Output states
  126. !EOP -------------------------------------------------------------------
  127. ! local variables
  128. integer :: avsize,ier,i,index
  129. if(rank==0) write(6,*) modelname, ' run start'
  130. ! Copy input data to output data using translation between different names
  131. call AttrVect_copy(IMPORT,EXPORT,rList="field3:field4", &
  132. TrList="field5:field6")
  133. if(rank==0) write(6,*) modelname, ' run done'
  134. end subroutine dstrun
  135. !!! END OF RUN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  136. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  137. ! FINALIZE PHASE
  138. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  139. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  140. ! Math and Computer Science Division, Argonne National Laboratory !
  141. !BOP -------------------------------------------------------------------
  142. !
  143. ! !IROUTINE: dstfin - Destination model finalize method
  144. subroutine dstfin(IMPORT,EXPORT,GSMap)
  145. ! !INPUT PARAMETERS:
  146. type(AttrVect),intent(inout) :: IMPORT,EXPORT ! MCT defined type
  147. type(GlobalSegMap),intent(inout) :: GSMap
  148. !EOP -------------------------------------------------------------------
  149. type(AttrVect) :: GlobalD
  150. integer :: lsize,ier,mdev,i
  151. if(rank==0) write(6,*) modelname,' fin start'
  152. ! gather data to node 0 and write it out
  153. call AttrVect_gather(EXPORT,GlobalD,GSMap,0,lcomm,ier)
  154. ! write out gathered data
  155. if(rank==0) then
  156. mdev=luavail()
  157. lsize=AttrVect_lsize(GlobalD)
  158. open(mdev, file="TS1out.dat")
  159. do i=1,lsize
  160. write(mdev,*) GlobalD%rAttr(1,i)
  161. enddo
  162. close(mdev)
  163. endif
  164. ! clean up
  165. call AttrVect_clean(IMPORT)
  166. call AttrVect_clean(EXPORT)
  167. if(rank==0)call AttrVect_clean(GlobalD)
  168. call GlobalSegMap_clean(GSMap)
  169. if(rank==0) write(6,*) modelname,' fin done'
  170. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  171. endsubroutine dstfin
  172. end module dstmodel