20 #ifndef SELDON_FILE_DISTRIBUTED_VECTOR_CXX
22 #include "DistributedVector.hxx"
33 template<
class T1,
class Allocator1>
38 SetComplexZero(value);
40 for (
int i = 0; i < nb_over; i++)
49 int nb_proc; MPI_Comm_size(comm, &nb_proc);
52 T1 sum; SetComplexZero(sum);
54 MpiAllreduce(comm, &value, xtmp, &sum, 1, MPI_SUM);
68 template<
class T1,
class Allocator1>
73 SetComplexZero(value);
75 for (
int i = 0; i < nb_over; i++)
83 int nb_proc; MPI_Comm_size(comm, &nb_proc);
86 T1 sum; SetComplexZero(sum);
88 MpiAllreduce(comm, &value, xtmp, &sum, 1, MPI_SUM);
97 template<
class T,
class Allocator>
100 T scal = abs(DotProdConj(x, x));
106 template<
class T,
class Allocator>
109 T scal = DotProd(x, x);
124 complex<T>
minComplex(
const complex<T>& x,
const complex<T>& y)
143 complex<T>
maxComplex(
const complex<T>& x,
const complex<T>& y)
157 IVect& MatchingNumber_Local,
160 MatchingNumber_Local.Clear();
161 MatchingDof_Local.Clear();
162 for (
int i = 0; i < MatchingNumber_Subdomain.GetM(); i++)
164 int proc = MatchingNumber_Subdomain(i);
166 for (
int j = 0; j < MatchingDofOrig_Subdomain(i).GetM(); j++)
167 if ((nb_ddl_local > 0) &&
168 (is_local(MatchingDofOrig_Subdomain(i)(j))))
173 IVect dof_num(nb_dof);
175 for (
int j = 0; j < MatchingDofOrig_Subdomain(i).GetM(); j++)
176 if (is_local(MatchingDofOrig_Subdomain(i)(j)))
178 dof_num(nb_dof) = MatchingDofOrig_Subdomain(i)(j);
182 MatchingNumber_Local.PushBack(proc);
183 MatchingDof_Local.PushBack(dof_num);
191 const IVect& ProcNumber,
193 const MPI_Comm& comm,
int Nvol,
int nb_u,
int tag)
195 int nb_proc; MPI_Comm_size(comm, &nb_proc);
200 int nb_dom = DofNumber.GetM();
207 for (
int i = 0; i < nb_dom; i++)
209 int j = ProcNumber(i);
210 int nb = DofNumber(i).GetM();
213 xsend(i).Reallocate(2*nb_u*nb);
214 for (
int m = 0; m < nb_u; m++)
215 for (
int k = 0; k < nb; k++)
217 xsend(i)(nb_u*k+m) = X(DofNumber(i)(k) + m*Nvol);
218 xsend(i)(nb_u*k+m+nb*nb_u)
219 = Xproc(DofNumber(i)(k) + m*Nvol);
223 MPI_Isend(&xsend(i)(0), 2*nb*nb_u,
224 MPI_INTEGER, j, tag, comm, &request_send(i));
230 for (
int i = 0; i < nb_dom; i++)
232 int j = ProcNumber(i);
233 int nb = DofNumber(i).GetM();
236 xdom(i).Reallocate(2*nb_u*nb);
240 MPI_Irecv(&xdom(i)(0), 2*nb*nb_u,
241 MPI_INTEGER, j, tag, comm, &request_recv(i));
246 for (
int i = 0; i < nb_dom; i++)
247 if (DofNumber(i).GetM() > 0)
248 MPI_Wait(&request_recv(i), &status);
250 for (
int i = 0; i < nb_dom; i++)
251 if (DofNumber(i).GetM() > 0)
252 MPI_Wait(&request_send(i), &status);
255 for (
int i = 0; i < nb_dom; i++)
257 for (
int m = 0; m < nb_u; m++)
258 for (
int k = 0; k < DofNumber(i).GetM(); k++)
260 int nb = DofNumber(i).GetM();
261 int p = DofNumber(i)(k) + m*Nvol;
262 int proc = xdom(i)(k*nb_u+m+nb*nb_u);
263 int col = xdom(i)(k*nb_u+m);
269 else if (proc == Xproc(p))
299 const MPI_Comm& comm,
int Nvol,
int nb_u,
int tag)
301 int nb_proc; MPI_Comm_size(comm, &nb_proc);
306 int nb_dom = DofNumber.GetM();
313 for (
int i = 0; i < nb_dom; i++)
315 int j = ProcNumber(i);
316 int nb = DofNumber(i).GetM();
319 xsend(i).Reallocate(nb_u*nb);
320 for (
int m = 0; m < nb_u; m++)
321 for (
int k = 0; k < nb; k++)
322 xsend(i)(nb_u*k+m) = X(DofNumber(i)(k) + m*Nvol);
325 request_send(i) = MpiIsend(comm, xsend(i), xsend_tmp(i),
331 T zero; SetComplexZero(zero);
334 for (
int i = 0; i < nb_dom; i++)
336 int j = ProcNumber(i);
337 int nb = DofNumber(i).GetM();
340 xdom(i).Reallocate(nb_u*nb);
344 request_recv(i) = MpiIrecv(comm, xdom(i), xdom_tmp(i),
350 for (
int i = 0; i < nb_dom; i++)
351 if (DofNumber(i).GetM() > 0)
352 MPI_Wait(&request_send(i), &status);
354 for (
int i = 0; i < nb_dom; i++)
355 if (DofNumber(i).GetM() > 0)
356 MPI_Wait(&request_recv(i), &status);
359 for (
int i = 0; i < nb_dom; i++)
360 if (DofNumber(i).GetM() > 0)
361 MpiCompleteIrecv(xdom(i), xdom_tmp(i), DofNumber(i).GetM()*nb_u);
364 for (
int i = 0; i < nb_dom; i++)
368 for (
int m = 0; m < nb_u; m++)
369 for (
int k = 0; k < DofNumber(i).GetM(); k++)
370 X(DofNumber(i)(k) + m*Nvol) += xdom(i)(k*nb_u+m);
372 else if (oper == MPI_MIN)
374 for (
int m = 0; m < nb_u; m++)
375 for (
int k = 0; k < DofNumber(i).GetM(); k++)
376 X(DofNumber(i)(k) + m*Nvol)
380 else if (oper == MPI_MAX)
382 for (
int m = 0; m < nb_u; m++)
383 for (
int k = 0; k < DofNumber(i).GetM(); k++)
384 X(DofNumber(i)(k) + m*Nvol)
390 cout <<
"Operation not implemented" << endl;
417 const MPI_Comm& comm,
int Nvol,
int nb_u,
int tag)
419 int nb_proc; MPI_Comm_size(comm, &nb_proc);
424 int nb_dom = DofNumber.GetM();
431 for (
int i = 0; i < nb_dom; i++)
433 int j = ProcNumber(i);
434 int nb = DofNumber(i).GetM();
437 xsend(i).Reallocate(nb_u*nb);
438 for (
int m = 0; m < nb_u; m++)
439 for (
int k = 0; k < nb; k++)
440 xsend(i)(nb_u*k+m) = X(DofNumber(i)(k) + m*Nvol);
443 request_send(i) = MpiIsend(comm, xsend(i), xsend_tmp(i),
449 T zero; SetComplexZero(zero);
452 for (
int i = 0; i < nb_dom; i++)
454 int j = ProcNumber(i);
455 int nb = DofNumber(i).GetM();
458 xdom(i).Reallocate(nb_u*nb);
462 request_recv(i) = MpiIrecv(comm, xdom(i), xdom_tmp(i),
468 for (
int i = 0; i < nb_dom; i++)
469 if (DofNumber(i).GetM() > 0)
470 MPI_Wait(&request_send(i), &status);
472 for (
int i = 0; i < nb_dom; i++)
473 if (DofNumber(i).GetM() > 0)
474 MPI_Wait(&request_recv(i), &status);
477 for (
int i = 0; i < nb_dom; i++)
478 if (DofNumber(i).GetM() > 0)
479 MpiCompleteIrecv(xdom(i), xdom_tmp(i), DofNumber(i).GetM()*nb_u);
482 for (
int i = 0; i < nb_dom; i++)
484 for (
int m = 0; m < nb_u; m++)
485 for (
int k = 0; k < DofNumber(i).GetM(); k++)
486 X(DofNumber(i)(k) + m*Nvol) = xdom(i)(k*nb_u+m);
508 template<
class T,
class Treal>
509 void ExchangeRelaxVector(
Vector<T>& X,
const Treal& omega,
int proc,
510 const IVect& ProcNumber,
512 const MPI_Comm& comm,
int Nvol,
int nb_u,
int tag)
514 int nb_proc; MPI_Comm_size(comm, &nb_proc);
515 int rank_proc; MPI_Comm_rank(comm, &rank_proc);
520 int nb_dom = DofNumber.GetM();
525 if (rank_proc == proc)
528 for (
int i = 0; i < nb_dom; i++)
530 int j = ProcNumber(i);
531 int nb = DofNumber(i).GetM();
534 xsend.Reallocate(nb_u*nb);
535 for (
int m = 0; m < nb_u; m++)
536 for (
int k = 0; k < nb; k++)
537 xsend(nb_u*k+m) = X(DofNumber(i)(k) + m*Nvol);
540 MpiSsend(comm, xsend, xsend_tmp, nb*nb_u, j, tag);
549 T zero; SetComplexZero(zero);
550 for (
int i = 0; i < nb_dom; i++)
552 int j = ProcNumber(i);
555 int nb = DofNumber(i).GetM();
558 xdom.Reallocate(nb_u*nb);
562 MpiRecv(comm, xdom, xdom_tmp, nb*nb_u, j, tag, status);
564 for (
int m = 0; m < nb_u; m++)
565 for (
int k = 0; k < DofNumber(i).GetM(); k++)
566 X(DofNumber(i)(k) + m*Nvol) =
567 (1.0-omega)* X(DofNumber(i)(k) + m*Nvol) +
568 omega*xdom(k*nb_u+m);
577 #define SELDON_FILE_DISTRIBUTED_VECTOR_CXX