master.F90 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. ! Math and Computer Science Division, Argonne National Laboratory !
  3. !-----------------------------------------------------------------------
  4. ! CVS master.F90,v 1.5 2009-02-23 23:22:47 jacob Exp
  5. ! CVS MCT_2_8_0
  6. !BOP -------------------------------------------------------------------
  7. !
  8. ! !PROGRAM: master -- driver for sequential coupled model example
  9. !
  10. ! !DESCRIPTION: Provide a simple example of using MCT to connect to
  11. ! components executing sequentially in a single executable.
  12. !
  13. program master
  14. !
  15. ! !USES:
  16. !
  17. use m_AttrVect,only : AttrVect
  18. use m_GlobalSegMap,only: GlobalSegMap
  19. use m_MCTWorld,only: MCTWorld_init => init
  20. use srcmodel
  21. use dstmodel
  22. use coupler
  23. implicit none
  24. include "mpif.h"
  25. !
  26. !EOP -------------------------------------------------------------------
  27. ! local variables
  28. character(len=*), parameter :: mastername='master.F90'
  29. integer :: ncomps = 3 ! Must know total number of
  30. ! components in coupled system
  31. integer,dimension(:),pointer :: comps ! array with component ids
  32. type(AttrVect) :: srcImp,srcExp ! import and export states for src and
  33. type(AttrVect) :: dstImp,dstExp ! destination models
  34. type(GlobalSegMap) :: srcGSMap ! decomposition descriptors for src and
  35. type(GlobalSegMap) :: dstGSMap ! desitnation models
  36. ! other variables
  37. integer :: comm1, comm2, rank, nprocs,compid, myID, ier,color
  38. integer :: anprocs,cnprocs
  39. !-----------------------------------------------------------------------
  40. ! The Main program.
  41. ! We are implementing a single-executable, sequential-execution system.
  42. !
  43. ! This main program initializes MCT and runs the whole model.
  44. ! Initialize MPI
  45. call MPI_INIT(ier)
  46. ! Get basic MPI information
  47. call MPI_COMM_SIZE(MPI_COMM_WORLD,nprocs,ier)
  48. call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ier)
  49. ! Get communicators for each model
  50. call mpi_comm_dup(MPI_COMM_WORLD,comm1,ier)
  51. call mpi_comm_dup(MPI_COMM_WORLD,comm2,ier)
  52. ! Initialize MCT
  53. allocate(comps(ncomps),stat=ier)
  54. comps(1)=1
  55. comps(2)=2
  56. comps(3)=3
  57. call MCTWorld_init(ncomps,MPI_COMM_WORLD,comm1,myids=comps)
  58. ! Initialize the model
  59. call srcinit(srcGSMap,srcImp,srcExp,comm1,1)
  60. call dstinit(dstGSMap,dstImp,dstExp,comm2,2)
  61. call cplinit(srcGSMap,dstGSMap,comm1,3)
  62. ! Run the model
  63. ! source does something with srcImp and produces export
  64. call srcrun(srcImp,srcExp)
  65. ! map the source model's Export to the destination model's Import
  66. call cplrun(srcExp,dstImp)
  67. ! destination model does something with dstImp
  68. call dstrun(dstImp,dstExp)
  69. ! Finalize
  70. call srcfin(srcImp,srcExp,srcGSMap)
  71. call dstfin(dstImp,dstExp,dstGSMap)
  72. call cplfin
  73. call MPI_FINALIZE(ier)
  74. end program master