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