source: CPL/oasis3-mct/branches/OASIS3-MCT_5.0_branch/lib/mct/benchmarks/RouterTestOvr.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.1 KB
Line 
1
2!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3!    Math and Computer Science Division, Argonne National Laboratory   !
4!-----------------------------------------------------------------------
5!BOP -------------------------------------------------------------------
6!
7! !PROGRAM: RouterTestOvr - Test building a router.
8!
9!
10! !DESCRIPTION:  Test building a router from output GSMaps on
11! overlapping processors
12!
13program RouterTestOvr
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
32  implicit none
33
34  include "mpif.h"
35
36!
37!EOP -------------------------------------------------------------------
38
39!     local variables
40
41  character(len=*), parameter :: myname_='RouterTestOvr'
42
43  integer :: ncomps = 2   ! Must know total number of
44                         ! components in coupled system
45
46  integer,dimension(:),pointer :: comps  ! array with component ids
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="gx1.8pR"
72  filename2="gx1.8pC"
73
74! open up the two files with the GSMap information.
75! and read the total number of processors needed
76
77  if(rank == 0) then
78   mdev1 = luavail()
79   open(mdev1,file=trim(filename1),status='old')
80
81   mdev2 = luavail()
82   open(mdev2,file=trim(filename2),status='old')
83
84
85   read(mdev1,*) nprocs1
86   read(mdev2,*) nprocs2
87
88
89!  Need to have enough processors.
90   if(nprocs .lt. max(nprocs1,nprocs2)) then
91     write(0,*)"Wrong processor count for 2 overlapping communicators."
92     write(0,*)"Need",max(nprocs1,nprocs2),"got",nprocs
93     call die("main","nprocs check")
94   endif
95   close(mdev1)
96   close(mdev2)
97  endif
98
99  call MPI_BCAST(nprocs1,1,MP_INTEGER,0,MPI_COMM_WORLD,ier)
100  call MPI_BCAST(nprocs2,1,MP_INTEGER,0,MPI_COMM_WORLD,ier)
101
102  call mpi_comm_dup(MPI_COMM_WORLD,comm1,ier)
103  call mpi_comm_dup(MPI_COMM_WORLD,comm2,ier)
104
105! Initialize MCT
106  allocate(comps(ncomps),stat=ier)
107  comps(1)=1
108  comps(2)=2
109  call MCTWorld_init(ncomps,MPI_COMM_WORLD,comm1,myids=comps)
110
111
112
113! *******************************
114!  Component 1
115! *******************************
116  call MPI_COMM_RANK(comm1,lrank,ier)
117
118! on non-root proccessors, allocate with length 1
119    if(lrank .ne. 0) then
120
121     allocate(root_start(1), root_length(1), &
122             root_pe_loc(1), stat=ier)
123     if (ier /= 0) then
124     call die(myname_, 'allocate((non)root_start...',ier)
125     endif
126    endif
127
128    if(lrank == 0) then
129      mdev1 = luavail()
130      open(mdev1,file=trim(filename1),status='old')
131      read(mdev1,*) junk
132      read(mdev1,*) junk
133      read(mdev1,*) ngseg
134      read(mdev1,*) gsize
135      allocate(root_start(ngseg), root_length(ngseg), &
136             root_pe_loc(ngseg), stat=ier)
137      if (ier /= 0) then
138        call die(myname_, 'allocate((non)root_start...',ier)
139      endif
140      do n=1,ngseg
141        read(mdev1,*) root_start(n),root_length(n), &
142                         root_pe_loc(n)
143      enddo
144    endif
145
146! initalize the GSMap from root
147   call GSMap_init(comp1GSMap, ngseg, root_start, root_length, &
148              root_pe_loc, 0, comm1, 1)
149
150   deallocate(root_start,root_length,root_pe_loc)
151
152! *******************************
153!  Component 2
154! *******************************
155    call MPI_COMM_RANK(comm2,lrank,ier)
156
157! on non-root proccessors, allocate with length 1
158    if(lrank .ne. 0) then
159
160     allocate(root_start(1), root_length(1), &
161             root_pe_loc(1), stat=ier)
162     if (ier /= 0) then
163     call die(myname_, 'allocate((non)root_start...',ier)
164     endif
165    endif
166
167    if(lrank == 0) then
168      mdev2 = luavail()
169      open(mdev2,file=trim(filename2),status='old')
170      read(mdev2,*) junk
171      read(mdev2,*) junk
172      read(mdev2,*) ngseg
173      read(mdev2,*) gsize
174      allocate(root_start(ngseg), root_length(ngseg), &
175             root_pe_loc(ngseg), stat=ier)
176      if (ier /= 0) then
177        call die(myname_, 'allocate((non)root_start...',ier)
178      endif
179      do n=1,ngseg
180        read(mdev2,*) root_start(n),root_length(n), &
181                         root_pe_loc(n)
182      enddo
183    endif
184
185! initalize the GSMap from root
186    call GSMap_init(comp2GSMap, ngseg, root_start, root_length, &
187              root_pe_loc, 0, comm2, 2)
188
189! now initialize the Router
190  call Router_init(comp1GSMap,comp2GSMap,comm1,myRout,"Over")
191
192
193  call MPI_Finalize(ier)
194
195end program RouterTestOvr
Note: See TracBrowser for help on using the repository browser.