Debian Codegraph @

idp/ffddm_geneoCS_3rdlvl.idp

raw
1 macro ffddmbuildSuperEdge(pr,Th,nsup,scalar,def,init,Pk,defpart,initpart,Pkpart)
2
3 int pr#nsuper = nsup;
4
5 int pr#superchunksize = (mpisize-ffddmexclude*nsup)/nsup;
6
7 /* supers = (0 2 4) (1 3 5) */
8
9 int pr#issuper = mpirank < nsup;
10 int pr#mysuper = mpirank%nsup;
11 int pr#mysuperrank = pr#mysuper;
12
13 int[int] pr#insuperinterior(pr#superchunksize);
14 if (pr#superchunksize == 1)
15 pr#insuperinterior[0] = mpirank;
16 else {
17 for (int i=0; i<pr#superchunksize;i++)
18 pr#insuperinterior[i] = pr#mysuperrank+nsup*i;
19 }
20
21 func int pr#superrankof(int r) {
22 return r%nsup;
23 }
24
25 func int pr#rankofsuper(int r) {
26 return r;
27 }
28
29 int[int] procsuper(nsup);
30 for (int i=0;i<nsup;i++)
31 procsuper[i] = i;
32
33
34 /* supers = (0 1 2) (3 4 5) */
35
36 /*
37 int pr#issuper = (mpirank%pr#superchunksize == 0);
38 int pr#mysuper = pr#superchunksize*(mpirank/pr#superchunksize);
39 int pr#mysuperrank = pr#mysuper/pr#superchunksize;
40
41 int[int] pr#insuperinterior(pr#superchunksize);
42 if (pr#superchunksize == 1)
43 pr#insuperinterior[0] = mpirank;
44 else
45 pr#insuperinterior = (mpirank:mpirank+pr#superchunksize-1);
46
47 func int pr#superrankof(int r) {
48 return r/pr#superchunksize;
49 }
50
51 func int pr#rankofsuper(int r) {
52 return r*pr#superchunksize;
53 }
54
55 int[int] procsuper(nsup);
56 for (int i=0;i<nsup;i++)
57 procsuper[i] = i*pr#superchunksize;
58 */
59
60 mpiGroup grpsuper(procsuper);
61 mpiComm pr#commsuper(mpiCommWorld,grpsuper);
62
63 fespace pr#Phglob(Th,P0);
64 pr#Phglob partsuper, part;
65
66 int[int] lpart(Th.nt);
67 if (mpirank == 0)
68 if (nsup > 1)
69 metisdual(lpart,Th,pr#nsuper);
70 else
71 lpart = 0;
72 if (pr#issuper) {
73 broadcast(processor(0, pr#commsuper), lpart);
74 for(int i=0;i<lpart.n;++i)
75 partsuper[][i]=lpart[i];
76 }
77
78 ffddmnpart = nsup;
79
80 IFMACRO(!pr#supersimple)
81 NewMacro pr#supersimple(Phglob, upart, pr#commsuper)
82 upart[] = partsuper[];
83 EndMacro
84 ENDIFMACRO
85
86 int backexclude = ffddmexclude;
87 ffddmexclude = 0;
88
89 IFMACRO(pr#partcubes)
90 NewMacro pr#super#partcubes()1 EndMacro
91 ENDIFMACRO
92 ffddmbuildDmesh(pr#super,Th,pr#commsuper)
93
94 ffddmexclude = backexclude;
95
96 ffddminitDfespacef(pr#super,pr#super,scalar,def,init,Pk,defpart,initpart,Pkpart)
97
98 IFMACRO(pr#superwithchunk)
99 mpiGroup grpchunk(pr#insuperinterior);
100 mpiComm pr#commchunk(mpiCommWorld,grpchunk);
101
102 broadcast(processor(0,pr#commchunk),pr#super#Thi);
103 ENDIFMACRO
104
105 fespace pr#Phsuperovl(pr#super#Thi,P0);
106
107 pr#Phsuperovl partchunki;
108
109 if (pr#issuper){
110 partchunki[] = pr#super#partloc;
111 pr#super#meshN Thsuper = trunc(pr#super#Thi, partchunki == pr#mysuperrank);
112
113 IFMACRO (!pr#chunk#simple)
114 int[int] mylpart(pr#super#Thi.nt);
115 if (pr#superchunksize > 1)
116 metisdual(mylpart,pr#super#Thi,pr#superchunksize);
117 else
118 mylpart = 0;
119
120 for(int i=0;i<partchunki[].n;++i)
121 partchunki[][i]=mylpart[i];
122 ENDIFMACRO
123
124 IFMACRO (pr#chunk#simple)
125 pr#chunk#simple(pr#Phsuperovl, partchunki, pr#commchunk)
126 ENDIFMACRO
127
128 fespace pr#Phsuper(Thsuper,P0);
129 pr#Phsuper partsuperi;
130
131 partsuperi = partchunki;
132 for [i, bi : partsuperi[]] bi = pr#insuperinterior[bi];
133
134 matrix Rsuper = interpolate(pr#Phsuper,pr#Phglob);
135 pr#Phglob tmp;
136 tmp[] = Rsuper'*partsuperi[];
137 mpiReduce(tmp[], part[], processor(0,pr#commsuper), mpiSUM);
138 }
139
140 broadcast(processor(0,mpiCommWorld),part[]);
141
142 int ffddmpartitionerbackup = ffddmpartitioner;
143
144 ffddmpartitioner = 0;
145
146 IFMACRO(!pr#simple)
147 NewMacro pr#simple(Phglob, upart, comm)
148 upart[] = part[];
149 EndMacro
150 ENDIFMACRO
151
152 int backpCS = ffddmpCS;
153 ffddmpCS = nsup;
154 ffddmnpart = mpisize-ffddmexclude*nsup;
155
156 ffddmbuildDmesh(pr,Th,mpiCommWorld)
157 ffddmbuildDfespaceEdge(pr,pr,scalar,def,init,Pk,defpart,initpart,Pkpart)
158
159 ffddmpCS = backpCS;
160
161 NewMacro pr#minexactgeneoCS()1 EndMacro
162 pr#binexactCS = 1;
163
164 IFMACRO(pr#superwithchunk)
165 broadcast(processor(0,pr#commchunk),partchunki[]);
166
167 ffddmnpart = pr#superchunksize;
168
169 IFMACRO(!pr#chunksimple)
170 NewMacro pr#chunksimple(Phglob, upart, comm)
171 upart = partchunki;
172 EndMacro
173 ENDIFMACRO
174
175 IFMACRO(pr#partcubes)
176 NewMacro pr#chunk#partcubes()1 EndMacro
177 ENDIFMACRO
178
179 int bnoGlobbackup = bnoGlob;
180 bnoGlob = 0;
181 ffddmbuildDmesh(pr#chunk,pr#super#Thi,pr#commchunk)
182 ffddmbuildDfespaceEdge(pr#chunk,pr#chunk,scalar,def,init,Pk,defpart,initpart,Pkpart)
183 bnoGlob = bnoGlobbackup;
184
185 ffddmpartitioner = ffddmpartitionerbackup;
186
187 matrix pr#super#chunkinterp = interpolate(pr#Vhi,pr#chunkVhi);
188 pr#super#chunkinterp.thresholding(1e-10);
189
190 scalar[int] pr#chunksuperDk(pr#Vhi.ndof);
191 {
192 ffddmbuildDfespaceEdge(pr#super,pr#super,scalar,def,init,Pk,defpart,initpart,Pkpart)
193 pr#super#Vhi<scalar> def(truePoU);
194
195 if (mpiRank(pr#commchunk) == 0)
196 truePoU[] = pr#superDk[mpiRank(pr#commsuper)];
197
198 broadcast(processor(0,pr#commchunk),truePoU[]);
199
200 matrix R = interpolate(pr#Vhi,pr#super#Vhi);
201 pr#chunksuperDk = R*truePoU[];
202 }
203 ENDIFMACRO
204
205 int[int] pr#listofsupers(pr#arrayIntersection.n+1);
206 {
207 int[int] tmp(pr#arrayIntersection.n+1);
208 for (int i=0; i < pr#arrayIntersection.n; i++) {
209 tmp[i] = pr#superrankof(pr#arrayIntersection[i]);
210 }
211 tmp[tmp.n-1] = pr#mysuperrank;
212 Unique(tmp,pr#listofsupers);
213 pr#listofsupers.sort;
214 }
215
216 int[int] pr#neighborsofsuper(10000);
217 int[int] pr#insuperwithoverlap(0);
218
219 /* equivalent de pr#superrestrictionIntersection, mais juste les ranks, pas les dofs*/
220 int[int][int] pr#superrestrictionIntersectionranks(pr#nsuper);
221 for (int i=0;i<pr#nsuper;i++)
222 pr#superrestrictionIntersectionranks[i].resize(0);
223
224 if (pr#issuper) {
225 int nc = 0;
226 for (int ci=0; ci < pr#insuperinterior.n; ci++) {
227 int i = pr#insuperinterior[ci];
228 /* faire un gatherv ici */
229 /* neighbors est la liste des petits voisins de notre petit sous domaine i (qui appartient a notre super) */
230 int[int] neighbors(0);
231 if (!pr#excluded && i == mpirank) {
232 neighbors.resize(pr#arrayIntersection.n);
233 neighbors = pr#arrayIntersection;
234 }
235 else {
236 int nn;
237 processor(i+pr#exclude*pr#pCS) >> nn;
238 neighbors.resize(nn);
239 processor(i+pr#exclude*pr#pCS) >> neighbors;
240 }
241 for(int j=0;j<neighbors.n;++j)
242 if (pr#superrankof(neighbors[j]) != pr#mysuperrank) {
243 pr#neighborsofsuper[nc++] = neighbors[j];
244 int superr = pr#superrankof(neighbors[j]);
245 int currsize = pr#superrestrictionIntersectionranks[superr].n;
246 pr#superrestrictionIntersectionranks[superr].resize(currsize+2);
247 /* on met notre petit sous domaine i dans la liste de l'overlap avec superr */
248 pr#superrestrictionIntersectionranks[superr][currsize] = i;
249 /* on met le petit sous domaine voisin de i qui appartient a superr dans la liste de l'overlap avec superr */
250 pr#superrestrictionIntersectionranks[superr][currsize+1] = neighbors[j];
251 }
252 }
253
254 pr#neighborsofsuper.resize(nc);
255 int[int] tmp(nc);
256 Unique(pr#neighborsofsuper, tmp);
257 pr#neighborsofsuper.resize(tmp.n);
258 pr#neighborsofsuper = tmp;
259
260 pr#insuperwithoverlap.resize(pr#neighborsofsuper.n+pr#insuperinterior.n);
261 pr#insuperwithoverlap(0:pr#insuperinterior.n-1) = pr#insuperinterior;
262 if (pr#insuperwithoverlap.n >pr#insuperinterior.n)
263 pr#insuperwithoverlap(pr#insuperinterior.n:pr#insuperwithoverlap.n-1) = pr#neighborsofsuper;
264
265 tmp.resize(pr#neighborsofsuper.n);
266 pr#superarrayIntersection.resize(tmp.n);
267 for (int i=0; i<pr#neighborsofsuper.n;i++)
268 tmp[i] = pr#superrankof(pr#neighborsofsuper[i]);
269 Unique(tmp, pr#superarrayIntersection);
270 pr#supernumberIntersection = pr#superarrayIntersection.n;
271
272 }
273 else {
274 /* on n'est pas un super domaine : on envoie notre liste de petits voisins a notre super */
275 processor(pr#mysuper) << pr#arrayIntersection.n;
276 processor(pr#mysuper) << pr#arrayIntersection;
277 }
278 // EOM
279
280 macro ffddmsetupsuperinit(pr,preffe)
281 matrix<preffe#K> pr#RsuperCS;
282 int[int] pr#superlocalnuminv(0);
283 NewMacro pr#superalgebraic()1 EndMacro
284 ffddmsetupinit(pr#super,preffe#super)
285 // EOM
286
287 macro ffddmbuildSuper(pr,Th,nsup,scalar,def,init,Pk)
288 ffddmbuildSuperEdge(pr,Th,nsup,scalar,def,init,Pk,def,init,Pk)
289 // EOM
290
291 macro ffddmsetupsuper(pr)
292
293 if (pr#prfe#prmesh#issuper) {
294 /*
295 broadcast(processor(0,pr#prfe#prmesh#commsuper),pr#E);
296 */
297
298 pr#prfe#superDk[mpiRank(pr#prfe#prmesh#commsuper)].resize(pr#ncoarsespace);
299 pr#prfe#superDk[mpiRank(pr#prfe#prmesh#commsuper)] = 0;
300
301 int[int] localnum(pr#ncoarsespace);
302 int nloc = 0;
303
304 for (int j=0; j<pr#prfe#prmesh#insuperwithoverlap.n; j++){
305 int ng = pr#prfe#prmesh#insuperwithoverlap[j];
306 for (int k=0; k<pr#sizelg[ng];k++) {
307 if (pr#prfe#prmesh#superrankof(ng) == pr#prfe#prmesh#mysuperrank)
308 pr#prfe#superDk[mpiRank(pr#prfe#prmesh#commsuper)][nloc] = 1;
309 localnum[nloc++] = pr#offseti[ng]+k;
310 }
311 }
312
313 pr#prfe#superDk[mpiRank(pr#prfe#prmesh#commsuper)].resize(nloc);
314 pr#prfe#superDih[mpiRank(pr#prfe#prmesh#commsuper)] = pr#prfe#superDk[mpiRank(pr#prfe#prmesh#commsuper)];
315
316 localnum.resize(nloc);
317
318 int[int] I(nloc);
319 pr#superlocalnuminv.resize(pr#ncoarsespace);
320 pr#prfe#K[int] K(nloc);
321 I = (0:nloc-1);
322 K = 1;
323 for (int j=0; j<nloc; j++)
324 pr#superlocalnuminv[localnum[j]] = j;
325
326 if (localnum.max != pr#ncoarsespace-1) {
327 I.resize(nloc+1);
328 localnum.resize(nloc+1);
329 K.resize(nloc+1);
330 I[nloc] = 0;
331 localnum[nloc] = pr#ncoarsespace-1;
332 K[nloc] = 0;
333 }
334
335 /* matrice de restriction au super domaine, dans la numerotation de E */
336 pr#RsuperCS = [I,localnum,K];
337 pr#RsuperCS.thresholding(1e-10);
338
339 /*
340 pr#superaRd[mpiRank(pr#prfe#prmesh#commsuper)] = pr#RsuperCS*pr#E;
341 pr#superaRd[mpiRank(pr#prfe#prmesh#commsuper)] = pr#superaRd[mpiRank(pr#prfe#prmesh#commsuper)]*pr#RsuperCS';
342 */
343
344 /*
345 La ou dans superrestrictionIntersectionranks il y avait des ranks(petits sous domaines),
346 dans superrestrictionIntersection il y a des dofs de E, en numerotation locale de super
347 (la correspondance locale-globale est donnee par localnum et superlocalnuminv)
348 */
349 pr#prfe#superrestrictionIntersection.resize(pr#prfe#prmesh#supernumberIntersection);
350 for (int i=0;i < pr#prfe#prmesh#supernumberIntersection;i++) {
351 int[int] uniqueranks(1);
352 Unique(pr#prfe#superrestrictionIntersectionranks[pr#prfe#prmesh#superarrayIntersection[i]],uniqueranks);
353 uniqueranks.sort;
354 int[int] restIntersection(0);
355 for (int j=0;j<uniqueranks.n;j++) {
356 int size = pr#sizelg[uniqueranks[j]];
357 int offset = pr#offseti[uniqueranks[j]];
358 restIntersection.resize(restIntersection.n+size);
359 for (int k=0; k<size;k++)
360 restIntersection[restIntersection.n-size+k] = pr#superlocalnuminv[offset+k];
361 }
362 int nn =restIntersection.n;
363 int[int] I(nn),J(nn);
364 pr#prfe#K[int] K(nn);
365 I = (0:nn-1);
366 K=1;
367 J = restIntersection;
368 if (J.max != pr#RsuperCS.n-1) {
369 I.resize(I.n+1);
370 J.resize(J.n+1);
371 K.resize(K.n+1);
372 I[I.n-1] = 0;
373 J[J.n-1] = pr#RsuperCS.n-1;
374 K[K.n-1] = 0;
375 }
376 pr#prfe#superrestrictionIntersection[i] = [I,J,K];
377 pr#prfe#superrestrictionIntersection[i].thresholding(1.e-10);
378 }
379 pr#prfe#superrcv.resize(pr#prfe#prmesh#supernumberIntersection);
380 pr#prfe#supersnd.resize(pr#prfe#prmesh#supernumberIntersection);
381 for(int j=0;j<pr#prfe#prmesh#supernumberIntersection;++j) {
382 pr#prfe#superrcv[j].resize(pr#prfe#superrestrictionIntersection[j].n);
383 pr#prfe#supersnd[j].resize(pr#prfe#superrestrictionIntersection[j].n);
384 }
385
386 }
387 // EOM
388
389 macro ffddmgeneosetupsuper(pr)
390 {
391 /*
392 assemblage de la matrice de Neumann:
393 pour chaque super domaine avec overlap auquel on appartient (sorted):
394 si on appartient au super sans overlap
395 - on envoie la restriction de la matrice de Neumann du petit sous domaine a chaque petit voisin
396 on recoit la restriction des matrices de Neumann de chacun des voisins qui appartiennent au super sans overlap
397 on fait la somme -> S
398 on fait Szi = S Zi
399 on envoie Szi a nos voisins qui appartiennent au super avec overlap
400 on fait Sii = Zi' S Zi
401 on fait Sij = Zi' Szj
402 on envoie Sij au super
403 */
404
405 pr#prfe#prmesh#supertic(pr#supertloc)
406 pr#prfe#prmesh#tic(pr#tloc)
407
408 matrix<pr#prfe#K>[int] restNeumann(pr#prfe#prmesh#arrayIntersection.n);
409 matrix<pr#prfe#K>[int] restNeumannSend(pr#prfe#prmesh#arrayIntersection.n);
410
411 mpiRequest[int] rqn(pr#prfe#prmesh#arrayIntersection.n*2);
412 for (int i=0; i<pr#prfe#prmesh#arrayIntersection.n; i++) {
413 /*
414 matrix rest = pr#prfe#restrictionIntersection[i]*pr#matN;
415 rest = rest*pr#prfe#restrictionIntersection[i]';
416 */
417 restNeumannSend[i] = pr#matN;
418
419 NewMacro localmacroK pr#prfe#K EndMacro
420 IFMACRO(localmacroK,real)
421 renumbering(restNeumannSend[i],pr#prfe#restrictionIntersection[i],eps=-1);
422 ENDIFMACRO
423
424 IFMACRO(localmacroK,complex)
425 matrix restreal = pr#prfe#restrictionIntersection[i].re;
426 renumbering(restNeumannSend[i],restreal,eps=-1);
427 ENDIFMACRO
428
429 Isend(processor(pr#prfe#prmesh#arrayIntersection[i],pr#prfe#prmesh#commddm,rqn[i]),restNeumannSend[i]);
430 }
431 for (int i=0; i<pr#prfe#prmesh#arrayIntersection.n; i++)
432 Irecv(processor(pr#prfe#prmesh#arrayIntersection[i],pr#prfe#prmesh#commddm,rqn[pr#prfe#prmesh#arrayIntersection.n+i]),restNeumann[i]);
433 for (int i=0; i<pr#prfe#prmesh#arrayIntersection.n*2; i++)
434 int k = mpiWaitAny(rqn);
435
436 int[int][int] inisuperwithoverlap(pr#prfe#prmesh#listofsupers.n);
437 int[int]inisuperwithoverlapsize(pr#prfe#prmesh#listofsupers.n);
438 inisuperwithoverlapsize = 0;
439 for (int i=0; i<inisuperwithoverlap.n; i++)
440 inisuperwithoverlap[i].resize(10000);
441
442 mpiRequest[int] rq(2*(pr#prfe#prmesh#listofsupers.n-pr#prfe#prmesh#issuper)+2*pr#prfe#prmesh#issuper*(pr#prfe#prmesh#insuperwithoverlap.n-!pr#prfe#prmesh#excluded));
443 int cpt = 0;
444 if (pr#prfe#prmesh#issuper) {
445 for (int i=!pr#prfe#prmesh#excluded;i<pr#prfe#prmesh#insuperwithoverlap.n;i++) {
446 Isend(processor(pr#prfe#prmesh#insuperwithoverlap[i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rq[cpt++]),pr#prfe#prmesh#insuperwithoverlap.n);
447 Isend(processor(pr#prfe#prmesh#insuperwithoverlap[i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rq[cpt++]),pr#prfe#prmesh#insuperwithoverlap);
448 }
449 }
450 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
451 int isuper = pr#prfe#prmesh#listofsupers[is];
452 if (!pr#prfe#prmesh#issuper || pr#prfe#prmesh#mysuperrank != isuper) {
453 Irecv(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rq[cpt++]),inisuperwithoverlapsize[is]);
454 Irecv(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rq[cpt++]),inisuperwithoverlap[is]);
455 }
456 }
457 for (int i=0;i < cpt;i++)
458 int k = mpiWaitAny(rq);
459
460 for (int is=0;is < pr#prfe#prmesh#listofsupers.n; is++) {
461 int isuper = pr#prfe#prmesh#listofsupers[is];
462 if (pr#prfe#prmesh#issuper && pr#prfe#prmesh#mysuperrank == isuper) {
463 inisuperwithoverlap[is].resize(pr#prfe#prmesh#insuperwithoverlap.n);
464 inisuperwithoverlap[is] = pr#prfe#prmesh#insuperwithoverlap;
465 }
466 else
467 inisuperwithoverlap[is].resize(inisuperwithoverlapsize[is]);
468 }
469
470 int[int][int] indicesofneighbors(pr#prfe#prmesh#listofsupers.n);
471 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
472 int isuper = pr#prfe#prmesh#listofsupers[is];
473 indicesofneighbors[is].resize(pr#prfe#prmesh#arrayIntersection.n);
474 cpt = 0;
475 for (int i=0; i<pr#prfe#prmesh#arrayIntersection.n; i++)
476 for (int j=0; j<inisuperwithoverlap[is].n;j++)
477 if (pr#prfe#prmesh#arrayIntersection[i] == inisuperwithoverlap[is][j])
478 indicesofneighbors[is][cpt++] = i;
479 indicesofneighbors[is].resize(cpt);
480 }
481
482 int[int][int] neighbors(pr#prfe#prmesh#listofsupers.n);
483 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
484 neighbors[is].resize(indicesofneighbors[is].n);
485 for (int i=0;i<indicesofneighbors[is].n;i++)
486 neighbors[is][i] = pr#prfe#prmesh#arrayIntersection[indicesofneighbors[is][i]];
487 }
488
489 int[int] tabnumberIntersection(pr#prfe#prmesh#insuperwithoverlap.n); /* i: number of neighbours of processor i */
490 int[int][int] tabarrayIntersection(pr#prfe#prmesh#insuperwithoverlap.n);
491 if (pr#prfe#prmesh#issuper)
492 for (int i=!pr#prfe#prmesh#excluded; i<pr#prfe#prmesh#insuperwithoverlap.n; i++)
493 tabarrayIntersection[i].resize(10000);
494
495 mpiRequest[int] rqt(2*(pr#prfe#prmesh#listofsupers.n-pr#prfe#prmesh#issuper)+2*pr#prfe#prmesh#issuper*(pr#prfe#prmesh#insuperwithoverlap.n-!pr#prfe#prmesh#excluded));
496
497 cpt = 0;
498 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
499 int isuper = pr#prfe#prmesh#listofsupers[is];
500 if (!pr#prfe#prmesh#issuper || pr#prfe#prmesh#mysuperrank != isuper) {
501 Isend(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rqt[cpt++]),neighbors[is].n);
502 Isend(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rqt[cpt++]),neighbors[is]);
503 }
504 else {
505 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++) {
506 Irecv(processor(inisuperwithoverlap[is][i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rqt[cpt++]),tabnumberIntersection[i]);
507 Irecv(processor(inisuperwithoverlap[is][i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rqt[cpt++]),tabarrayIntersection[i]);
508 }
509 }
510 }
511
512 for (int i=0;i < cpt;i++)
513 int k = mpiWaitAny(rqt);
514
515 if (pr#prfe#prmesh#issuper)
516 for (int i=!pr#prfe#prmesh#excluded; i<pr#prfe#prmesh#insuperwithoverlap.n; i++)
517 tabarrayIntersection[i].resize(tabnumberIntersection[i]);
518
519 int cptmpi = 0;
520
521 int nbrqmpi = 0;
522 int nbrqmpiexcl = 0;
523
524 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
525 nbrqmpi += indicesofneighbors[is].n;
526 if (!pr#prfe#prmesh#issuper || pr#prfe#prmesh#mysuperrank != pr#prfe#prmesh#listofsupers[is])
527 nbrqmpiexcl += indicesofneighbors[is].n;
528 }
529
530 pr#prfe#K[int,int][int] mrcv(nbrqmpi);
531 pr#prfe#K[int,int][int] msnd(nbrqmpi);
532
533 mpiRequest[int] rqszi(2*nbrqmpi);
534
535 pr#prfe#K[int,int][int] Sii(pr#prfe#prmesh#listofsupers.n);
536 for (int i=0; i<pr#prfe#prmesh#listofsupers.n; i++)
537 Sii[i].resize(pr#si,pr#si);
538
539 if (!pr#prfe#prmesh#excluded) {
540 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++)
541 {
542 int isuper = pr#prfe#prmesh#listofsupers[is];
543
544 int[int] indicesofinteriorneighbors(pr#prfe#prmesh#arrayIntersection.n);
545 int cpt = 0;
546 for (int i=0; i<pr#prfe#prmesh#arrayIntersection.n; i++)
547 if (pr#prfe#prmesh#superrankof(pr#prfe#prmesh#arrayIntersection[i]) == isuper) {
548 indicesofinteriorneighbors[cpt++] = i;
549 }
550 indicesofinteriorneighbors.resize(cpt);
551
552 matrix<pr#prfe#K> SumNeumann;
553 if (pr#prfe#prmesh#mysuperrank == isuper)
554 SumNeumann = pr#matN;
555 for(int cj=0;cj<indicesofinteriorneighbors.n;++cj) {
556 int j = indicesofinteriorneighbors[cj];
557 matrix<pr#prfe#K> extens = pr#prfe#restrictionIntersection[j]'*restNeumann[j];
558 extens = extens*pr#prfe#restrictionIntersection[j];
559 SumNeumann = SumNeumann+extens;
560 }
561
562 pr#prfe#K[int,int] Szi(pr#matN.n,pr#si);
563 for (int ii=0; ii < pr#si; ii++) {
564 pr#prfe#K[int] tmp(SumNeumann.n);
565 tmp = SumNeumann*pr#Z[ii];
566 Szi(:,ii) = tmp;
567 }
568
569 for (int ii=0; ii < pr#si; ii++)
570 for (int jj=0; jj < pr#si; jj++) {
571 Sii[is](ii,jj) = pr#Z[ii]'*Szi(:,jj);
572 }
573
574 for(int j=0;j<indicesofneighbors[is].n;++j) {
575 msnd[cptmpi].resize(pr#prfe#restrictionIntersection[indicesofneighbors[is][j]].n,pr#si);
576 mrcv[cptmpi].resize(pr#prfe#restrictionIntersection[indicesofneighbors[is][j]].n, pr#sizelg[pr#prfe#prmesh#arrayIntersection[indicesofneighbors[is][j]]]);
577 for (int ii=0; ii<pr#si; ii++) {
578 pr#prfe#K[int] tmp(pr#prfe#restrictionIntersection[indicesofneighbors[is][j]].n);
579 tmp = pr#prfe#restrictionIntersection[indicesofneighbors[is][j]]*Szi(:,ii);
580 msnd[cptmpi](:,ii) = tmp;
581 }
582 Isend(processor(pr#prfe#prmesh#arrayIntersection[indicesofneighbors[is][j]],pr#prfe#prmesh#commddm,rqszi[2*cptmpi]),msnd[cptmpi]);
583 Irecv(processor(pr#prfe#prmesh#arrayIntersection[indicesofneighbors[is][j]],pr#prfe#prmesh#commddm,rqszi[2*cptmpi+1]),mrcv[cptmpi]);
584 cptmpi++;
585 }
586 }
587
588 for (int i=0; i<2*cptmpi; i++)
589 int k = mpiWaitAny(rqszi);
590 }
591
592 mpiRequest[int] rqsii(pr#prfe#prmesh#listofsupers.n-pr#prfe#prmesh#issuper);
593 cpt = 0;
594 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
595 int isuper = pr#prfe#prmesh#listofsupers[is];
596 if (!pr#prfe#prmesh#issuper || pr#prfe#prmesh#mysuperrank != isuper)
597 Isend(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rqsii[cpt++]),Sii[is]);
598 }
599
600 for (int i=0;i < cpt;i++)
601 int k = mpiWaitAny(rqsii);
602
603 pr#prfe#K[int,int][int] Sij(nbrqmpi);
604
605 mpiRequest[int] rqsij(nbrqmpiexcl);
606 cptmpi = 0;
607 int cptmpiexcl = 0;
608 int myindexinsij = -1;
609 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
610 int isuper = pr#prfe#prmesh#listofsupers[is];
611 if (pr#prfe#prmesh#issuper && pr#prfe#prmesh#mysuperrank == isuper)
612 myindexinsij = cptmpi;
613 for(int j=0;j<indicesofneighbors[is].n;++j) {
614 Sij[cptmpi].resize(pr#si,pr#sizelg[pr#prfe#prmesh#arrayIntersection[indicesofneighbors[is][j]]]);
615 for (int jj=0; jj < pr#sizelg[pr#prfe#prmesh#arrayIntersection[indicesofneighbors[is][j]]]; jj++) {
616 pr#prfe#K[int] tmp(pr#prfe#restrictionIntersection[indicesofneighbors[is][j]].m);
617 tmp = pr#prfe#restrictionIntersection[indicesofneighbors[is][j]]'*mrcv[cptmpi](:,jj);
618 for (int ii=0; ii < pr#si; ii++){
619 Sij[cptmpi](ii,jj) = pr#Z[ii]'*tmp;
620 }
621 }
622 if (!pr#prfe#prmesh#issuper || pr#prfe#prmesh#mysuperrank != isuper) {
623 Isend(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rqsij[cptmpiexcl]),Sij[cptmpi]);
624 cptmpiexcl++;
625 }
626 cptmpi++;
627 }
628 }
629
630 for (int i=0; i<nbrqmpiexcl; i++)
631 int k = mpiWaitAny(rqsij);
632
633 if (pr#prfe#prmesh#issuper) {
634 int is = -1;
635 for (int i=0; i< pr#prfe#prmesh#listofsupers.n; i++)
636 if (pr#prfe#prmesh#listofsupers[i] == pr#prfe#prmesh#mysuperrank)
637 is = i;
638
639 int isuper = pr#prfe#prmesh#mysuperrank;
640
641 int nbij = 0;
642 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++)
643 nbij += tabnumberIntersection[i];
644
645 pr#prfe#K[int,int][int] tabSij(nbij); /* big vector of full matrices for the blocks Sij */
646 pr#prfe#K[int,int][int] tabSii(inisuperwithoverlap[is].n); /* big vector of full matrices for the blocks Sii */
647
648 /* on proc 0 resize tabSii and receive Sii blocks */
649 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++)
650 tabSii[i].resize(pr#sizelg[inisuperwithoverlap[is][i]],pr#sizelg[inisuperwithoverlap[is][i]]);
651 mpiRequest[int] rqtii(inisuperwithoverlap[is].n-!pr#prfe#prmesh#excluded);
652 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++)
653 Irecv(processor(inisuperwithoverlap[is][i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rqtii[i-!pr#prfe#prmesh#excluded]),tabSii[i]);
654 for (int i = 0; i < inisuperwithoverlap[is].n-!pr#prfe#prmesh#excluded; i++)
655 int k = mpiWaitAny(rqtii);
656
657 /* on proc 0 resize tabSij and receive Sij blocks */
658 int cpt = 0;
659 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++)
660 for (int j=0; j < tabnumberIntersection[i]; j++) {
661 tabSij[cpt].resize(pr#sizelg[inisuperwithoverlap[is][i]],pr#sizelg[tabarrayIntersection[i][j]]);
662 cpt++;
663 }
664 mpiRequest[int] rqtij(nbij);
665 cpt = 0;
666 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++)
667 for (int j=0; j < tabnumberIntersection[i]; j++) {
668 Irecv(processor(inisuperwithoverlap[is][i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rqtij[cpt]),tabSij[cpt]);
669 cpt++;
670 }
671 for (int i=0; i < nbij; i++)
672 int k = mpiWaitAny(rqtij);
673
674 /* fill S0 with Sii and Sij */
675 pr#prfe#K[int,int] S0(pr#prfe#superDk[mpiRank(pr#prfe#prmesh#commsuper)].n,pr#prfe#superDk[mpiRank(pr#prfe#prmesh#commsuper)].n);
676 S0 = 0;
677
678 if (!pr#prfe#prmesh#excluded) {
679 /* block S00 */
680 for (int jj=0; jj< pr#sizelg[mpiRank(pr#prfe#prmesh#commddm)]; jj++)
681 S0(pr#superlocalnuminv[pr#offseti[mpiRank(pr#prfe#prmesh#commddm)]]:pr#superlocalnuminv[pr#offseti[mpiRank(pr#prfe#prmesh#commddm)]]+pr#sizelg[mpiRank(pr#prfe#prmesh#commddm)]-1,
682 pr#superlocalnuminv[pr#offseti[mpiRank(pr#prfe#prmesh#commddm)]]+jj) = Sii[is](:,jj);
683 /* blocks S0j */
684 for(int j=0;j<indicesofneighbors[is].n;++j)
685 for (int jj=0; jj< pr#sizelg[pr#prfe#prmesh#arrayIntersection[indicesofneighbors[is][j]]]; jj++)
686 S0(pr#superlocalnuminv[pr#offseti[mpiRank(pr#prfe#prmesh#commddm)]]:pr#superlocalnuminv[pr#offseti[mpiRank(pr#prfe#prmesh#commddm)]]+pr#sizelg[mpiRank(pr#prfe#prmesh#commddm)]-1,
687 pr#superlocalnuminv[pr#offseti[pr#prfe#prmesh#arrayIntersection[indicesofneighbors[is][j]]]]+jj) = Sij[myindexinsij+j](:,jj);
688 }
689
690 cpt = 0;
691 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++) {
692 /* blocks Sii */
693 for (int jj=0; jj< pr#sizelg[inisuperwithoverlap[is][i]]; jj++)
694 S0(pr#superlocalnuminv[pr#offseti[inisuperwithoverlap[is][i]]]:pr#superlocalnuminv[pr#offseti[inisuperwithoverlap[is][i]]]+pr#sizelg[inisuperwithoverlap[is][i]]-1,
695 pr#superlocalnuminv[pr#offseti[inisuperwithoverlap[is][i]]]+jj) = tabSii[i](:,jj);
696 /* blocks Sij */
697 for(int j=0;j<tabnumberIntersection[i];++j) {
698 for (int jj=0; jj< pr#sizelg[tabarrayIntersection[i][j]]; jj++) {
699 S0(pr#superlocalnuminv[pr#offseti[inisuperwithoverlap[is][i]]]:pr#superlocalnuminv[pr#offseti[inisuperwithoverlap[is][i]]]+pr#sizelg[inisuperwithoverlap[is][i]]-1,
700 pr#superlocalnuminv[pr#offseti[tabarrayIntersection[i][j]]]+jj) = tabSij[cpt](:,jj);
701 }
702 cpt++;
703 }
704 }
705
706 pr#supermatN = S0;
707 /*
708 matrix S0s = S0;
709 pr#supermatN = pr#RsuperCS*S0s;
710 pr#supermatN = pr#supermatN*pr#RsuperCS';
711 */
712 }
713
714 pr#prfe#prmesh#supertoc(pr#supertloc,"assembling super Neumann matrices",pr#supertbuildE)
715
716 ffddmgeneosetup(pr#super,null)
717
718 pr#prfe#prmesh#toc(pr#tloc,"",pr#tbuildE)
719 }
720 // EOM