1 |
jmc |
1.1 |
!======================================================================= |
2 |
|
|
subroutine MITCPLR_init1( myTypeStr, couplerFlag ) |
3 |
|
|
implicit none |
4 |
|
|
|
5 |
|
|
! Arguments |
6 |
|
|
character*(*) myTypeStr |
7 |
|
|
logical couplerFlag |
8 |
|
|
|
9 |
|
|
! MPI variables |
10 |
|
|
#include "mpif.h" |
11 |
|
|
integer myid, numprocs, ierr, rc |
12 |
|
|
|
13 |
|
|
|
14 |
|
|
! Predefined constants/arrays |
15 |
|
|
#include "CPLR_SIG.h" |
16 |
|
|
|
17 |
|
|
! Functions |
18 |
|
|
integer mitcplr_match_comp |
19 |
|
|
|
20 |
|
|
! Local |
21 |
|
|
integer n,j |
22 |
|
|
integer MPI_GROUP_World |
23 |
|
|
integer MPI_GROUP_Tmp |
24 |
|
|
integer lenbuf |
25 |
|
|
integer compind |
26 |
|
|
character*(MAXLEN_COMP_NAME) cbuf |
27 |
|
|
|
28 |
|
|
! ------------------------------------------------------------------ |
29 |
|
|
|
30 |
|
|
! Find-out my position (rank) in the "world" communicator |
31 |
|
|
call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr ) |
32 |
|
|
if (ierr.ne.0) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
33 |
|
|
& ' Rank = ',myid,' MPI_COMM_RANK ierr=',ierr |
34 |
|
|
! How big is the "world"? |
35 |
|
|
call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr ) |
36 |
|
|
if (ierr.ne.0) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
37 |
|
|
& ' Size = ',numprocs,' MPI_COMM_RANK ierr=',ierr |
38 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
39 |
|
|
& ' Rank/Size = ',myid,' /',numprocs |
40 |
|
|
|
41 |
|
|
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
42 |
|
|
|
43 |
|
|
! Registration: collect/bcast lists of who is who |
44 |
|
|
|
45 |
|
|
! Assume nothing |
46 |
|
|
num_components = 0 |
47 |
|
|
num_coupler_procs = 0 |
48 |
|
|
|
49 |
|
|
! Receive a message from each of the other processes |
50 |
|
|
do n=0,numprocs-1 |
51 |
|
|
ibuf(1)=myid |
52 |
|
|
ibuf(2)=0 |
53 |
|
|
if ( couplerFlag ) ibuf(2)=MITCPLR_COUPLER |
54 |
|
|
ibuf(3)=0 |
55 |
|
|
ibuf(4)=0 |
56 |
|
|
ibuf(5)=0 |
57 |
|
|
ibuf(6)=0 |
58 |
|
|
ibuf(7)=0 |
59 |
|
|
call mitcplr_char2int( myTypeStr, ibuf(8) ) |
60 |
|
|
lenbuf=8+MAXLEN_COMP_NAME |
61 |
|
|
call MPI_Bcast( |
62 |
|
|
& ibuf, lenbuf, MPI_INTEGER, |
63 |
|
|
& n, |
64 |
|
|
& MPI_COMM_WORLD, ierr ) |
65 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
66 |
|
|
& ' MPI_Bcast from ',ibuf(1),ibuf(2),' ierr=',ierr |
67 |
|
|
call mitcplr_int2char( ibuf(8), cbuf ) |
68 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
69 |
|
|
& ' Bcast cbuf=',cbuf,'x' |
70 |
|
|
|
71 |
|
|
if ( ibuf(2).eq.MITCPLR_COUPLER ) then |
72 |
|
|
! If the broadcaster is the "coupler" |
73 |
|
|
num_coupler_procs=num_coupler_procs + 1 |
74 |
|
|
rank_coupler_procs(num_coupler_procs) = ibuf(1) |
75 |
|
|
coupler_Name=cbuf |
76 |
|
|
else |
77 |
|
|
! If the broadcaster is a "component" |
78 |
|
|
compind=mitcplr_match_comp( cbuf ) |
79 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
80 |
|
|
& ' compind=',compind |
81 |
|
|
num_component_procs(compind)=num_component_procs(compind) + 1 |
82 |
|
|
j=num_component_procs(compind) |
83 |
|
|
rank_component_procs(j,compind)=ibuf(1) |
84 |
|
|
endif |
85 |
|
|
|
86 |
|
|
enddo |
87 |
|
|
|
88 |
|
|
if ( num_coupler_procs .ne. 1 ) then |
89 |
|
|
stop 'MITCPLR_init1: I can only handle one coupler process' |
90 |
|
|
endif |
91 |
|
|
|
92 |
|
|
do compind=1,num_components |
93 |
|
|
num_compcplr_procs(compind)=num_component_procs(compind) + 1 |
94 |
|
|
do j=1,num_compcplr_procs(compind) |
95 |
|
|
rank_compcplr_procs(j,compind)=rank_component_procs(j,compind) |
96 |
|
|
enddo |
97 |
|
|
j=num_compcplr_procs(compind) |
98 |
|
|
rank_compcplr_procs(j,compind)=rank_coupler_procs(1) |
99 |
|
|
call mitcplr_sortranks( j, rank_compcplr_procs(1,compind) ) |
100 |
|
|
enddo |
101 |
|
|
|
102 |
|
|
|
103 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
104 |
|
|
& ' coupler=',coupler_Name, |
105 |
|
|
& ( rank_coupler_procs(j),j=1,num_coupler_procs ) |
106 |
|
|
do n=1,num_components |
107 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
108 |
|
|
& ' component=',component_Name(n), |
109 |
|
|
& ( rank_component_procs(j,n),j=1,num_component_procs(n) ) |
110 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
111 |
|
|
& ' comp+cplr=',component_Name(n), |
112 |
|
|
& ( rank_compcplr_procs(j,n),j=1,num_compcplr_procs(n) ) |
113 |
|
|
enddo |
114 |
|
|
|
115 |
|
|
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
116 |
|
|
|
117 |
|
|
! Create new groups and communicators |
118 |
|
|
|
119 |
|
|
! Establish MPI_GROUP_World associated with MPI_COMM_WORLD |
120 |
|
|
call MPI_Comm_group( MPI_COMM_WORLD, MPI_GROUP_World, ierr ) |
121 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
122 |
|
|
& ' MPI_Comm_group MPI_GROUP_World=',MPI_GROUP_World, |
123 |
|
|
& ' ierr=',ierr |
124 |
|
|
|
125 |
|
|
do n=1,num_components |
126 |
|
|
|
127 |
|
|
! Create group MPI_GROUP_Tmp |
128 |
|
|
call MPI_Group_incl( |
129 |
|
|
& MPI_GROUP_World, |
130 |
|
|
& num_component_procs(n), |
131 |
|
|
& rank_component_procs(1,n), |
132 |
|
|
& MPI_GROUP_Tmp, |
133 |
|
|
& ierr ) |
134 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
135 |
|
|
& ' MPI_Group_incl MPI_GROUP_Tmp=', |
136 |
|
|
& MPI_GROUP_Tmp,' ierr=',ierr |
137 |
|
|
|
138 |
|
|
! Create communicator MPI_COMM_component |
139 |
|
|
call MPI_Comm_create( |
140 |
|
|
& MPI_COMM_WORLD, |
141 |
|
|
& MPI_GROUP_Tmp, |
142 |
|
|
& MPI_COMM_component(n), |
143 |
|
|
& ierr ) |
144 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
145 |
|
|
& ' MPI_Comm_create MPI_COMM_component=',MPI_COMM_component(n), |
146 |
|
|
& ' ierr=',ierr |
147 |
|
|
|
148 |
|
|
! Create group MPI_GROUP_Tmp |
149 |
|
|
call MPI_Group_incl( |
150 |
|
|
& MPI_GROUP_World, |
151 |
|
|
& num_compcplr_procs(n), |
152 |
|
|
& rank_compcplr_procs(1,n), |
153 |
|
|
& MPI_GROUP_Tmp, |
154 |
|
|
& ierr ) |
155 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
156 |
|
|
& ' MPI_Group_incl MPI_GROUP_Tmp=', |
157 |
|
|
& MPI_GROUP_Tmp,' ierr=',ierr |
158 |
|
|
|
159 |
|
|
! Create communicator MPI_COMM_compcplr |
160 |
|
|
call MPI_Comm_create( |
161 |
|
|
& MPI_COMM_WORLD, |
162 |
|
|
& MPI_GROUP_Tmp, |
163 |
|
|
& MPI_COMM_compcplr(n), |
164 |
|
|
& ierr ) |
165 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
166 |
|
|
& ' MPI_Comm_create MPI_COMM_compcplr=',MPI_COMM_compcplr(n), |
167 |
|
|
& ' ierr=',ierr |
168 |
|
|
|
169 |
|
|
enddo |
170 |
|
|
|
171 |
|
|
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
172 |
|
|
|
173 |
|
|
if ( couplerFlag ) then |
174 |
|
|
my_component_ind=-1 |
175 |
|
|
MPI_COMM_mylocal=MPI_COMM_World |
176 |
|
|
MPI_COMM_myglobal=MPI_COMM_World |
177 |
|
|
my_component_name=coupler_Name |
178 |
|
|
else |
179 |
|
|
compind=mitcplr_match_comp( myTypeStr ) |
180 |
|
|
my_component_ind=compind |
181 |
|
|
MPI_COMM_mylocal=MPI_COMM_component( compind ) |
182 |
|
|
MPI_COMM_myglobal=MPI_COMM_compcplr( compind ) |
183 |
|
|
my_component_name=component_Name( compind ) |
184 |
|
|
endif |
185 |
|
|
|
186 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
187 |
|
|
& ' component num=',compind, |
188 |
|
|
& ' MPI_COMM=',MPI_COMM_mylocal,MPI_COMM_myglobal |
189 |
|
|
|
190 |
|
|
if ( couplerFlag ) then |
191 |
|
|
do n=1,num_components |
192 |
|
|
! Find-out my position (rank) in the "global" communicator |
193 |
|
|
call MPI_COMM_RANK( MPI_COMM_compcplr(n), j, ierr ) |
194 |
|
|
if (ierr.ne.0) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
195 |
|
|
& ' Rank = ',j,' MPI_COMM_RANK ierr=',ierr |
196 |
|
|
! How big is the "global" communicator? |
197 |
|
|
call MPI_COMM_SIZE( MPI_COMM_compcplr(n), numprocs, ierr ) |
198 |
|
|
if (ierr.ne.0) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
199 |
|
|
& ' Size = ',numprocs,' MPI_COMM_SIZE ierr=',ierr |
200 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
201 |
|
|
& ' Rank/Size = ',j,' /',numprocs, |
202 |
|
|
& ' in Component =',n |
203 |
|
|
enddo |
204 |
|
|
else |
205 |
|
|
! Find-out my position (rank) in the "global" communicator |
206 |
|
|
call MPI_COMM_RANK( MPI_COMM_myglobal, j, ierr ) |
207 |
|
|
if (ierr.ne.0) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
208 |
|
|
& ' Rank = ',j,' MPI_COMM_RANK ierr=',ierr |
209 |
|
|
! How big is the "global" communicator? |
210 |
|
|
call MPI_COMM_SIZE( MPI_COMM_myglobal, numprocs, ierr ) |
211 |
|
|
if (ierr.ne.0) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
212 |
|
|
& ' Size = ',numprocs,' MPI_COMM_SIZE ierr=',ierr |
213 |
|
|
if (DEBUG) write(0,*) 'MITCPLR_init1: ',myid,' ',myTypeStr, |
214 |
|
|
& ' Rank/Size = ',j,' /',numprocs |
215 |
|
|
endif |
216 |
|
|
|
217 |
|
|
! Open log file |
218 |
|
|
if ( couplerFlag ) j=myid |
219 |
|
|
write(cbuf(1:MAXLEN_COMP_NAME),'(2a,i4.4,a)') |
220 |
|
|
& myTypeStr,'.',j,'.clog' |
221 |
|
|
open(LogUnit,file=cbuf,status='unknown',form='formatted') |
222 |
|
|
write(LogUnit,'(2a)') '========================================', |
223 |
|
|
& '========================================' |
224 |
|
|
write(LogUnit,*) 'This is "',myTypeStr,'"' |
225 |
|
|
write(LogUnit,*) 'myid in MPI_COMM_World = ',myid |
226 |
|
|
if (.not.couplerFlag) |
227 |
|
|
& write(LogUnit,*) 'myid in MPI_COMM_Global = ',j |
228 |
|
|
|
229 |
|
|
! ------------------------------------------------------------------ |
230 |
|
|
return |
231 |
|
|
end |
232 |
|
|
!======================================================================= |