source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/lib/mct/examples/simple/twocmp.con.F90 @ 4775

Last change on this file since 4775 was 4775, checked in by aclsce, 5 years ago
  • Imported oasis3-mct from Cerfacs svn server (not suppotred anymore).

The version has been extracted from https://oasis3mct.cerfacs.fr/svn/branches/OASIS3-MCT_2.0_branch/oasis3-mct@1818

File size: 6.2 KB
Line 
1!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2!    Math and Computer Science Division, Argonne National Laboratory   !
3!-----------------------------------------------------------------------
4! CVS twocmp.con.F90,v 1.4 2006-07-25 22:31:34 jacob Exp
5! CVS MCT_2_8_0
6!BOP -------------------------------------------------------------------
7!
8! !ROUTINE:  twocomponent.concurrent
9!
10! !DESCRIPTION:  Provide a simple example of using MCT to connect two
11!  components executing concurrently in a single executable.
12
13!
14! !INTERFACE:
15!
16      program twocon
17!
18! !USES:
19!
20!--- Use only the things needed from MCT
21      use m_MCTWorld,only: MCTWorld_init => init
22
23      use m_GlobalSegMap,only: GlobalSegMap
24      use m_GlobalSegMap,only: MCT_GSMap_init => init
25      use m_GlobalSegMap,only: MCT_GSMap_lsize => lsize
26
27      use m_AttrVect,only    : AttrVect
28      use m_AttrVect,only    : MCT_AtrVt_init => init
29      use m_AttrVect,only    : MCT_AtrVt_zero => zero
30      use m_AttrVect,only    : MCT_AtrVt_lsize => lsize
31      use m_AttrVect,only    : MCT_AtrVt_indexRA => indexRA
32      use m_AttrVect,only    : MCT_AtrVt_importRA => importRAttr
33
34      use m_Router,only: Router
35      use m_Router,only: MCT_Router_init => init
36
37      use m_Transfer,only : MCT_Send => send
38      use m_Transfer,only : MCT_Recv => recv
39
40      implicit none
41
42      include 'mpif.h'
43!-----------------------------------------------------------------------
44      ! Local variables
45
46      integer,parameter :: npoints = 24  ! number of grid points
47
48      integer ier,nprocs
49      integer color,myrank,mycomm
50!-----------------------------------------------------------------------
51!  The Main program.
52! We are implementing a single-executable, concurrent-execution system.
53! This small main program carves up MPI_COMM_WORLD and then starts
54! each component on its own processor set.
55
56      call MPI_init(ier)
57
58      call mpi_comm_size(MPI_COMM_WORLD, nprocs,ier)
59      call mpi_comm_rank(MPI_COMM_WORLD, myrank,ier)
60
61      if((nprocs .gt. 14).or.(nprocs .lt. 3)) then
62        write(6,*)"The small problem size in this example &
63        &requires between 3 and 14 processors."
64        write(6,*)"nprocs =",nprocs
65        stop
66      endif
67
68
69!  Force the model1 to run on the first 2 processors
70      color =1
71      if (myrank .lt. 2) then
72        color = 0
73      endif
74
75! Split MPI_COMM_WORLD into a communicator for each model
76      call mpi_comm_split(MPI_COMM_WORLD,color,0,mycomm,ier)
77
78! Start up the the models, pass in the communicators
79      if(color .eq. 0) then
80       call model1(mycomm)
81      else
82       call model2(mycomm)
83      endif
84
85! Models are finished.
86      call mpi_finalize(ier)
87
88      contains
89
90!-----------------------------------------------------------------------
91!-----------------------------------------------------------------------
92! !ROUTINE:
93      subroutine model1(comm1)   ! the first model
94
95      implicit none
96
97      integer :: comm1,mysize,ier,asize,myproc
98      integer :: fieldindx,avsize,i
99      integer,dimension(1) :: start,length
100      real,pointer :: testarray(:)
101     
102      type(GlobalSegMap) :: GSmap
103      type(AttrVect) :: av1
104      type(Router) :: Rout
105!---------------------------
106
107!  find local rank and size
108      call mpi_comm_size(comm1,mysize,ier)
109      call mpi_comm_rank(comm1,myproc,ier)
110      write(6,*)"model1 size",mysize
111
112!  initialize ThisMCTWorld
113      call MCTWorld_init(2,MPI_COMM_WORLD,comm1,1)
114
115!  set up a grid and decomposition
116      asize =  npoints/mysize
117
118      start(1)= (myproc*asize) +1
119      length(1)=asize
120
121!  describe decomposition with MCT GSmap type
122      call MCT_GSMap_init(GSMap,start,length,0,comm1,1)
123
124      write(6,*)"model 1 GSMap ngseg",myproc,GSMap%ngseg,start(1)
125
126!  Initialize an Attribute Vector
127      call MCT_AtrVt_init(av1,rList="field1:field2",lsize=MCT_GSMap_lsize(GSMap,comm1))
128
129      avsize = MCT_AtrVt_lsize(av1)
130      write(6,*)"model 1 av size", avsize
131
132!  Fill Av with some data
133!  fill first attribute the direct way
134      fieldindx = MCT_AtrVt_indexRA(av1,"field1")
135      do i=1,avsize
136        av1%rAttr(fieldindx,i) = float(i)
137      enddo
138
139!  fill second attribute using Av import function
140      allocate(testarray(avsize))
141      do i=1,avsize
142        testarray(i)= cos((float(i)/npoints) * 3.14)
143      enddo
144      call MCT_AtrVt_importRA(av1,"field2",testarray)
145
146!  initialize a Router
147      call MCT_Router_init(2,GSMap,comm1,Rout)
148
149!  print out Av data
150      do i=1,asize
151        write(6,*) "model 1 data", myproc,i,av1%rAttr(1,i),av1%rAttr(2,i)
152      enddo
153     
154!  send the data
155      call MCT_Send(av1,Rout)
156
157
158
159      end subroutine model1
160
161!-----------------------------------------------------------------------
162!-----------------------------------------------------------------------
163! !ROUTINE:
164      subroutine model2(comm2)
165
166      implicit none
167
168      integer :: comm2,mysize,ier,asize,myproc
169      integer :: i
170      integer,dimension(1) :: start,length
171      type(GlobalSegMap) :: GSmap
172      type(AttrVect) :: av1
173      type(Router)   :: Rout
174!---------------------------
175
176!  find local rank and size
177      call mpi_comm_size(comm2,mysize,ier)
178      call mpi_comm_rank(comm2,myproc,ier)
179      write(6,*)"model2 size",mysize
180
181!  initialize ThisMCTWorld
182      call MCTWorld_init(2,MPI_COMM_WORLD,comm2,2)
183
184!  set up a grid and decomposition
185      asize =  npoints/mysize
186
187      start(1)= (myproc*asize) +1
188      length(1)=asize
189
190!  describe decomposition with MCT GSmap type
191      call MCT_GSMap_init(GSMap,start,length,0,comm2,2)
192
193      write(6,*)"model 2 GSMap ngseg",myproc,GSMap%ngseg,start(1)
194
195!  Initialize an Attribute Vector
196      call MCT_AtrVt_init(av1,rList="field1:field2",lsize=MCT_GSMap_lsize(GSMap,comm2))
197
198      write(6,*)"model 2 av size", MCT_AtrVt_lsize(av1)
199
200! initialize Av to be zero everywhere
201      call MCT_AtrVt_zero(av1)
202
203!  initialize a Router
204      call MCT_Router_init(1,GSMap,comm2,Rout)
205
206!  print out Av data before Recv
207      do i=1,asize
208        write(6,*) "model 2 data", myproc,i,av1%rAttr(1,i),av1%rAttr(2,i)
209      enddo
210
211!  Recv the data
212      call MCT_Recv(av1,Rout)
213
214!  print out Av data after Recv.
215      do i=1,asize
216        write(6,*) "model 2 data after", myproc,i,av1%rAttr(1,i),av1%rAttr(2,i)
217      enddo
218
219
220      end subroutine model2
221
222      end
Note: See TracBrowser for help on using the repository browser.