source: CPL/oasis3-mct/branches/OASIS3-MCT_5.0_branch/lib/mct/benchmarks/RouterTestDis.F90 @ 6331

Last change on this file since 6331 was 6331, checked in by aclsce, 17 months ago

Moved oasis-mct_5.0 in oasis3-mct/branches directory.

File size: 5.3 KB
Line 
1
2!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3!    Math and Computer Science Division, Argonne National Laboratory   !
4!-----------------------------------------------------------------------
5!BOP -------------------------------------------------------------------
6!
7! !PROGRAM: RouterTestDis - Test building a router.
8!
9!
10! !DESCRIPTION:  Test building a router from output GSMaps on
11! 2 disjoint sets of processors.
12!
13program RouterTestDis
14
15!
16! !USES:
17!
18
19  use m_GlobalSegMap,only: GlobalSegMap
20  use m_GlobalSegMap,only: GSMap_init => init
21  use m_GlobalSegMap,only: GSMap_lsize => lsize
22
23  use m_Router,only:  Router
24  use m_Router,only:  Router_init => init
25
26  use m_MCTWorld,only: MCTWorld_init => init
27  use m_ioutil,       only : luavail
28  use m_stdio,        only : stdout,stderr
29  use m_die,          only : die
30  use m_mpif90
31  use m_zeit
32
33  implicit none
34
35  include "mpif.h"
36
37!
38!EOP -------------------------------------------------------------------
39
40!     local variables
41
42  character(len=*), parameter :: myname_='RouterTestDis'
43
44  integer,dimension(:),pointer :: comps  ! array with component ids
45
46
47
48  type(GlobalSegMap) :: comp1GSMap
49  type(GlobalSegMap) :: comp2GSMap
50  type(Router)       :: myRout
51
52! other variables
53  integer :: comm1, comm2, rank, nprocs,compid, myID, ier,color
54  integer :: mdev1, mdev2, nprocs1,nprocs2,ngseg,gsize
55  character*24 :: filename1, filename2
56  integer :: lrank,newcomm,n,junk
57  integer, dimension(:), allocatable :: root_start, root_length, root_pe_loc
58
59!-----------------------------------------------------------------------
60! The Main program.
61!
62! This main program initializes MCT
63
64! Initialize MPI
65  call MPI_INIT(ier)
66
67! Get basic MPI information
68  call MPI_COMM_SIZE(MPI_COMM_WORLD,nprocs,ier)
69  call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ier)
70
71  filename1="T42.8pR"
72  filename2="T42.8pC"
73
74! open up the two files with the GSMap information.
75
76  if(rank == 0) then
77   mdev1 = luavail()
78   open(mdev1,file=trim(filename1),status='old')
79
80   mdev2 = luavail()
81   open(mdev2,file=trim(filename2),status='old')
82
83
84   read(mdev1,*) nprocs1
85   read(mdev2,*) nprocs2
86
87
88!  This is the disjoint test so need to have enough processors.
89   if(nprocs1+nprocs2 .ne. nprocs) then
90     write(0,*)"Wrong processor count for exactly 2 disjoint communicators."
91     write(0,*)"Need",nprocs1+nprocs2,"got",nprocs
92     call die("main","nprocs check")
93   endif
94   close(mdev1)
95   close(mdev2)
96  endif
97
98  call MPI_BCAST(nprocs1,1,MP_INTEGER,0,MPI_COMM_WORLD,ier)
99  call MPI_BCAST(nprocs2,1,MP_INTEGER,0,MPI_COMM_WORLD,ier)
100
101! Split world into 2 pieces for each component
102  color=0
103  if(rank < nprocs1) color=1
104
105  call MPI_COMM_SPLIT(MPI_COMM_WORLD,color,rank,newcomm,ier)
106
107! *******************************
108!  Component 1
109! *******************************
110  if(color == 0) then
111    call MPI_COMM_RANK(newcomm,lrank,ier)
112
113!  build an MCTWorld with 2 components
114    call MCTWorld_init(2,MPI_COMM_WORLD,newcomm,1)
115
116! on non-root proccessors, allocate with length 1
117    if(lrank .ne. 0) then
118
119     allocate(root_start(1), root_length(1), &
120             root_pe_loc(1), stat=ier)
121     if (ier /= 0) then
122     call die(myname_, 'allocate((non)root_start...',ier)
123     endif
124    endif
125
126    if(lrank == 0) then
127      mdev1 = luavail()
128      open(mdev1,file=trim(filename1),status='old')
129      read(mdev1,*) junk
130      read(mdev1,*) junk
131      read(mdev1,*) ngseg
132      read(mdev1,*) gsize
133      allocate(root_start(ngseg), root_length(ngseg), &
134             root_pe_loc(ngseg), stat=ier)
135      if (ier /= 0) then
136        call die(myname_, 'allocate((non)root_start...',ier)
137      endif
138      do n=1,ngseg
139        read(mdev1,*) root_start(n),root_length(n), &
140                         root_pe_loc(n)
141      enddo
142    endif
143
144! initalize the GSMap from root
145   call GSMap_init(comp1GSMap, ngseg, root_start, root_length, &
146              root_pe_loc, 0, newcomm, 1)
147
148
149! initalize the Router with component 2
150   call Router_init(2,comp1GSMap,newcomm,myRout,"Dis1")
151   call zeit_allflush(newcomm,0,6)
152
153! *******************************
154!  Component 2
155! *******************************
156  else
157    call MPI_COMM_RANK(newcomm,lrank,ier)
158
159!  build an MCTWorld with 2 components
160    call MCTWorld_init(2,MPI_COMM_WORLD,newcomm,2)
161! on non-root proccessors, allocate with length 1
162    if(lrank .ne. 0) then
163
164     allocate(root_start(1), root_length(1), &
165             root_pe_loc(1), stat=ier)
166     if (ier /= 0) then
167     call die(myname_, 'allocate((non)root_start...',ier)
168     endif
169    endif
170
171    if(lrank == 0) then
172      mdev2 = luavail()
173      open(mdev2,file=trim(filename2),status='old')
174      read(mdev2,*) junk
175      read(mdev2,*) junk
176      read(mdev2,*) ngseg
177      read(mdev2,*) gsize
178      allocate(root_start(ngseg), root_length(ngseg), &
179             root_pe_loc(ngseg), stat=ier)
180      if (ier /= 0) then
181        call die(myname_, 'allocate((non)root_start...',ier)
182      endif
183      do n=1,ngseg
184        read(mdev2,*) root_start(n),root_length(n), &
185                         root_pe_loc(n)
186      enddo
187    endif
188
189! initalize the GSMap from root
190    call GSMap_init(comp2GSMap, ngseg, root_start, root_length, &
191              root_pe_loc, 0, newcomm, 2)
192
193! initalize the Router with component 1
194   call Router_init(1,comp2GSMap,newcomm,myRout,"Dis2")
195   call zeit_allflush(newcomm,0,6)
196  endif
197
198  call MPI_Finalize(ier)
199
200end program RouterTestDis
Note: See TracBrowser for help on using the repository browser.