20 #ifndef SELDON_FILE_DISTRIBUTED_MATRIX_CXX
22 #include "DistributedMatrix.hxx"
31 void DistributedMatrixIntegerArray::Clear()
33 OverlapRowNumbers.Clear();
34 OverlapProcNumbers.Clear();
35 GlobalRowNumbers.Clear();
36 ProcSharingRows.Clear();
37 SharingRowNumbers.Clear();
41 void DistributedMatrixIntegerArray
42 ::SetData(
int nl,
int ng,
int nodl,
int nb_u,
const MPI_Comm& comm_,
43 const IVect& overlap_row,
const IVect& overlap_proc,
44 const IVect& global_rows,
const IVect& proc_rows,
const Vector<IVect>& sharing_rows)
49 nb_unknowns_scal = nb_u;
52 OverlapRowNumbers.SetData(overlap_row.GetM(), overlap_row.GetData());
53 OverlapProcNumbers.SetData(overlap_proc.GetM(), overlap_proc.GetData());
54 GlobalRowNumbers.SetData(global_rows.GetM(), global_rows.GetData());
55 ProcSharingRows.SetData(proc_rows.GetM(), proc_rows.GetData());
56 SharingRowNumbers.SetData(sharing_rows.GetM(), sharing_rows.GetData());
60 void DistributedMatrixIntegerArray::Nullify()
62 OverlapRowNumbers.Nullify();
63 OverlapProcNumbers.Nullify();
64 GlobalRowNumbers.Nullify();
65 ProcSharingRows.Nullify();
66 SharingRowNumbers.Nullify();
69 int DistributedMatrixIntegerArray
70 ::ConstructArrays(Vector<IVect>& all_rows,
71 IVect& row_num, IVect& overlap_num, IVect& proc_num,
72 IVect& MatchingProc, Vector<IVect>& MatchingDofNumber,
73 const MPI_Comm& comm,
bool distribute_row)
75 int nb_proc; MPI_Comm_size(comm, &nb_proc);
76 int rank_proc; MPI_Comm_rank(comm, &rank_proc);
78 if ((rank_proc == 0) && (distribute_row))
79 for (
int i = 0; i < nb_proc; i++)
82 for (
int j = 1; j < all_rows(i).GetM(); j++)
83 if (all_rows(i)(j) < all_rows(i)(j-1))
88 cout <<
"Row numbers must be sorted in this function" << endl;
97 for (
int i = 0; i < all_rows.GetM(); i++)
98 for (
int j = 0; j < all_rows(i).GetM(); j++)
99 if (all_rows(i)(j)+1 > nglob)
100 nglob = all_rows(i)(j)+1;
105 for (
int i = 1; i < nb_proc; i++)
107 int n = all_rows(i).GetM();
108 MPI_Send(&nglob, 1, MPI_INTEGER, i, 101, comm);
111 MPI_Send(&n, 1, MPI_INTEGER, i, 102, comm);
112 MPI_Send(all_rows(i).GetData(), all_rows(i).GetM(),
113 MPI_INTEGER, i, 103, comm);
118 row_num = all_rows(0);
121 Vector<int> MinProc(nglob);
122 MinProc.Fill(nb_proc);
123 for (
int i = 0; i < all_rows.GetM(); i++)
124 for (
int j = 0; j < all_rows(i).GetM(); j++)
125 if (MinProc(all_rows(i)(j)) > i)
126 MinProc(all_rows(i)(j)) = i;
130 for (
int i = 0; i < all_rows.GetM(); i++)
133 for (
int j = 0; j < all_rows(i).GetM(); j++)
134 if (MinProc(all_rows(i)(j)) < i)
137 IVect num(nb_overlap), proc(nb_overlap);
139 for (
int j = 0; j < all_rows(i).GetM(); j++)
140 if (MinProc(all_rows(i)(j)) < i)
143 proc(nb_overlap) = MinProc(all_rows(i)(j));
155 MPI_Send(&nb_overlap, 1, MPI_INTEGER, i, 104, comm);
158 MPI_Send(num.GetData(), nb_overlap,
159 MPI_INTEGER, i, 105, comm);
160 MPI_Send(proc.GetData(), nb_overlap,
161 MPI_INTEGER, i, 106, comm);
168 for (
int i = 0; i < all_rows.GetM(); i++)
169 for (
int j = 0; j < all_rows(i).GetM(); j++)
170 MinProc(all_rows(i)(j))++;
172 int nb_shared_row = 0;
173 for (
int i = 0; i < nglob; i++)
177 MinProc(i) = nb_shared_row;
185 Vector<IVect> ListProcRow(nb_shared_row);
186 for (
int i = 0; i < all_rows.GetM(); i++)
187 for (
int j = 0; j < all_rows(i).GetM(); j++)
189 int n = all_rows(i)(j);
192 int nloc = MinProc(n);
193 ListProcRow(nloc).PushBack(i);
198 for (
int i = 0; i < all_rows.GetM(); i++)
201 Vector<bool> ProcUsed(nb_proc);
202 ProcUsed.Fill(
false);
203 for (
int j = 0; j < all_rows(i).GetM(); j++)
205 int n = all_rows(i)(j);
208 int nloc = MinProc(n);
209 for (
int k = 0; k < ListProcRow(nloc).GetM(); k++)
210 ProcUsed(ListProcRow(nloc)(k)) =
true;
214 int nb_proc_interac = 0;
215 for (
int k = 0; k < ProcUsed.GetM(); k++)
216 if ((k != i) && (ProcUsed(k)))
219 Vector<int> matching_proc(nb_proc_interac);
220 Vector<Vector<int> > matching_row(nb_proc_interac);
222 for (
int k = 0; k < ProcUsed.GetM(); k++)
223 if ((k != i) && (ProcUsed(k)))
226 int nb_row_interac = 0;
227 for (
int j = 0; j < all_rows(i).GetM(); j++)
229 int n = all_rows(i)(j);
232 int nloc = MinProc(n);
234 k2 < ListProcRow(nloc).GetM(); k2++)
235 if (ListProcRow(nloc)(k2) == k)
241 matching_proc(nb_proc_interac) = k;
242 matching_row(nb_proc_interac).Reallocate(nb_row_interac);
244 for (
int j = 0; j < all_rows(i).GetM(); j++)
246 int n = all_rows(i)(j);
249 int nloc = MinProc(n);
251 k2 < ListProcRow(nloc).GetM(); k2++)
252 if (ListProcRow(nloc)(k2) == k)
254 matching_row(nb_proc_interac)
255 (nb_row_interac) = j;
268 MatchingProc = matching_proc;
269 MatchingDofNumber = matching_row;
273 MPI_Send(&nb_proc_interac, 1, MPI_INTEGER, i, 107, comm);
274 if (nb_proc_interac > 0)
276 MPI_Send(matching_proc.GetData(), nb_proc_interac,
277 MPI_INTEGER, i, 108, comm);
279 for (
int k = 0; k < nb_proc_interac; k++)
281 int nb_row = matching_row(k).GetM();
282 MPI_Send(&nb_row, 1, MPI_INTEGER, i, 109, comm);
283 MPI_Send(matching_row(k).GetData(), nb_row,
284 MPI_INTEGER, i, 110, comm);
293 MPI_Status status;
int n;
294 MPI_Recv(&nglob, 1, MPI_INTEGER, 0, 101, comm, &status);
297 MPI_Recv(&n, 1, MPI_INTEGER, 0, 102, comm, &status);
298 row_num.Reallocate(n);
299 MPI_Recv(row_num.GetData(), n, MPI_INTEGER, 0, 103, comm, &status);
303 MPI_Recv(&n, 1, MPI_INTEGER, 0, 104, comm, &status);
306 overlap_num.Reallocate(n);
307 proc_num.Reallocate(n);
308 MPI_Recv(overlap_num.GetData(), n, MPI_INTEGER,0, 105, comm, &status);
309 MPI_Recv(proc_num.GetData(), n, MPI_INTEGER, 0, 106, comm, &status);
318 MPI_Recv(&n, 1, MPI_INTEGER, 0, 107, comm, &status);
321 MatchingProc.Reallocate(n);
322 MatchingDofNumber.Reallocate(n);
323 MPI_Recv(MatchingProc.GetData(), n,
324 MPI_INTEGER, 0, 108, comm, &status);
326 for (
int k = 0; k < MatchingProc.GetM(); k++)
328 MPI_Recv(&n, 1, MPI_INTEGER, 0, 109, comm, &status);
329 MatchingDofNumber(k).Reallocate(n);
330 MPI_Recv(MatchingDofNumber(k).GetData(), n, MPI_INTEGER,
331 0, 110, comm, &status);
336 MatchingProc.Clear();
337 MatchingDofNumber.Clear();
345 int DistributedMatrixIntegerArray
346 ::ConstructArrays(IVect& row_num, IVect& overlap_num, IVect& proc_num,
348 Vector<IVect>& MatchingDofNumber,
const MPI_Comm& comm)
352 for (
int j = 1; j < row_num.GetM(); j++)
353 if (row_num(j) < row_num(j-1))
358 cout <<
"Row numbers must be sorted in this function" << endl;
364 int nb_proc; MPI_Comm_size(comm, &nb_proc);
365 int rank_proc; MPI_Comm_rank(comm, &rank_proc);
366 Vector<IVect> all_rows(nb_proc);
369 all_rows(0) = row_num;
370 int nodl_par; MPI_Status status;
371 for (
int i = 1; i < nb_proc; i++)
373 MPI_Recv(&nodl_par, 1, MPI_INTEGER, i, 13, comm, &status);
374 all_rows(i).Reallocate(nodl_par);
375 MPI_Recv(all_rows(i).GetData(), nodl_par,
376 MPI_INTEGER, i, 14, comm, &status);
381 int nodl = row_num.GetM();
382 MPI_Send(&nodl, 1, MPI_INTEGER, 0, 13, comm);
383 MPI_Send(row_num.GetData(), nodl, MPI_INTEGER, 0, 14, comm);
387 return ConstructArrays(all_rows, row_num, overlap_num, proc_num,
388 MatchingProc, MatchingDofNumber, comm,
false);
408 global_row_to_recv.Clear(); global_col_to_recv.Clear();
409 ptr_global_row_to_recv.Clear(); ptr_global_col_to_recv.Clear();
410 local_row_to_send.Clear(); local_col_to_send.Clear();
412 proc_col_to_recv.Clear(); proc_col_to_send.Clear();
413 proc_row_to_recv.Clear(); proc_row_to_send.Clear();
415 local_number_distant_values =
false;
416 size_max_distant_row = 0;
417 size_max_distant_col = 0;
427 if (!local_number_distant_values)
431 for (
int i = 0; i < dist_row.GetM(); i++)
432 for (
int j = 0; j < dist_row(i).GetM(); j++)
433 dist_row(i).Index(j) = global_row_to_recv(dist_row(i).Index(j));
436 for (
int i = 0; i < dist_col.GetM(); i++)
437 for (
int j = 0; j < dist_col(i).GetM(); j++)
438 dist_col(i).Index(j) = global_col_to_recv(dist_col(i).Index(j));
441 EraseArrayForMltAdd();
468 template<
class T>
template<
class TypeDist>
477 MPI_Comm& comm = comm_;
480 for (
int i = 0; i < dist_proc.GetM(); i++)
481 N += dist_proc(i).GetM();
485 int nb_proc; MPI_Comm_size(comm, &nb_proc);
487 permut.Fill();
long nb = 0;
488 nb_inter_per_proc.Fill(0);
489 for (
int i = 0; i < dist_proc.GetM(); i++)
490 for (
int j = 0; j < dist_proc(i).GetM(); j++)
492 all_proc(nb) = dist_proc(i)(j);
493 all_num(nb) = dist_val(i).Index(j);
494 nb_inter_per_proc(dist_proc(i)(j))++;
498 Sort(all_proc, all_num, permut);
501 int nb_global_proc = 0;
502 for (
int i = 0; i < nb_inter_per_proc.GetM(); i++)
503 if (nb_inter_per_proc(i) > 0)
506 proc_glob.Reallocate(nb_global_proc);
513 nb_num_per_proc.Fill(0);
515 for (
int p = 0; p < nb_inter_per_proc.GetM(); p++)
516 if (nb_inter_per_proc(p) > 0)
518 long size = nb_inter_per_proc(p);
519 Sort(offset, offset+size-1, all_num, permut);
520 int prec = all_num(offset);
522 for (
long j = 1; j < size; j++)
523 if (all_num(offset+j) != prec)
525 prec = all_num(offset+j);
529 nb_num_per_proc(p) = nb_glob_p;
530 nb_glob += nb_glob_p;
531 proc_glob(nb_global_proc) = p;
537 all_proc.Clear();
IVect local(N);
538 offset = 0; glob_num.Reallocate(nb_glob);
539 ptr_glob_num.Reallocate(nb_global_proc+1);
540 nb_glob = 0; nb_global_proc = 0; ptr_glob_num(0) = 0;
541 for (
int p = 0; p < nb_inter_per_proc.GetM(); p++)
542 if (nb_inter_per_proc(p) > 0)
544 long size = nb_inter_per_proc(p);
545 int prec = all_num(offset);
546 ptr_glob_num(nb_global_proc+1) = ptr_glob_num(nb_global_proc)
547 + nb_num_per_proc(p);
549 glob_num(nb_glob) = prec; nb_glob++;
551 for (
long j = 0; j < size; j++)
553 if (all_num(offset+j) != prec)
555 prec = all_num(offset+j);
556 glob_num(nb_glob) = prec;
557 nb_glob_p++; nb_glob++;
560 local(offset+j) = nb_glob-1;
569 for (
int i = 0; i < N; i++)
570 inv_permut(permut(i)) = i;
573 for (
int i = 0; i < dist_val.GetM(); i++)
574 for (
int j = 0; j < dist_val(i).GetM(); j++)
576 int n = inv_permut(nb_glob_d);
577 dist_val(i).Index(j) = local(n);
582 IVect nb_num_send(nb_proc);
583 MPI_Alltoall(nb_num_per_proc.GetData(), 1, MPI_INTEGER,
584 nb_num_send.GetData(), 1, MPI_INTEGER, comm);
590 for (
int p = 0; p < nb_proc; p++)
591 if (nb_num_per_proc(p) > 0)
593 int size = nb_num_per_proc(p);
594 MPI_Isend(&glob_num(ptr_glob_num(nb_global_proc)), size,
595 MPI_INTEGER, p, 17, comm, &request_send(p));
600 int nb_local_proc = 0;
601 for (
int p = 0; p < nb_proc; p++)
602 if (nb_num_send(p) > 0)
605 local_num.Reallocate(nb_local_proc);
606 proc_local.Reallocate(nb_local_proc);
609 MPI_Status status; nb_local_proc = 0;
610 for (
int p = 0; p < nb_proc; p++)
611 if (nb_num_send(p) > 0)
613 proc_local(nb_local_proc) = p;
614 local_num(nb_local_proc).Reallocate(nb_num_send(p));
615 MPI_Recv(local_num(nb_local_proc).GetData(), nb_num_send(p),
616 MPI_INTEGER, p, 17, comm, &status);
621 for (
int i = 0; i < request_send.GetM(); i++)
622 if (nb_num_per_proc(i) > 0)
623 MPI_Wait(&request_send(i), &status);
626 IVect Glob_to_local(this->GetGlobalM());
627 const IVect& RowNumber = this->GetGlobalRowNumber();
628 Glob_to_local.Fill(-1);
629 for (
int i = 0; i < RowNumber.GetM(); i++)
630 Glob_to_local(RowNumber(i)) = i;
633 for (
int i = 0; i < local_num.GetM(); i++)
634 for (
int j = 0; j < local_num(i).GetM(); j++)
635 local_num(i)(j) = Glob_to_local(local_num(i)(j));
640 template<
class T>
template<
class T2>
643 const IVect& ptr_num_recv,
const IVect& proc_recv,
648 const MPI_Comm& comm = comm_;
651 xrecv_tmp(proc_recv.GetM());
655 for (
int i = 0; i < proc_send.GetM(); i++)
657 int nb = num_send(i).GetM();
658 xsend(i).Reallocate(nb);
659 for (
int j = 0; j < nb; j++)
660 xsend(i)(j) = X(num_send(i)(j));
663 MpiIsend(comm, xsend(i), xsend_tmp(i), nb, proc_send(i), tag);
669 for (
int i = 0; i < proc_recv.GetM(); i++)
671 int nb = ptr_num_recv(i+1) - ptr_num_recv(i); N += nb;
672 xrecv(i).Reallocate(nb);
674 MpiIrecv(comm, xrecv(i), xrecv_tmp(i), nb, proc_recv(i), tag);
679 for (
int i = 0; i < request_send.GetM(); i++)
680 MPI_Wait(&request_send(i), &status);
682 for (
int i = 0; i < request_recv.GetM(); i++)
683 MPI_Wait(&request_recv(i), &status);
687 for (
int i = 0; i < request_recv.GetM(); i++)
688 MpiCompleteIrecv(xrecv(i), xrecv_tmp(i), xrecv(i).GetM());
691 Xcol.Reallocate(N); N = 0;
692 for (
int i = 0; i < proc_recv.GetM(); i++)
693 for (
int j = 0; j < ptr_num_recv(i+1) - ptr_num_recv(i); j++)
694 Xcol(N++) = xrecv(i)(j);
699 template<
class T>
template<
class T2>
702 const IVect& ptr_num_recv,
const IVect& proc_recv,
707 const MPI_Comm& comm = comm_;
710 xrecv_tmp(proc_send.GetM());
714 for (
int i = 0; i < proc_recv.GetM(); i++)
716 int nb = ptr_num_recv(i+1) - ptr_num_recv(i);
717 xsend(i).Reallocate(nb);
718 for (
int j = 0; j < nb; j++)
719 xsend(i)(j) = Xcol(N++);
722 MpiIsend(comm, xsend(i), xsend_tmp(i), nb, proc_recv(i), tag);
727 for (
int i = 0; i < proc_send.GetM(); i++)
729 int nb = num_send(i).GetM();
730 xrecv(i).Reallocate(nb);
732 MpiIrecv(comm, xrecv(i), xrecv_tmp(i), nb, proc_send(i), tag);
737 for (
int i = 0; i < request_send.GetM(); i++)
738 MPI_Wait(&request_send(i), &status);
740 for (
int i = 0; i < request_recv.GetM(); i++)
741 MPI_Wait(&request_recv(i), &status);
745 for (
int i = 0; i < request_recv.GetM(); i++)
746 MpiCompleteIrecv(xrecv(i), xrecv_tmp(i), xrecv(i).GetM());
749 for (
int i = 0; i < num_send.GetM(); i++)
750 for (
int j = 0; j < num_send(i).GetM(); j++)
751 X(num_send(i)(j)) += xrecv(i)(j);
765 const IVect& num_recv,
const IVect& ptr_num_recv,
766 const IVect& proc_recv,
771 const MPI_Comm& comm = comm_;
775 for (
int i = 0; i < proc_recv.GetM(); i++)
777 int nb = ptr_num_recv(i+1) - ptr_num_recv(i);
778 xsend(i).Reallocate(2*nb);
779 for (
int j = 0; j < nb; j++)
781 xsend(i)(j) = Xcol(N);
782 xsend(i)(nb+j) = Xcol_proc(N);
786 MPI_Isend(xsend(i).GetDataVoid(), 2*nb,
787 GetMpiDataType(Xcol), proc_recv(i), tag, comm, &request_send(i));
792 for (
int i = 0; i < proc_send.GetM(); i++)
794 int nb = num_send(i).GetM();
795 xrecv(i).Reallocate(2*nb);
796 MPI_Irecv(xrecv(i).GetDataVoid(), 2*nb,
797 GetMpiDataType(Xcol), proc_send(i), tag, comm, &request_recv(i));
802 for (
int i = 0; i < request_send.GetM(); i++)
803 MPI_Wait(&request_send(i), &status);
805 for (
int i = 0; i < request_recv.GetM(); i++)
806 MPI_Wait(&request_recv(i), &status);
810 for (
int i = 0; i < num_send.GetM(); i++)
811 for (
int j = 0; j < num_send(i).GetM(); j++)
813 int nb = num_send(i).GetM();
814 int proc = xrecv(i)(nb+j);
815 int col = xrecv(i)(j);
816 if (proc < Yproc(num_send(i)(j)))
818 Yproc(num_send(i)(j)) = proc;
819 Y(num_send(i)(j)) = col;
821 else if (proc == Yproc(num_send(i)(j)))
823 if (col < Y(num_send(i)(j)))
824 Y(num_send(i)(j)) = col;
840 comm_, nodl_scalar_, nb_unknowns_scal_, 13);
846 template<
class T>
template<
class T0,
class TypeDist>
851 for (
int i = 0; i < dist_vec.GetM(); i++)
853 int nb = 0, size = dist_vec(i).GetM();
854 for (
int j = 0; j < size; j++)
855 if (abs(dist_vec(i).Value(j)) > epsilon)
861 for (
int j = 0; j < size; j++)
863 num(j) = dist_vec(i).Index(j);
864 val(j) = dist_vec(i).Value(j);
865 proc(j) = dist_proc(i)(j);
868 dist_vec(i).Reallocate(nb);
869 dist_proc(i).Reallocate(nb);
871 for (
int j = 0; j < size; j++)
872 if (abs(val(j)) > epsilon)
874 dist_vec(i).Index(nb) = num(j);
875 dist_vec(i).Value(nb) = val(j);
876 dist_proc(i)(nb) = proc(j);
885 template<
class T>
template<
class T0>
889 for (
int i = 0; i < dist_col.GetM(); i++)
890 for (
int j = 0; j < dist_col(i).GetM(); j++)
891 vec_sum(i) += abs(dist_col(i).Value(j));
896 template<
class T>
template<
class T0>
900 T0 zero; SetComplexZero(zero);
903 for (
int i = 0; i < dist_row.GetM(); i++)
904 for (
int j = 0; j < dist_row(i).GetM(); j++)
906 int jrow = dist_row(i).Index(j);
907 Y(jrow) += abs(dist_row(i).Value(j));
910 AssembleRowValues(Y, vec_sum);
915 template<
class T>
template<
class T0>
919 T0 zero; SetComplexZero(zero);
922 for (
int i = 0; i < dist_col.GetM(); i++)
923 for (
int j = 0; j < dist_col(i).GetM(); j++)
925 int jrow = dist_col(i).Index(j);
926 Y(jrow) += abs(dist_col(i).Value(j));
929 AssembleColValues(Y, vec_sum);
934 template<
class T>
template<
class T0>
938 for (
int i = 0; i < dist_row.GetM(); i++)
939 for (
int j = 0; j < dist_row(i).GetM(); j++)
940 vec_sum(i) += abs(dist_row(i).Value(j));
958 if (local_number_distant_values)
961 local_number_distant_values =
true;
962 const MPI_Comm& comm = comm_;
963 int nb_proc; MPI_Comm_size(comm, &nb_proc);
968 for (
int i = 0; i < dist_col.GetM(); i++)
969 N += dist_col(i).GetM();
971 MPI_Allreduce(&N, &size_max_distant_col, 1, MPI_LONG, MPI_MAX, comm);
973 for (
int i = 0; i < dist_row.GetM(); i++)
974 N += dist_row(i).GetM();
976 MPI_Allreduce(&N, &size_max_distant_row, 1, MPI_INTEGER, MPI_MAX, comm);
978 if (size_max_distant_col > 0)
979 SortAndAssembleDistantInteractions(dist_col, proc_col,
981 ptr_global_col_to_recv,
983 local_col_to_send, proc_col_to_send);
985 if (size_max_distant_row > 0)
986 SortAndAssembleDistantInteractions(dist_row, proc_row,
988 ptr_global_row_to_recv,
990 local_row_to_send, proc_row_to_send);
995 template<
class T>
template<
class T2>
999 ScatterValues(X, global_row_to_recv, ptr_global_row_to_recv,
1001 local_row_to_send, proc_row_to_send, Xcol);
1010 template<
class T>
template<
class T2>
1014 ScatterValues(X, global_col_to_recv, ptr_global_col_to_recv,
1016 local_col_to_send, proc_col_to_send, Xcol);
1026 template<
class T>
template<
class T2>
1030 AssembleValues(Xrow, global_row_to_recv, ptr_global_row_to_recv,
1032 local_row_to_send, proc_row_to_send, X);
1037 template<
class T>
template<
class T2>
1041 AssembleValues(Xcol, global_col_to_recv, ptr_global_col_to_recv,
1043 local_col_to_send, proc_col_to_send, X);
1048 template<
class T>
template<
class T2>
1052 AssembleVector(X, MPI_SUM, *ProcSharingRows, *SharingRowNumbers,
1053 comm_, nodl_scalar_, nb_unknowns_scal_, 14);
1059 template<
class T2,
class Storage2,
class Allocator2,
1060 class T4,
class Storage4,
class Allocator4>
1066 if (Trans.NoTrans())
1068 for (
int i = 0; i < dist_col.GetM(); i++)
1069 for (
int j = 0; j < dist_col(i).GetM(); j++)
1071 int jloc = dist_col(i).Index(j);
1072 Y(i) += dist_col(i).Value(j)*X(jloc);
1077 T4 zero; SetComplexZero(zero);
1078 Y.Reallocate(global_col_to_recv.GetM());
1082 for (
int i = 0; i < dist_col.GetM(); i++)
1083 for (
int j = 0; j < dist_col(i).GetM(); j++)
1085 int jrow = dist_col(i).Index(j);
1086 Y(jrow) += dist_col(i).Value(j)*X(i);
1091 for (
int i = 0; i < dist_col.GetM(); i++)
1092 for (
int j = 0; j < dist_col(i).GetM(); j++)
1094 int jrow = dist_col(i).Index(j);
1095 Y(jrow) += conjugate(dist_col(i).Value(j))*X(i);
1104 template<
class T2,
class Storage2,
class Allocator2,
1105 class T4,
class Storage4,
class Allocator4>
1111 if (Trans.NoTrans())
1113 T4 zero; SetComplexZero(zero);
1114 Y.Reallocate(global_row_to_recv.GetM());
1116 for (
int i = 0; i < dist_row.GetM(); i++)
1117 for (
int j = 0; j < dist_row(i).GetM(); j++)
1119 int jrow = dist_row(i).Index(j);
1120 Y(jrow) += dist_row(i).Value(j)*X(i);
1127 for (
int i = 0; i < dist_row.GetM(); i++)
1128 for (
int j = 0; j < dist_row(i).GetM(); j++)
1130 int jloc = dist_row(i).Index(j);
1131 Y(i) += dist_row(i).Value(j)*X(jloc);
1136 for (
int i = 0; i < dist_row.GetM(); i++)
1137 for (
int j = 0; j < dist_row(i).GetM(); j++)
1139 int jloc = dist_row(i).Index(j);
1140 Y(i) += conjugate(dist_row(i).Value(j))*X(jloc);
1165 IVect& proc_col_,
int jglob,
int proc2,
const T& val)
1168 int size_row = dist_col_.GetM();
1169 while ((pos < size_row) && (dist_col_.Index(pos) < jglob))
1172 if ((pos < size_row) && (dist_col_.Index(pos) == jglob))
1175 dist_col_.Value(pos) += val;
1181 IVect index(size_row), proc(size_row);
1182 for (
int k = 0; k < size_row; k++)
1184 index(k) = dist_col_.Index(k);
1185 value(k) = dist_col_.Value(k);
1186 proc(k) = proc_col_(k);
1189 dist_col_.Reallocate(size_row+1);
1190 proc_col_.Reallocate(size_row+1);
1191 for (
int k = 0; k < pos; k++)
1193 dist_col_.Index(k) = index(k);
1194 dist_col_.Value(k) = value(k);
1195 proc_col_(k) = proc(k);
1198 dist_col_.Index(pos) = jglob;
1199 dist_col_.Value(pos) = val;
1200 proc_col_(pos) = proc2;
1201 for (
int k = pos+1; k <= size_row; k++)
1203 dist_col_.Index(k) = index(k-1);
1204 dist_col_.Value(k) = value(k-1);
1205 proc_col_(k) = proc(k-1);
1223 int nb_proc; MPI_Comm_size(comm, &nb_proc);
1224 int rank; MPI_Comm_rank(comm, &rank);
1228 for (
int i = 0; i < nb_proc; i++)
1231 MPI_Isend(&nsend_int(i), 1, MPI_INTEGER, i, 4, comm, &request(i));
1234 if (nsend_int(i) > 0)
1236 MPI_Isend(EntierToSend(i).GetData(), nsend_int(i),
1237 MPI_INTEGER, i, 5, comm, &request(i+nb_proc));
1239 if (EntierToSend(i)(0) > 0)
1240 request(i+2*nb_proc) =
1241 MpiIsend(comm, FloatToSend(i), FloatToSend_tmp(i),
1242 FloatToSend(i).GetM(), i, 6);
1250 for (
int i = 0; i < nb_proc; i++)
1252 MPI_Recv(&nrecv_int(i), 1, MPI_INTEGER, i, 4, comm, &status);
1255 for (
int i = 0; i < nb_proc; i++)
1257 MPI_Wait(&request(i), &status);
1259 for (
int i = 0; i < nb_proc; i++)
1261 if (nrecv_int(i) > 0)
1263 EntierToRecv(i).Reallocate(nrecv_int(i));
1264 MPI_Recv(EntierToRecv(i).GetData(), nrecv_int(i),
1265 MPI_INTEGER, i, 5, comm, &status);
1268 EntierToRecv(i).Clear();
1272 for (
int i = 0; i < nb_proc; i++)
1273 if (nsend_int(i) > 0)
1274 MPI_Wait(&request(i+nb_proc), &status);
1276 for (
int i = 0; i < nb_proc; i++)
1278 if (nrecv_int(i) > 0)
1280 int nb_float = EntierToRecv(i)(0);
1283 FloatToRecv(i).Reallocate(nb_float);
1284 MpiRecv(comm, FloatToRecv(i), FloatToRecv_tmp,
1285 nb_float, i, 6, status);
1288 FloatToRecv(i).Clear();
1291 FloatToRecv(i).Clear();
1295 for (
int i = 0; i < nb_proc; i++)
1296 if (nsend_int(i) > 0)
1297 if (EntierToSend(i)(0) > 0)
1298 MPI_Wait(&request(i + 2*nb_proc), &status);
1301 for (
int i = 0; i < nb_proc; i++)
1304 EntierToSend(i).Clear();
1305 FloatToSend(i).Clear();
1317 IVect& Glob_to_local,
const IVect& OverlappedCol,
1318 const IVect& OverlapProcNumber,
1321 int nb_proc; MPI_Comm_size(comm, &nb_proc);
1326 for (
int i = 0; i < nb_proc; i++)
1328 if (FloatToRecv(i).GetM() > 0)
1330 int nrow = EntierToRecv(i)(1);
1332 nrecv_int(i) = 2;
int nrecv_float = 0;
1334 for (
int j = 0; j < nrow; j++)
1336 int iglob = EntierToRecv(i)(nrecv_int(i)++);
1337 int irow = Glob_to_local(iglob);
1338 int size_row = EntierToRecv(i)(nrecv_int(i)++);
1342 proc_num.Reallocate(size_row);
1343 for (
int k = 0; k < size_row; k++)
1345 index(k) = EntierToRecv(i)(nrecv_int(i)++);
1346 proc_num(k) = EntierToRecv(i)(nrecv_int(i)++);
1347 values(k) = FloatToRecv(i)(nrecv_float++);
1352 for (
int k = 0; k < size_row; k++)
1354 index(k) = EntierToRecv(i)(nrecv_int(i)++);
1355 values(k) = FloatToRecv(i)(nrecv_float++);
1361 if (OverlappedCol(irow) == -1)
1366 bool index_sorted =
true;
1367 for (
int k = 1; k < size_row; k++)
1368 if (index(k) < index(k-1))
1369 index_sorted =
false;
1372 Sort(size_row, index, values, proc_num);
1374 int size_rowB = B.GetRowSize(irow);
1375 IVect new_col(size_rowB + size_row), new_proc(size_rowB + size_row);
1376 Vector<T> new_val(size_rowB + size_row);
1378 for (
int k = 0; k < size_row; k++)
1380 while ((p < size_rowB) && (B.Index(irow, p) < index(k)))
1382 new_col(nb) = B.Index(irow, p);
1383 new_val(nb) = B.Value(irow, p);
1384 new_proc(nb) = procB(irow)(p);
1388 if ((p < size_rowB) && (B.Index(irow, p) == index(k)))
1391 new_col(nb) = index(k);
1392 new_val(nb) = values(k) + B.Value(irow, p);
1393 new_proc(nb) = procB(irow)(p);
1399 new_col(nb) = index(k);
1400 new_val(nb) = values(k);
1401 new_proc(nb) = proc_num(k);
1406 while (p < size_rowB)
1408 new_col(nb) = B.Index(irow, p);
1409 new_val(nb) = B.Value(irow, p);
1410 new_proc(nb) = procB(irow)(p);
1414 B.ReallocateRow(irow, nb);
1415 procB(irow).Reallocate(nb);
1416 for (
int k = 0; k < nb; k++)
1418 B.Index(irow, k) = new_col(k);
1419 B.Value(irow, k) = new_val(k);
1420 procB(irow)(k) = new_proc(k);
1426 B.AddInteraction(irow, index(0), values(0));
1428 B.AddInteractionRow(irow, size_row, index, values);
1433 int irow_ = OverlappedCol(irow);
1434 int proc = OverlapProcNumber(irow_);
1436 int offset_int(2), offset_float(0);
1437 if (nsend_int(proc) == 0)
1439 nsend_int(proc) = 2;
1440 EntierToSend(proc).Reallocate(nfac*size_row+4);
1441 FloatToSend(proc).Reallocate(size_row);
1442 EntierToSend(proc)(0) = 0;
1443 EntierToSend(proc)(1) = 0;
1447 offset_int = EntierToSend(proc).GetM();
1448 offset_float = FloatToSend(proc).GetM();
1449 EntierToSend(proc).Resize(nfac*size_row+2+offset_int);
1450 FloatToSend(proc).Resize(size_row+offset_float);
1453 nsend_int(proc) += nfac*size_row+2;
1454 EntierToSend(proc)(0) += size_row;
1455 EntierToSend(proc)(1)++;
1456 EntierToSend(proc)(offset_int++) = iglob;
1457 EntierToSend(proc)(offset_int++) = size_row;
1458 for (
int k = 0; k < size_row; k++)
1460 EntierToSend(proc)(offset_int++) = index(k);
1462 EntierToSend(proc)(offset_int++) = proc_num(k);
1464 FloatToSend(proc)(offset_float++) = values(k);
1480 IVect& Glob_to_local,
const IVect& OverlappedCol,
1481 const IVect& OverlapProcNumber,
1484 int nb_proc; MPI_Comm_size(comm, &nb_proc);
1489 for (
int i = 0; i < nb_proc; i++)
1491 if (FloatToRecv(i).GetM() > 0)
1493 int ncol = EntierToRecv(i)(1);
1495 nrecv_int(i) = 2;
int nrecv_float = 0;
1497 for (
int j = 0; j < ncol; j++)
1499 int iglob = EntierToRecv(i)(nrecv_int(i)++);
1500 int irow = Glob_to_local(iglob);
1501 int size_col = EntierToRecv(i)(nrecv_int(i)++);
1505 proc_num.Reallocate(size_col);
1506 for (
int k = 0; k < size_col; k++)
1508 index(k) = EntierToRecv(i)(nrecv_int(i)++);
1509 proc_num(k) = EntierToRecv(i)(nrecv_int(i)++);
1510 values(k) = FloatToRecv(i)(nrecv_float++);
1515 for (
int k = 0; k < size_col; k++)
1517 index(k) = EntierToRecv(i)(nrecv_int(i)++);
1518 values(k) = FloatToRecv(i)(nrecv_float++);
1524 if (OverlappedCol(irow) == -1)
1529 bool index_sorted =
true;
1530 for (
int k = 1; k < size_col; k++)
1531 if (index(k) < index(k-1))
1532 index_sorted =
false;
1535 Sort(size_col, index, values, proc_num);
1537 int size_colB = B.GetColumnSize(irow);
1538 IVect new_col(size_colB + size_col), new_proc(size_colB + size_col);
1539 Vector<T> new_val(size_colB + size_col);
1541 for (
int k = 0; k < size_col; k++)
1543 while ((p < size_colB) && (B.Index(irow, p) < index(k)))
1545 new_col(nb) = B.Index(irow, p);
1546 new_val(nb) = B.Value(irow, p);
1547 new_proc(nb) = procB(irow)(p);
1551 if ((p < size_colB) && (B.Index(irow, p) == index(k)))
1554 new_col(nb) = index(k);
1555 new_val(nb) = values(k) + B.Value(irow, p);
1556 new_proc(nb) = procB(irow)(p);
1562 new_col(nb) = index(k);
1563 new_val(nb) = values(k);
1564 new_proc(nb) = proc_num(k);
1569 while (p < size_colB)
1571 new_col(nb) = B.Index(irow, p);
1572 new_val(nb) = B.Value(irow, p);
1573 new_proc(nb) = procB(irow)(p);
1577 B.ReallocateColumn(irow, nb);
1578 procB(irow).Reallocate(nb);
1579 for (
int k = 0; k < nb; k++)
1581 B.Index(irow, k) = new_col(k);
1582 B.Value(irow, k) = new_val(k);
1583 procB(irow)(k) = new_proc(k);
1589 B.AddInteraction(index(0), irow, values(0));
1591 B.AddInteractionColumn(irow, size_col, index, values);
1596 int irow_ = OverlappedCol(irow);
1597 int proc = OverlapProcNumber(irow_);
1599 int offset_int(2), offset_float(0);
1600 if (nsend_int(proc) == 0)
1602 nsend_int(proc) = 2;
1603 EntierToSend(proc).Reallocate(nfac*size_col+4);
1604 FloatToSend(proc).Reallocate(size_col);
1605 EntierToSend(proc)(0) = 0;
1606 EntierToSend(proc)(1) = 0;
1610 offset_int = EntierToSend(proc).GetM();
1611 offset_float = FloatToSend(proc).GetM();
1612 EntierToSend(proc).Resize(nfac*size_col+2+offset_int);
1613 FloatToSend(proc).Resize(size_col+offset_float);
1616 nsend_int(proc) += nfac*size_col+2;
1617 EntierToSend(proc)(0) += size_col;
1618 EntierToSend(proc)(1)++;
1619 EntierToSend(proc)(offset_int++) = iglob;
1620 EntierToSend(proc)(offset_int++) = size_col;
1621 for (
int k = 0; k < size_col; k++)
1623 EntierToSend(proc)(offset_int++) = index(k);
1625 EntierToSend(proc)(offset_int++) = proc_num(k);
1627 FloatToSend(proc)(offset_float++) = values(k);
1637 template<
class T>
template<
class TypeDist>
1644 typedef typename TypeDist::value_type Vect1;
1645 typedef typename Vect1::value_type T1;
1646 for (
int i = 0; i < dist_col_.GetM(); i++)
1647 if (IsRowDropped(i))
1649 dist_col_(i).Clear();
1650 proc_col_(i).Clear();
1653 for (
int j = 0; j < dist_row_.GetM(); j++)
1656 for (
int iloc = 0; iloc < dist_row_(j).GetM(); iloc++)
1657 if (IsRowDroppedDistant(dist_row_(j).Index(iloc)))
1662 int size = dist_row_(j).GetM();
1664 for (
int iloc = 0; iloc < dist_row_(j).GetM(); iloc++)
1666 row_num(iloc) = dist_row_(j).Index(iloc);
1667 val(iloc) = dist_row_(j).Value(iloc);
1668 proc(iloc) = proc_row_(j)(iloc);
1671 dist_row_(j).Reallocate(size-nb);
1672 proc_row_(j).Reallocate(size-nb);
1674 for (
int iloc = 0; iloc < size; iloc++)
1675 if (!IsRowDroppedDistant(row_num(iloc)))
1677 dist_row_(j).Index(nb) = row_num(iloc);
1678 dist_row_(j).Value(nb) = val(iloc);
1679 proc_row_(j)(nb) = proc(iloc);
1696 GlobalRowNumbers = NULL;
1697 OverlapProcNumbers = NULL;
1698 OverlapRowNumbers = NULL;
1699 ProcSharingRows = NULL;
1700 SharingRowNumbers = NULL;
1702 nb_unknowns_scal_ = 1;
1704 comm_ = MPI_COMM_SELF;
1706 local_number_distant_values =
false;
1707 size_max_distant_row = 0;
1708 size_max_distant_col = 0;
1719 GlobalRowNumbers = NULL;
1720 OverlapProcNumbers = NULL;
1721 OverlapRowNumbers = NULL;
1722 ProcSharingRows = NULL;
1723 SharingRowNumbers = NULL;
1726 nb_unknowns_scal_ = 1;
1727 comm_ = MPI_COMM_SELF;
1729 dist_col.Reallocate(m);
1730 dist_row.Reallocate(n);
1731 proc_col.Reallocate(m);
1732 proc_row.Reallocate(n);
1734 local_number_distant_values =
false;
1735 size_max_distant_row = 0;
1736 size_max_distant_col = 0;
1751 int Nvol,
int nb_u,
IVect* MatchingProc,
1755 GlobalRowNumbers = row_num;
1756 OverlapRowNumbers = overlap_num;
1757 OverlapProcNumbers = proc_num;
1759 nodl_scalar_ = Nvol;
1760 nb_unknowns_scal_ = nb_u;
1761 ProcSharingRows = MatchingProc;
1762 SharingRowNumbers = MatchingDofNumber;
1773 nglob_ = Ainfo.nglob;
1774 GlobalRowNumbers = &Ainfo.GlobalRowNumbers;
1775 OverlapRowNumbers = &Ainfo.OverlapRowNumbers;
1776 OverlapProcNumbers = &Ainfo.OverlapProcNumbers;
1778 nodl_scalar_ = Ainfo.nodl_scalar;
1779 nb_unknowns_scal_ = Ainfo.nb_unknowns_scal;
1780 ProcSharingRows = &Ainfo.ProcSharingRows;
1781 SharingRowNumbers = &Ainfo.SharingRowNumbers;
1793 info.GlobalRowNumbers = row_num;
1794 info.nloc = row_num.GetM(); info.nb_unknowns_scal = 1;
1795 info.nodl_scalar = row_num.GetM();
1799 info.nglob = DistributedMatrixIntegerArray
1800 ::ConstructArrays(row_num, info.OverlapRowNumbers, info.OverlapProcNumbers,
1801 info.ProcSharingRows, info.SharingRowNumbers, comm);
1806 template<
class T>
template<
class T0>
1816 nb_unknowns_scal_ = A.nb_unknowns_scal_;
1828 const MPI_Comm& comm,
bool distribute_row)
1830 int nglob = DistributedMatrixIntegerArray
1831 ::ConstructArrays(all_rows, row_num, overlap_num, proc_num,
1832 MatchingProc, MatchingDofNumber, comm, distribute_row);
1836 GlobalRowNumbers = &row_num;
1837 OverlapRowNumbers = &overlap_num;
1838 OverlapProcNumbers = &proc_num;
1840 nodl_scalar_ = row_num.GetM();
1841 nb_unknowns_scal_ = 1;
1842 ProcSharingRows = &MatchingProc;
1843 SharingRowNumbers = &MatchingDofNumber;
1853 IVect& MatchingProc,
1856 int nglob = DistributedMatrixIntegerArray
1857 ::ConstructArrays(row_num, overlap_num, proc_num,
1858 MatchingProc, MatchingDofNumber, comm);
1862 GlobalRowNumbers = &row_num;
1863 OverlapRowNumbers = &overlap_num;
1864 OverlapProcNumbers = &proc_num;
1866 nodl_scalar_ = row_num.GetM();
1867 nb_unknowns_scal_ = 1;
1868 ProcSharingRows = &MatchingProc;
1869 SharingRowNumbers = &MatchingDofNumber;
1889 dist_col.Reallocate(m);
1890 dist_row.Reallocate(n);
1891 proc_col.Reallocate(m);
1892 proc_row.Reallocate(n);
1900 if (dist_col.GetM() != m)
1906 if (dist_row.GetM() != n)
1923 global_row_to_recv.Clear(); global_col_to_recv.Clear();
1924 ptr_global_row_to_recv.Clear(); ptr_global_col_to_recv.Clear();
1925 local_row_to_send.Clear(); local_col_to_send.Clear();
1926 proc_col_to_recv.Clear(); proc_col_to_send.Clear();
1927 proc_row_to_recv.Clear(); proc_row_to_send.Clear();
1928 size_max_distant_row = 0;
1929 size_max_distant_col = 0;
1930 local_number_distant_values =
false;
1950 template<
class T>
template<
class T2>
1954 dist_col.Reallocate(X.
dist_col.GetM());
1955 for (
int i = 0; i < dist_col.GetM(); i++)
1958 dist_row.Reallocate(X.
dist_row.GetM());
1959 for (
int i = 0; i < dist_row.GetM(); i++)
1963 proc_row = X.proc_row;
1973 nb_unknowns_scal_ = X.nb_unknowns_scal_;
1979 global_col_to_recv = X.global_col_to_recv;
1980 ptr_global_row_to_recv = X.ptr_global_row_to_recv;
1981 ptr_global_col_to_recv = X.ptr_global_col_to_recv;
1984 local_col_to_send = X.local_col_to_send;
1986 proc_col_to_send = X.proc_col_to_send;
1987 proc_row_to_recv = X.proc_row_to_recv;
1988 proc_row_to_send = X.proc_row_to_send;
1992 size_max_distant_col = X.size_max_distant_col;
1997 template<
class T>
template<
class T0>
2001 for (
int i = 0; i < dist_col.GetM(); i++)
2004 for (
int i = 0; i < dist_row.GetM(); i++)
2016 if (this->GlobalRowNumbers == NULL)
2018 cout <<
"You should call Init of DistributedMatrix" << endl;
2022 return *GlobalRowNumbers;
2031 if (this->GlobalRowNumbers == NULL)
2033 cout <<
"You should call Init of DistributedMatrix" << endl;
2037 return *GlobalRowNumbers;
2046 if (this->OverlapRowNumbers == NULL)
2048 cout <<
"You should call Init of DistributedMatrix" << endl;
2052 return *OverlapRowNumbers;
2061 if (this->OverlapRowNumbers == NULL)
2063 cout <<
"You should call Init of DistributedMatrix" << endl;
2067 return *OverlapRowNumbers;
2075 if (this->OverlapProcNumbers == NULL)
2077 cout <<
"You should call Init of DistributedMatrix" << endl;
2081 return *OverlapProcNumbers;
2090 if (this->OverlapProcNumbers == NULL)
2092 cout <<
"You should call Init of DistributedMatrix" << endl;
2096 return *OverlapProcNumbers;
2105 if (this->ProcSharingRows == NULL)
2107 cout <<
"You should call Init of DistributedMatrix" << endl;
2111 return *ProcSharingRows;
2120 if (this->ProcSharingRows == NULL)
2122 cout <<
"You should call Init of DistributedMatrix" << endl;
2126 return *ProcSharingRows;
2135 if (this->SharingRowNumbers == NULL)
2137 cout <<
"You should call Init of DistributedMatrix" << endl;
2141 return *SharingRowNumbers;
2150 if (this->SharingRowNumbers == NULL)
2152 cout <<
"You should call Init of DistributedMatrix" << endl;
2156 return *SharingRowNumbers;
2164 size_t taille =
sizeof(*this) +
sizeof(
int*)*(proc_row.GetM()+proc_col.GetM());
2165 taille +=
sizeof(
int*)*(local_row_to_send.GetM() + local_col_to_send.GetM()
2166 + dist_row.GetM() + dist_col.GetM());
2168 taille += global_row_to_recv.GetMemorySize() + global_col_to_recv.GetMemorySize() +
2169 ptr_global_row_to_recv.GetMemorySize() + ptr_global_col_to_recv.GetMemorySize() +
2170 proc_col_to_recv.GetMemorySize() + proc_col_to_send.GetMemorySize() +
2171 proc_row_to_recv.GetMemorySize() + proc_row_to_send.GetMemorySize();
2173 for (
int i = 0; i < proc_row.GetM(); i++)
2174 taille += proc_row(i).GetMemorySize();
2176 for (
int i = 0; i < proc_col.GetM(); i++)
2177 taille += proc_col(i).GetMemorySize();
2179 for (
int i = 0; i < local_row_to_send.GetM(); i++)
2180 taille += local_row_to_send(i).GetMemorySize();
2182 for (
int i = 0; i < local_col_to_send.GetM(); i++)
2183 taille += local_col_to_send(i).GetMemorySize();
2185 for (
int i = 0; i < dist_row.GetM(); i++)
2186 taille += dist_row(i).GetMemorySize();
2188 for (
int i = 0; i < dist_col.GetM(); i++)
2189 taille += dist_col(i).GetMemorySize();
2210 for (
int i = 0; i < dist_col.GetM(); i++)
2211 nnz += dist_col(i).GetM();
2213 for (
int i = 0; i < dist_row.GetM(); i++)
2214 nnz += dist_row(i).GetM();
2230 long size_int = 0, size = 0;
2231 for (
int i = 0; i < dist_col.GetM(); i++)
2233 size_int += 2*dist_col(i).GetM();
2234 size += dist_col(i).GetM();
2237 for (
int i = 0; i < dist_row.GetM(); i++)
2239 size_int += 2*dist_row(i).GetM();
2240 size += dist_row(i).GetM();
2243 size_int += 2*(global_row_to_recv.GetM() + global_col_to_recv.GetM());
2245 for (
int i = 0; i < local_row_to_send.GetM(); i++)
2246 size_int += local_row_to_send(i).GetM();
2248 for (
int i = 0; i < local_col_to_send.GetM(); i++)
2249 size_int += local_col_to_send(i).GetM();
2251 size_int += 2*(dist_col.GetM() + dist_row.GetM()) +
2252 2*(local_row_to_send.GetM() + local_col_to_send.GetM()) + 25;
2254 int ratio =
sizeof(T)/
sizeof(
int);
2256 return size + size_int/ratio;
2266 template<
class T>
template<
class T0>
2270 RemoveSmallEntryDistant(epsilon, dist_col, proc_col);
2271 RemoveSmallEntryDistant(epsilon, dist_row, proc_row);
2279 for (
int i = 0; i < dist_col.GetM(); i++)
2281 dist_col(i).Clear();
2282 proc_col(i).Clear();
2285 for (
int i = 0; i < dist_row.GetM(); i++)
2287 dist_row(i).Clear();
2288 proc_row(i).Clear();
2291 EraseArrayForMltAdd();
2299 for (
int i = 0; i < dist_col.GetM(); i++)
2302 for (
int i = 0; i < dist_row.GetM(); i++)
2316 for (
int i = 0; i < dist_col.GetM(); i++)
2317 for (
int j = 0; j < dist_col(i).GetM(); j++)
2323 for (
int i = 0; i < dist_row.GetM(); i++)
2324 for (
int j = 0; j < dist_row(i).GetM(); j++)
2337 template<
class T>
template<
class T0>
2340 for (
int i = 0; i < dist_col.GetM(); i++)
2341 dist_col(i).Fill(x);
2343 for (
int i = 0; i < dist_row.GetM(); i++)
2344 dist_row(i).Fill(x);
2352 for (
int i = 0; i < dist_col.GetM(); i++)
2353 dist_col(i).FillRand();
2355 for (
int i = 0; i < dist_row.GetM(); i++)
2356 dist_row(i).FillRand();
2366 #ifdef SELDON_CHECK_IO
2368 if (!FileStream.good())
2369 throw IOError(
"DistributedMatrix::WriteText(ofstream& FileStream)",
2370 "Stream is not ready.");
2375 for (
int i = 0; i < dist_col.GetM(); i++)
2376 N += dist_col(i).GetM();
2378 for (
int i = 0; i < dist_row.GetM(); i++)
2379 N += dist_row(i).GetM();
2381 long old_size = IndRow.GetM();
2382 IndRow.Resize(old_size+N);
2383 IndCol.Resize(old_size+N);
2384 Value.Resize(old_size+N);
2387 const IVect& global = this->GetGlobalRowNumber();
2389 for (
int i = 0; i < dist_col.GetM(); i++)
2390 for (
int j = 0; j < dist_col(i).GetM(); j++)
2392 IndRow(N) = global(i) + 1;
2393 IndCol(N) = dist_col(i).Index(j) + 1;
2394 if (local_number_distant_values)
2395 IndCol(N) = global_col_to_recv(dist_col(i).Index(j)) + 1;
2397 Value(N) = dist_col(i).Value(j);
2401 for (
int i = 0; i < dist_row.GetM(); i++)
2402 for (
int j = 0; j < dist_row(i).GetM(); j++)
2404 IndCol(N) = global(i) + 1;
2405 IndRow(N) = dist_row(i).Index(j) + 1;
2406 if (local_number_distant_values)
2407 IndRow(N) = global_row_to_recv(dist_row(i).Index(j)) + 1;
2409 Value(N) = dist_row(i).Value(j);
2414 for (
int i = 0; i < old_size; i++)
2416 IndRow(i) = global(IndRow(i)) + 1;
2417 IndCol(i) = global(IndCol(i)) + 1;
2421 WriteCoordinateMatrix(FileStream, IndRow, IndCol, Value, cplx);
2432 template<
class T2,
class T3,
class T4,
class Storage4,
class Allocator4>
2439 const MPI_Comm& comm = this->GetCommunicator();
2440 proceed_distant_row =
true;
2441 proceed_distant_col =
true;
2442 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2445 proceed_distant_row =
false;
2446 proceed_distant_col =
false;
2450 if (!this->IsReadyForMltAdd())
2459 if (this->GetMaxDataSizeDistantCol() == 0)
2460 proceed_distant_col =
false;
2462 if (this->GetMaxDataSizeDistantRow() == 0)
2463 proceed_distant_row =
false;
2467 SetComplexZero(zero);
2470 Y.SetData(Yres.GetM(), Yres.GetData());
2472 Y.Reallocate(Yres.GetM());
2477 if (proceed_distant_col)
2478 this->ScatterColValues(X, Xcol);
2484 template<
class T2,
class T3,
class T4,
class Storage4,
class Allocator4>
2492 if (proceed_distant_col)
2493 this->MltAddCol(SeldonNoTrans, Xcol, Y);
2497 if (proceed_distant_row)
2498 this->MltAddRow(SeldonNoTrans, X, Yrow);
2501 if (proceed_distant_row)
2502 this->AssembleRowValues(Yrow, Y);
2506 this->AssembleVec(Y);
2509 SetComplexZero(zero);
2519 Add(alpha, Y, Yres);
2526 template<
class T2,
class T3,
class T4,
class Storage4,
class Allocator4>
2533 const MPI_Comm& comm = this->GetCommunicator();
2534 proceed_distant_row =
true;
2535 proceed_distant_col =
true;
2536 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2539 proceed_distant_row =
false;
2540 proceed_distant_col =
false;
2544 if (!this->IsReadyForMltAdd())
2553 if (this->GetMaxDataSizeDistantCol() == 0)
2554 proceed_distant_col =
false;
2556 if (this->GetMaxDataSizeDistantRow() == 0)
2557 proceed_distant_row =
false;
2561 SetComplexZero(zero);
2564 Y.SetData(Yres.GetM(), Yres.GetData());
2566 Y.Reallocate(Yres.GetM());
2571 if (proceed_distant_row)
2572 this->ScatterRowValues(X, Xrow);
2578 template<
class T2,
class T3,
class T4,
class Storage4,
class Allocator4>
2586 if (proceed_distant_row)
2587 this->MltAddRow(trans, Xrow, Y);
2591 if (proceed_distant_col)
2592 this->MltAddCol(trans, X, Ycol);
2595 if (proceed_distant_col)
2596 this->AssembleColValues(Ycol, Y);
2600 this->AssembleVec(Y);
2603 SetComplexZero(zero);
2613 Add(alpha, Y, Yres);
2624 const MPI_Comm& comm = this->GetCommunicator();
2625 if (!this->IsReadyForMltAdd())
2634 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2637 this->ScatterColValues(Y, Xcol);
2638 this->ScatterColValues(Yproc, Xcol_proc);
2649 const MPI_Comm& comm = this->GetCommunicator();
2651 int N = this->global_col_to_recv.GetM();
2655 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2656 Yrow.Fill(0); Yrow_proc.Fill(nb_proc);
2657 for (
int i = 0; i < this->dist_col.GetM(); i++)
2658 for (
int j = 0; j < this->dist_col(i).GetM(); j++)
2660 int k = this->dist_col(i).Index(j);
2661 if (Xcol_proc(k) < Yproc(i))
2663 Yproc(i) = Xcol_proc(k);
2666 else if (Xcol_proc(k) == Yproc(i))
2672 if (Yproc(i) < Yrow_proc(k))
2674 Yrow_proc(k) = Yproc(i);
2677 else if (Yproc(i) == Yrow_proc(k))
2684 this->AssembleValuesMin(Yrow, Yrow_proc,
2685 global_col_to_recv, ptr_global_col_to_recv,
2686 proc_col_to_recv, local_col_to_send,
2687 proc_col_to_send, Y, Yproc);
2692 ScatterRowValues(Y, Xcol);
2693 ScatterRowValues(Yproc, Xcol_proc);
2696 N = global_row_to_recv.GetM();
2697 Yrow.Reallocate(N), Yrow_proc.Reallocate(N);
2698 Yrow.Fill(0); Yrow_proc.Fill(nb_proc);
2699 for (
int i = 0; i < dist_row.GetM(); i++)
2700 for (
int j = 0; j < dist_row(i).GetM(); j++)
2702 int jrow = dist_row(i).Index(j);
2703 if (Xcol_proc(jrow) < Yproc(i))
2705 Yproc(i) = Xcol_proc(jrow);
2708 else if (Xcol_proc(jrow) == Yproc(i))
2710 if (Xcol(jrow) < Y(i))
2714 if (Yproc(i) < Yrow_proc(jrow))
2716 Yrow_proc(jrow) = Yproc(i);
2719 else if (Yproc(i) == Yrow_proc(jrow))
2721 if (Y(i) < Yrow(jrow))
2729 AssembleValuesMin(Yrow, Yrow_proc,
2730 global_row_to_recv, ptr_global_row_to_recv,
2731 proc_row_to_recv, local_row_to_send,
2732 proc_row_to_send, Y, Yproc);
2735 AssembleVecMin(Y, Yproc);
2746 template<
class T>
template<
class T0,
class T1>
2752 .SwitchToGlobalNumbers();
2754 this->SwitchToGlobalNumbers();
2757 for (
int i = 0; i < A.
dist_row.GetM(); i++)
2758 for (
int j = 0; j < A.
dist_row(i).GetM(); j++)
2759 this->AddRowDistantInteraction(A.
dist_row(i).Index(j), i,
2763 for (
int i = 0; i < A.
dist_col.GetM(); i++)
2764 for (
int j = 0; j < A.
dist_col(i).GetM(); j++)
2765 this->AddDistantInteraction(i, A.
dist_col(i).Index(j),
2776 const MPI_Comm& comm = this->GetCommunicator();
2777 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2781 for (
int i = 0; i < this->dist_row.GetM(); i++)
2782 for (
int j = 0; j < this->dist_row(i).GetM(); j++)
2783 res = max(res, abs(this->dist_row(i).Value(j)));
2785 for (
int i = 0; i < this->dist_col.GetM(); i++)
2786 for (
int j = 0; j < this->dist_col(i).GetM(); j++)
2787 res = max(res, abs(this->dist_col(i).Value(j)));
2791 typename ClassComplexType<T>::Treal amax(0);
2792 MpiAllreduce(comm, &res, xtmp, &amax, 1, MPI_MAX);
2799 template<
class T>
template<
class T0>
2802 const MPI_Comm& comm = this->GetCommunicator();
2803 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2807 if (!this->IsReadyForMltAdd())
2815 this->GetRowSumDistantCol(vec_sum);
2816 this->GetRowSumDistantRow(vec_sum);
2818 this->AssembleVec(vec_sum);
2823 template<
class T>
template<
class T0>
2826 const MPI_Comm& comm = this->GetCommunicator();
2827 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2831 if (!this->IsReadyForMltAdd())
2839 this->GetColSumDistantCol(vec_sum);
2840 this->GetColSumDistantRow(vec_sum);
2842 this->AssembleVec(vec_sum);
2847 template<
class T>
template<
class T0>
2851 const MPI_Comm& comm = this->GetCommunicator();
2852 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2856 if (!this->IsReadyForMltAdd())
2864 this->GetRowSumDistantCol(sum_row);
2865 this->GetRowSumDistantRow(sum_row);
2867 this->GetColSumDistantCol(sum_col);
2868 this->GetColSumDistantRow(sum_col);
2870 this->AssembleVec(sum_row);
2871 this->AssembleVec(sum_col);
2884 IVect& global_row_to_recv_,
IVect& global_col_to_recv_,
2885 IVect& ptr_global_row_to_recv_,
IVect& ptr_global_col_to_recv_,
2887 IVect& proc_row_to_recv_,
IVect& proc_col_to_recv_,
2888 IVect& proc_row_to_send_,
IVect& proc_col_to_send_)
2890 const MPI_Comm& comm = this->GetCommunicator();
2891 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2895 long stmp = smax_row;
2896 smax_row = size_max_distant_row;
2897 size_max_distant_row = stmp;
2900 smax_col = size_max_distant_col;
2901 size_max_distant_col = stmp;
2903 bool btmp = local_number;
2904 local_number = local_number_distant_values;
2905 local_number_distant_values = btmp;
2911 SwapPointer(global_row_to_recv, global_row_to_recv_);
2912 SwapPointer(global_col_to_recv, global_col_to_recv_);
2913 SwapPointer(ptr_global_row_to_recv, ptr_global_row_to_recv_);
2914 SwapPointer(ptr_global_col_to_recv, ptr_global_col_to_recv_);
2915 SwapPointer(local_row_to_send, local_row_to_send_);
2916 SwapPointer(local_col_to_send, local_col_to_send_);
2928 const MPI_Comm& comm = this->GetCommunicator();
2929 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2933 for (
int i = 0; i < this->dist_row.GetM(); i++)
2934 for (
int j = 0; j < this->dist_row(i).GetM(); j++)
2935 this->dist_row(i).Value(j) = conjugate(this->dist_row(i).Value(j));
2937 for (
int i = 0; i < this->dist_col.GetM(); i++)
2938 for (
int j = 0; j < this->dist_col(i).GetM(); j++)
2939 this->dist_col(i).Value(j) = conjugate(this->dist_col(i).Value(j));
2948 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2954 this->proc_col = A.proc_row;
2956 this->ptr_global_col_to_recv = A.ptr_global_row_to_recv;
2958 this->proc_col_to_recv = A.proc_row_to_recv;
2959 this->proc_col_to_send = A.proc_row_to_send;
2963 this->global_row_to_recv = A.global_col_to_recv;
2964 this->ptr_global_row_to_recv = A.ptr_global_col_to_recv;
2965 this->local_row_to_send = A.local_col_to_send;
2967 this->proc_row_to_send = A.proc_col_to_send;
2970 this->size_max_distant_row = A.size_max_distant_col;
2976 template<
class T>
template<
class T0>
2979 MPI_Comm& comm = this->GetCommunicator();
2980 int nb_proc; MPI_Comm_size(comm, &nb_proc);
2984 if (!this->IsReadyForMltAdd())
2993 for (
int i = 0; i < this->dist_col.GetM(); i++)
2994 this->dist_col(i) *= Drow(i);
2998 this->ScatterRowValues(Drow, Drow_glob);
3000 for (
int i = 0; i < this->dist_row.GetM(); i++)
3001 for (
int j = 0; j < this->dist_row(i).GetM(); j++)
3002 this->dist_row(i).Value(j) *= Drow_glob(this->dist_row(i).Index(j));
3007 template<
class T>
template<
class T0>
3010 MPI_Comm& comm = this->GetCommunicator();
3011 int nb_proc; MPI_Comm_size(comm, &nb_proc);
3015 if (!this->IsReadyForMltAdd())
3024 for (
int i = 0; i < this->dist_row.GetM(); i++)
3025 this->dist_row(i) *= Dcol(i);
3029 this->ScatterColValues(Dcol, Dcol_glob);
3031 for (
int i = 0; i < this->dist_col.GetM(); i++)
3032 for (
int j = 0; j < this->dist_col(i).GetM(); j++)
3033 this->dist_col(i).Value(j) *= Dcol_glob(this->dist_col(i).Index(j));
3038 template<
class T>
template<
class T0,
class T1>
3042 MPI_Comm& comm = this->GetCommunicator();
3043 int nb_proc; MPI_Comm_size(comm, &nb_proc);
3047 if (!this->IsReadyForMltAdd())
3056 for (
int i = 0; i < this->dist_col.GetM(); i++)
3057 this->dist_col(i) *= Drow(i);
3061 this->ScatterRowValues(Drow, Drow_glob);
3063 for (
int i = 0; i < this->dist_row.GetM(); i++)
3064 for (
int j = 0; j < this->dist_row(i).GetM(); j++)
3065 this->dist_row(i).Value(j) *= Drow_glob(this->dist_row(i).Index(j));
3068 for (
int i = 0; i < this->dist_row.GetM(); i++)
3069 this->dist_row(i) *= Dcol(i);
3073 this->ScatterColValues(Dcol, Dcol_glob);
3075 for (
int i = 0; i < this->dist_col.GetM(); i++)
3076 for (
int j = 0; j < this->dist_col(i).GetM(); j++)
3077 this->dist_col(i).Value(j) *= Dcol_glob(this->dist_col(i).Index(j));
3085 MPI_Comm& comm = this->GetCommunicator();
3086 int nb_proc; MPI_Comm_size(comm, &nb_proc);
3090 if (!this->IsReadyForMltAdd())
3091 this->PrepareMltAdd();
3094 IsColDropped.Fill(
false);
3095 for (
int i = 0; i < num.GetM(); i++)
3096 IsColDropped(num(i)) =
true;
3099 this->ScatterColValues(IsColDropped, IsColDroppedDistant);
3101 EraseDistantEntries(comm, IsColDropped, IsColDroppedDistant,
3102 this->dist_col, this->proc_col, this->dist_row, this->proc_row);
3106 this->ScatterRowValues(IsColDropped, IsColDroppedDistant);
3108 EraseDistantEntries(comm, IsColDropped, IsColDroppedDistant,
3109 this->dist_row, this->proc_row, this->dist_col, this->proc_col);
3118 MPI_Comm& comm = this->GetCommunicator();
3119 int nb_proc; MPI_Comm_size(comm, &nb_proc);
3123 if (!this->IsReadyForMltAdd())
3124 this->PrepareMltAdd();
3127 IsRowDropped.Fill(
false);
3128 for (
int i = 0; i < num.GetM(); i++)
3129 IsRowDropped(num(i)) =
true;
3132 this->ScatterRowValues(IsRowDropped, IsRowDroppedDistant);
3134 EraseDistantEntries(comm, IsRowDropped, IsRowDroppedDistant,
3135 this->dist_row, this->proc_row, this->dist_col, this->proc_col);
3139 this->ScatterColValues(IsRowDropped, IsRowDroppedDistant);
3141 EraseDistantEntries(comm, IsRowDropped, IsRowDroppedDistant,
3142 this->dist_col, this->proc_col, this->dist_row, this->proc_row);
3148 template<
class T>
template<
class T1>
3151 const IVect& row,
const IVect& col,
bool sym)
3153 MPI_Comm& comm = this->GetCommunicator();
3154 int nb_proc; MPI_Comm_size(comm, &nb_proc);
3165 RowKept.Fill(
false); ColKept.Fill(
false);
3166 for (
int i = 0; i < row.GetM(); i++)
3167 RowKept(row(i)) =
true;
3169 for (
int i = 0; i < col.GetM(); i++)
3170 ColKept(col(i)) =
true;
3177 cout <<
"A is non-symmetric while B is symmetric" << endl;
3181 for (
int i = 0; i < m; i++)
3182 if (RowKept(i) ^ ColKept(i))
3184 cout <<
"row and col must be identic to obtain "
3185 <<
"a symmetric matrix" << endl;
3195 this->SwitchToGlobalNumbers();
3198 this->dist_col.Reallocate(m);
3199 this->proc_col.Reallocate(m);
3200 for (
int i = 0; i < A.
dist_col.GetM(); i++)
3205 for (
int j = 0; j < A.
dist_col(i).GetM(); j++)
3206 if (ColKeptDistant(A.
dist_col(i).Index(j)))
3209 this->dist_col(i).Reallocate(size_row);
3210 this->proc_col(i).Reallocate(size_row);
3212 for (
int j = 0; j < A.
dist_col(i).GetM(); j++)
3213 if (ColKeptDistant(A.
dist_col(i).Index(j)))
3215 this->dist_col(i).Value(size_row) = A.
dist_col(i).Value(j);
3216 this->dist_col(i).Index(size_row)
3217 = A.global_col_to_recv(A.
dist_col(i).Index(j));
3219 this->proc_col(i)(size_row) = A.
proc_col(i)(j);
3225 this->dist_col(i).Clear();
3226 this->proc_col(i).Clear();
3231 this->dist_row.Reallocate(n);
3232 this->proc_row.Reallocate(n);
3233 for (
int i = 0; i < A.
dist_row.GetM(); i++)
3238 for (
int j = 0; j < A.
dist_row(i).GetM(); j++)
3239 if (RowKeptDistant(A.
dist_row(i).Index(j)))
3242 this->dist_row(i).Reallocate(size_col);
3243 this->proc_row(i).Reallocate(size_col);
3245 for (
int j = 0; j < A.
dist_row(i).GetM(); j++)
3246 if (RowKeptDistant(A.
dist_row(i).Index(j)))
3248 this->dist_row(i).Value(size_col) = A.
dist_row(i).Value(j);
3249 this->dist_row(i).Index(size_col)
3252 this->proc_row(i)(size_col) = A.proc_row(i)(j);
3258 this->dist_row(i).Clear();
3259 this->proc_row(i).Clear();
3270 if (this->nglob_ != A.
nglob_)
3276 if (nb_unknowns_scal_ != A.nb_unknowns_scal_)
3279 IVect& glob = *GlobalRowNumbers;
3281 if (glob.GetM() != globA.GetM())
3284 for (
int i = 0; i < glob.GetM(); i++)
3285 if (glob(i) != globA(i))
3288 IVect& over = *OverlapRowNumbers;
3290 if (over.GetM() != overA.GetM())
3293 for (
int i = 0; i < over.GetM(); i++)
3294 if (over(i) != overA(i))
3297 IVect& proc = *OverlapProcNumbers;
3299 if (proc.GetM() != procA.GetM())
3302 for (
int i = 0; i < proc.GetM(); i++)
3303 if (proc(i) != procA(i))
3320 IVect& OverlappedCol,
bool sym_pattern,
bool reorder)
3322 int m = this->GetLocalM();
3323 int n = this->GetGlobalM();
3325 MPI_Comm& comm = this->GetCommunicator();
3326 int nb_proc; MPI_Comm_size(comm, &nb_proc);
3327 int rank; MPI_Comm_rank(comm, &rank);
3329 IVect RowNumber(this->GetGlobalRowNumber());
3330 const IVect& OverlapRowNumber = this->GetOverlapRowNumber();
3331 const IVect& OverlapProcNumber = this->GetOverlapProcNumber();
3335 OverlappedCol.Reallocate(m); OverlappedCol.Fill(-1);
3336 for (
int i = 0; i < OverlapRowNumber.GetM(); i++)
3337 OverlappedCol(OverlapRowNumber(i)) = i;
3345 Vector<int> nsend_int(nb_proc), nsend_float(nb_proc);
3352 for (
int i = 0; i < nb_proc; i++)
3364 for (
int j = 0; j < OverlapRowNumber.GetM(); j++)
3366 int i = OverlapProcNumber(j);
3371 int irow = OverlapRowNumber(j);
3372 nsend_int(i) += B.GetRowSize(irow);
3373 nsend_float(i) += B.GetRowSize(irow);
3375 nsend_int(i) += B.GetRowSize(irow);
3380 for (
int j = 0; j < this->dist_row.GetM(); j++)
3381 for (
int k = 0; k < this->dist_row(j).GetM(); k++)
3383 int i = this->proc_row(j)(k);
3386 int irow = this->dist_row(j).Index(k);
3387 if (this->local_number_distant_values)
3388 irow = this->global_row_to_recv(irow);
3390 if (irow <= RowNumber(j))
3402 for (
int i = 0; i < nb_proc; i++)
3405 if (nb_row_sent(i) == 0)
3408 if (nb_row_sent(i) > 0)
3410 EntierToSend(i).Reallocate(nsend_int(i));
3411 FloatToSend(i).Reallocate(nsend_float(i));
3412 EntierToSend(i)(0) = nsend_float(i);
3413 EntierToSend(i)(1) = nb_row_sent(i);
3414 nsend_int(i) = 2; nsend_float(i) = 0;
3422 for (
int j = 0; j < OverlapRowNumber.GetM(); j++)
3424 int i = OverlapProcNumber(j);
3427 int irow = OverlapRowNumber(j);
3428 EntierToSend(i)(nsend_int(i)++) = RowNumber(irow);
3429 EntierToSend(i)(nsend_int(i)++) = B.GetRowSize(irow);
3430 for (
int k = 0; k < B.GetRowSize(irow); k++)
3432 EntierToSend(i)(nsend_int(i)++) = B.Index(irow, k);
3434 EntierToSend(i)(nsend_int(i)++) = procB(irow)(k);
3436 FloatToSend(i)(nsend_float(i)++) = B.Value(irow, k);
3444 procB(irow).Clear();
3449 for (
int j = 0; j < this->dist_row.GetM(); j++)
3450 for (
int k = 0; k < this->dist_row(j).GetM(); k++)
3452 int i = this->proc_row(j)(k);
3455 int irow = this->dist_row(j).Index(k);
3456 if (this->local_number_distant_values)
3457 irow = this->global_row_to_recv(irow);
3459 if (irow <= RowNumber(j))
3461 EntierToSend(i)(nsend_int(i)++) = irow;
3462 EntierToSend(i)(nsend_int(i)++) = 1;
3463 EntierToSend(i)(nsend_int(i)++) = RowNumber(j);
3465 EntierToSend(i)(nsend_int(i)++) = rank;
3467 FloatToSend(i)(nsend_float(i)++)
3468 = this->dist_row(j).Value(k);
3479 IVect nrecv_int(nb_proc);
3482 SendAndReceiveDistributed(comm, nsend_int, EntierToSend, FloatToSend,
3483 nrecv_int, EntierToRecv, FloatToRecv);
3486 int nloc = m - OverlapRowNumber.GetM();
3487 local_row_numbers.Reallocate(nloc);
3489 for (
int i = 0; i < m; i++)
3490 if (OverlappedCol(i) == -1)
3491 local_row_numbers(nrow++) = i;
3495 IVect inv_local_row_numbers(m);
3496 inv_local_row_numbers.Fill(-1);
3498 for (
int i = 0; i < m; i++)
3499 if (OverlappedCol(i) == -1)
3500 inv_local_row_numbers(i) = nrow++;
3503 IVect Glob_to_local(n);
3504 Glob_to_local.Fill(-1);
3505 for (
int i = 0; i < m; i++)
3506 Glob_to_local(RowNumber(i)) = i;
3509 AddReceivedInteractions(comm, B, EntierToRecv, FloatToRecv, nrecv_int,
3510 EntierToSend, FloatToSend, nsend_int, Glob_to_local,
3511 OverlappedCol, OverlapProcNumber, procB, reorder);
3514 SendAndReceiveDistributed(comm, nsend_int, EntierToSend, FloatToSend,
3515 nrecv_int, EntierToRecv, FloatToRecv);
3518 AddReceivedInteractions(comm, B, EntierToRecv, FloatToRecv, nrecv_int,
3519 EntierToSend, FloatToSend, nsend_int, Glob_to_local,
3520 OverlappedCol, OverlapProcNumber, procB, reorder);
3533 IVect OverlapLocalNumber(OverlapRowNumber.GetM());
3534 IVect offset_global(nb_proc+1);
3536 IVect nb_col_sent(nb_proc);
3537 IVect nb_row_overlap(nb_proc);
3544 nb_row_overlap.Zero();
3545 for (
int j = 0; j < OverlapRowNumber.GetM(); j++)
3547 int i = OverlapProcNumber(j);
3549 nb_row_overlap(i)++;
3553 for (
int i = 0; i < nb_proc; i++)
3554 if (nb_row_overlap(i) > 0)
3555 row_send_overlap(i).Reallocate(nb_row_overlap(i));
3557 nb_row_overlap.Zero();
3558 for (
int j = 0; j < OverlapRowNumber.GetM(); j++)
3560 int i = OverlapProcNumber(j);
3562 row_send_overlap(i)(nb_row_overlap(i)++) = RowNumber(OverlapRowNumber(j));
3566 for (
int j = 0; j < B.GetM(); j++)
3567 for (
int k = 0; k < B.GetRowSize(j); k++)
3569 int i = procB(j)(k);
3574 for (
int i = 0; i < nb_proc; i++)
3576 col_number_sorted(i).Reallocate(nb_col_sent(i));
3580 for (
int j = 0; j < B.GetM(); j++)
3581 for (
int k = 0; k < B.GetRowSize(j); k++)
3583 int i = procB(j)(k);
3585 col_number_sorted(i)(nb_col_sent(i)++) = B.Index(j, k);
3589 for (
int i = 0; i < nb_proc; i++)
3592 IVect permut(nb_col_sent(i)), col_number_sort(col_number_sorted(i));
3594 Sort(nb_col_sent(i), col_number_sort, permut);
3597 int prec = -1; nb_col_sent(i) = 0;
3598 for (
int j = 0; j < col_number_sort.GetM(); j++)
3600 if (col_number_sort(j) != prec)
3603 prec = col_number_sort(j);
3607 col_number_to_send(i).Reallocate(nb_col_sent(i));
3610 for (
int j = 0; j < col_number_sort.GetM(); j++)
3612 if (col_number_sort(j) != prec)
3614 col_number_to_send(i)(nb_col_sent(i)) = col_number_sort(j);
3618 col_number_sorted(i)(permut(j)) = nb_col_sent(i)-1;
3619 prec = col_number_sort(j);
3625 for (
int i = 0; i < nb_proc; i++)
3626 if ((i != rank) && (nb_col_sent(i)+nb_row_overlap(i) > 0))
3629 nsend_int(i) = 2+nb_col_sent(i) + nb_row_overlap(i);
3630 EntierToSend(i).Reallocate(nsend_int(i));
3631 EntierToSend(i)(0) = 0;
3632 EntierToSend(i)(1) = nb_col_sent(i) + nb_row_overlap(i);
3637 for (
int i = 0; i < nb_proc; i++)
3639 for (
int j = 0; j < nb_row_overlap(i); j++)
3640 EntierToSend(i)(nsend_int(i)++) = row_send_overlap(i)(j);
3642 for (
int j = 0; j < nb_col_sent(i); j++)
3643 EntierToSend(i)(nsend_int(i)++) = col_number_to_send(i)(j);
3647 SendAndReceiveDistributed(comm, nsend_int, EntierToSend, FloatToSend,
3648 nrecv_int, EntierToRecv, FloatToRecv);
3650 IVect nsend_intB(nb_proc), nrecv_intB(nb_proc);
3651 nsend_intB.Zero(); nrecv_intB.Zero();
3652 Vector<IVect> EntierToSendB(nb_proc), EntierToRecvB(nb_proc);
3654 for (
int i = 0; i < nb_proc; i++)
3655 if ((i != rank) && (nrecv_int(i) > 0))
3657 int nb_col = EntierToRecv(i)(1);
3658 for (
int j = 0; j < nb_col; j++)
3660 int iglob = EntierToRecv(i)(2+j);
3661 int irow = Glob_to_local(iglob);
3662 if (inv_local_row_numbers(irow) == -1)
3664 int p = OverlappedCol(irow);
3665 int nproc = OverlapProcNumber(p);
3666 if (nsend_intB(nproc) == 0)
3668 nsend_intB(nproc) = 3;
3669 EntierToSendB(nproc).Reallocate(3);
3670 EntierToSendB(nproc)(0) = 0;
3671 EntierToSendB(nproc)(1) = 1;
3672 EntierToSendB(nproc)(2) = iglob;
3676 nsend_intB(nproc)++;
3677 EntierToSendB(nproc)(1)++;
3678 EntierToSendB(nproc).PushBack(iglob);
3685 SendAndReceiveDistributed(comm, nsend_intB, EntierToSendB, FloatToSend,
3686 nrecv_intB, EntierToRecvB, FloatToRecv);
3689 for (
int i = 0; i < nb_proc; i++)
3690 if ((i != rank) && (nrecv_intB(i) > 0))
3692 int nb_col = EntierToRecvB(i)(1);
3695 nsend_intB(i) = nb_col+2;
3696 EntierToSendB(i).Reallocate(nb_col+2);
3697 EntierToSendB(i)(0) = 0;
3698 EntierToSendB(i)(1) = nb_col;
3700 for (
int j = 0; j < nb_col; j++)
3702 int iglob = EntierToRecvB(i)(2+j);
3703 int irow = Glob_to_local(iglob);
3704 if (inv_local_row_numbers(irow) == -1)
3706 cout <<
"impossible case" << endl;
3710 EntierToSendB(i)(2+j) = inv_local_row_numbers(irow);
3716 SendAndReceiveDistributed(comm, nsend_intB, EntierToSendB, FloatToSend,
3717 nrecv_intB, EntierToRecvB, FloatToRecv);
3721 for (
int i = 0; i < nb_proc; i++)
3722 if ((i != rank) && (nrecv_int(i) > 0))
3724 int nb_col = EntierToRecv(i)(1);
3727 nsend_int(i) = 2*nb_col+2;
3728 EntierToSend(i).Reallocate(2*nb_col+2);
3729 EntierToSend(i)(0) = 0;
3730 EntierToSend(i)(1) = 2*nb_col;
3732 for (
int j = 0; j < nb_col; j++)
3734 int iglob = EntierToRecv(i)(2+j);
3735 int irow = Glob_to_local(iglob);
3736 if (inv_local_row_numbers(irow) == -1)
3738 int p = OverlappedCol(irow);
3739 int nproc = OverlapProcNumber(p);
3740 int num = EntierToRecvB(nproc)(2+nsend_intB(nproc));
3741 nsend_intB(nproc)++;
3743 EntierToSend(i)(2+2*j) = num;
3744 EntierToSend(i)(3+2*j) = nproc;
3748 EntierToSend(i)(2+2*j) = inv_local_row_numbers(irow);
3749 EntierToSend(i)(3+2*j) = rank;
3756 SendAndReceiveDistributed(comm, nsend_int, EntierToSend, FloatToSend,
3757 nrecv_int, EntierToRecv, FloatToRecv);
3761 for (
int i = 0; i < nb_proc; i++)
3763 if (EntierToRecv(i).GetM() > 0)
3766 proc_number_to_send(i).Reallocate(nb_col_sent(i));
3767 for (
int j = 0; j < nb_row_overlap(i); j++)
3769 row_send_overlap(i)(j) = EntierToRecv(i)(nrecv_int(i));
3770 if (EntierToRecv(i)(nrecv_int(i)+1) != i)
3772 cout <<
"Impossible case" << endl;
3779 for (
int j = 0; j < nb_col_sent(i); j++)
3781 col_number_to_send(i)(j) = EntierToRecv(i)(nrecv_int(i));
3782 proc_number_to_send(i)(j) = EntierToRecv(i)(nrecv_int(i)+1);
3789 nb_row_overlap.Zero();
3791 OverlapLocalNumber.Fill(-1);
3792 for (
int j = 0; j < OverlapRowNumber.GetM(); j++)
3794 int i = OverlapProcNumber(j);
3797 OverlapLocalNumber(j) = row_send_overlap(i)(nb_row_overlap(i));
3798 nb_row_overlap(i)++;
3804 offset_global.Zero();
3806 MPI_Allgather(&nloc, 1, MPI_INTEGER, &offset_global(1), 1, MPI_INTEGER, comm);
3808 for (
int i = 1; i < nb_proc; i++)
3809 offset_global(i+1) += offset_global(i);
3813 for (
int i = 0; i < m; i++)
3815 if (OverlappedCol(i) == -1)
3817 RowNumber(i) = offset_global(rank) + nrow;
3826 for (
int j = 0; j < m; j++)
3827 if (OverlappedCol(j) == -1)
3829 for (
int k = 0; k < B.GetRowSize(j); k++)
3831 int jglob = B.Index(j, k);
3832 int i = procB(j)(k);
3837 int irow = Glob_to_local(jglob);
3838 if (OverlappedCol(irow) == -1)
3839 iloc = inv_local_row_numbers(irow);
3842 int p = OverlappedCol(irow);
3843 i = OverlapProcNumber(p);
3845 iloc = OverlapLocalNumber(p);
3850 int ilocC = col_number_sorted(i)(nb_col_sent(i));
3851 ireal = proc_number_to_send(i)(ilocC);
3852 iloc = col_number_to_send(i)(ilocC);
3858 B.Index(j, k) = offset_global(ireal) + iloc;
3862 cout <<
"Impossible case" << endl;
3869 Glob_to_local.Clear();
3872 row_numbers.Reallocate(nloc);
3873 for (
int i = 0; i < m; i++)
3874 if (OverlappedCol(i) == -1)
3876 row_numbers(nrow) = RowNumber(i);
3883 template<
class T>
template<
class T
int0,
class T
int1>
3890 for (
int i = 0; i < m; i++)
3891 if (OverlappedCol(i) == -1)
3899 PtrA.Reallocate(nloc+1);
3900 int nrow = 0;
long nnz = 0;
3902 for (
int i = 0; i < m; i++)
3903 if (OverlappedCol(i) == -1)
3905 PtrA(nrow+1) = PtrA(nrow) + B.GetRowSize(i);
3907 nnz += B.GetRowSize(i);
3910 IndA.Reallocate(nnz);
3911 ValA.Reallocate(nnz); nrow = 0; nnz = 0;
3912 for (
int i = 0; i < m; i++)
3913 if (OverlappedCol(i) == -1)
3915 for (
int j = 0; j < B.GetRowSize(i); j++)
3917 IndA(nnz) = B.Index(i, j);
3918 ValA(nnz) = B.Value(i, j);
3932 IVect& OverlappedCol,
bool sym_pattern,
bool reorder)
3934 int n = this->GetLocalN();
3935 int m = this->GetGlobalM();
3937 const MPI_Comm& comm = this->GetCommunicator();
3938 int nb_proc; MPI_Comm_size(comm, &nb_proc);
3939 int rank; MPI_Comm_rank(comm, &rank);
3941 IVect RowNumber = this->GetGlobalRowNumber();
3942 const IVect& OverlapRowNumber = this->GetOverlapRowNumber();
3943 const IVect& OverlapProcNumber = this->GetOverlapProcNumber();
3947 OverlappedCol.Reallocate(n); OverlappedCol.Fill(-1);
3948 for (
int i = 0; i < OverlapRowNumber.GetM(); i++)
3949 OverlappedCol(OverlapRowNumber(i)) = i;
3957 IVect nsend_int(nb_proc), nsend_float(nb_proc), nb_col_sent(nb_proc);
3965 for (
int i = 0; i < nb_proc; i++)
3977 for (
int j = 0; j < OverlapRowNumber.GetM(); j++)
3979 int i = OverlapProcNumber(j);
3984 int irow = OverlapRowNumber(j);
3985 nsend_int(i) += B.GetColumnSize(irow);
3986 nsend_float(i) += B.GetColumnSize(irow);
3988 nsend_int(i) += B.GetColumnSize(irow);
3994 for (
int j = 0; j < this->dist_row.GetM(); j++)
3995 for (
int k = 0; k < this->dist_row(j).GetM(); k++)
3997 int i = this->proc_row(j)(k);
4009 for (
int j = 0; j < this->dist_col.GetM(); j++)
4010 for (
int k = 0; k < this->dist_col(j).GetM(); k++)
4012 int i = this->proc_col(j)(k);
4025 for (
int i = 0; i < nb_proc; i++)
4028 if (nb_col_sent(i) == 0)
4031 if (nb_col_sent(i) > 0)
4033 EntierToSend(i).Reallocate(nsend_int(i));
4034 FloatToSend(i).Reallocate(nsend_float(i));
4035 EntierToSend(i)(0) = nsend_float(i);
4036 EntierToSend(i)(1) = nb_col_sent(i);
4037 nsend_int(i) = 2; nsend_float(i) = 0;
4045 for (
int j = 0; j < OverlapRowNumber.GetM(); j++)
4047 int i = OverlapProcNumber(j);
4050 int irow = OverlapRowNumber(j);
4051 EntierToSend(i)(nsend_int(i)++) = RowNumber(irow);
4052 EntierToSend(i)(nsend_int(i)++) = B.GetColumnSize(irow);
4053 for (
int k = 0; k < B.GetColumnSize(irow); k++)
4055 EntierToSend(i)(nsend_int(i)++) = B.Index(irow, k);
4057 EntierToSend(i)(nsend_int(i)++) = procB(irow)(k);
4059 FloatToSend(i)(nsend_float(i)++) = B.Value(irow, k);
4065 B.ClearColumn(irow);
4067 procB(irow).Clear();
4073 for (
int j = 0; j < this->dist_row.GetM(); j++)
4074 for (
int k = 0; k < this->dist_row(j).GetM(); k++)
4076 int i = this->proc_row(j)(k);
4079 int irow = this->dist_row(j).Index(k);
4080 if (this->local_number_distant_values)
4081 irow = this->global_row_to_recv(irow);
4083 EntierToSend(i)(nsend_int(i)++) = irow;
4084 EntierToSend(i)(nsend_int(i)++) = 1;
4085 EntierToSend(i)(nsend_int(i)++) = RowNumber(j);
4087 EntierToSend(i)(nsend_int(i)++) = rank;
4089 FloatToSend(i)(nsend_float(i)++) = 0;
4094 for (
int j = 0; j < this->dist_col.GetM(); j++)
4095 for (
int k = 0; k < this->dist_col(j).GetM(); k++)
4097 int i = this->proc_col(j)(k);
4100 int irow = this->dist_col(j).Index(k);
4101 if (this->local_number_distant_values)
4102 irow = this->global_col_to_recv(irow);
4104 EntierToSend(i)(nsend_int(i)++) = irow;
4105 EntierToSend(i)(nsend_int(i)++) = 1;
4106 EntierToSend(i)(nsend_int(i)++) = RowNumber(j);
4108 EntierToSend(i)(nsend_int(i)++) = rank;
4110 FloatToSend(i)(nsend_float(i)++)
4111 = this->dist_col(j).Value(k);
4119 IVect nrecv_int(nb_proc);
4124 SendAndReceiveDistributed(comm, nsend_int, EntierToSend, FloatToSend,
4125 nrecv_int, EntierToRecv, FloatToRecv);
4128 int nloc = n - OverlapRowNumber.GetM();
4129 local_col_numbers.Reallocate(nloc);
4131 for (
int i = 0; i < n; i++)
4132 if (OverlappedCol(i) == -1)
4133 local_col_numbers(ncol++) = i;
4137 IVect inv_local_col_numbers(n);
4138 inv_local_col_numbers.Fill(-1);
4140 for (
int i = 0; i < n; i++)
4141 if (OverlappedCol(i) == -1)
4142 inv_local_col_numbers(i) = ncol++;
4145 IVect Glob_to_local(m);
4146 Glob_to_local.Fill(-1);
4147 for (
int i = 0; i < n; i++)
4148 Glob_to_local(RowNumber(i)) = i;
4151 AddReceivedInteractions(comm, B, EntierToRecv, FloatToRecv, nrecv_int,
4152 EntierToSend, FloatToSend, nsend_int, Glob_to_local,
4153 OverlappedCol, OverlapProcNumber, procB, reorder);
4156 SendAndReceiveDistributed(comm, nsend_int, EntierToSend, FloatToSend,
4157 nrecv_int, EntierToRecv, FloatToRecv);
4160 AddReceivedInteractions(comm, B, EntierToRecv, FloatToRecv, nrecv_int,
4161 EntierToSend, FloatToSend, nsend_int, Glob_to_local,
4162 OverlappedCol, OverlapProcNumber, procB, reorder);
4175 IVect OverlapLocalNumber(OverlapRowNumber.GetM());
4176 IVect offset_global(nb_proc+1);
4178 IVect nb_col_overlap(nb_proc);
4185 nb_col_overlap.Zero();
4186 for (
int j = 0; j < OverlapRowNumber.GetM(); j++)
4188 int i = OverlapProcNumber(j);
4190 nb_col_overlap(i)++;
4194 for (
int i = 0; i < nb_proc; i++)
4195 if (nb_col_overlap(i) > 0)
4196 col_send_overlap(i).Reallocate(nb_col_overlap(i));
4198 nb_col_overlap.Zero();
4199 for (
int j = 0; j < OverlapRowNumber.GetM(); j++)
4201 int i = OverlapProcNumber(j);
4203 col_send_overlap(i)(nb_col_overlap(i)++) = RowNumber(OverlapRowNumber(j));
4207 for (
int j = 0; j < B.GetN(); j++)
4208 for (
int k = 0; k < B.GetColumnSize(j); k++)
4210 int i = procB(j)(k);
4215 for (
int i = 0; i < nb_proc; i++)
4217 col_number_sorted(i).Reallocate(nb_col_sent(i));
4221 for (
int j = 0; j < B.GetN(); j++)
4222 for (
int k = 0; k < B.GetColumnSize(j); k++)
4224 int i = procB(j)(k);
4226 col_number_sorted(i)(nb_col_sent(i)++) = B.Index(j, k);
4230 for (
int i = 0; i < nb_proc; i++)
4233 IVect permut(nb_col_sent(i)), col_number_sort(col_number_sorted(i));
4235 Sort(nb_col_sent(i), col_number_sort, permut);
4238 int prec = -1; nb_col_sent(i) = 0;
4239 for (
int j = 0; j < col_number_sort.GetM(); j++)
4241 if (col_number_sort(j) != prec)
4244 prec = col_number_sort(j);
4248 col_number_to_send(i).Reallocate(nb_col_sent(i));
4251 for (
int j = 0; j < col_number_sort.GetM(); j++)
4253 if (col_number_sort(j) != prec)
4255 col_number_to_send(i)(nb_col_sent(i)) = col_number_sort(j);
4259 col_number_sorted(i)(permut(j)) = nb_col_sent(i)-1;
4260 prec = col_number_sort(j);
4266 for (
int i = 0; i < nb_proc; i++)
4267 if ((i != rank) && (nb_col_sent(i)+nb_col_overlap(i) > 0))
4270 nsend_int(i) = 2+nb_col_sent(i) + nb_col_overlap(i);
4271 EntierToSend(i).Reallocate(nsend_int(i));
4272 EntierToSend(i)(0) = 0;
4273 EntierToSend(i)(1) = nb_col_sent(i) + nb_col_overlap(i);
4278 for (
int i = 0; i < nb_proc; i++)
4280 for (
int j = 0; j < nb_col_overlap(i); j++)
4281 EntierToSend(i)(nsend_int(i)++) = col_send_overlap(i)(j);
4283 for (
int j = 0; j < nb_col_sent(i); j++)
4284 EntierToSend(i)(nsend_int(i)++) = col_number_to_send(i)(j);
4288 SendAndReceiveDistributed(comm, nsend_int, EntierToSend, FloatToSend,
4289 nrecv_int, EntierToRecv, FloatToRecv);
4291 IVect nsend_intB(nb_proc), nrecv_intB(nb_proc);
4292 nsend_intB.Zero(); nrecv_intB.Zero();
4293 Vector<IVect> EntierToSendB(nb_proc), EntierToRecvB(nb_proc);
4295 for (
int i = 0; i < nb_proc; i++)
4296 if ((i != rank) && (nrecv_int(i) > 0))
4298 int nb_col = EntierToRecv(i)(1);
4299 for (
int j = 0; j < nb_col; j++)
4301 int iglob = EntierToRecv(i)(2+j);
4302 int irow = Glob_to_local(iglob);
4303 if (inv_local_col_numbers(irow) == -1)
4305 int p = OverlappedCol(irow);
4306 int nproc = OverlapProcNumber(p);
4307 if (nsend_intB(nproc) == 0)
4309 nsend_intB(nproc) = 3;
4310 EntierToSendB(nproc).Reallocate(3);
4311 EntierToSendB(nproc)(0) = 0;
4312 EntierToSendB(nproc)(1) = 1;
4313 EntierToSendB(nproc)(2) = iglob;
4317 nsend_intB(nproc)++;
4318 EntierToSendB(nproc)(1)++;
4319 EntierToSendB(nproc).PushBack(iglob);
4326 SendAndReceiveDistributed(comm, nsend_intB, EntierToSendB, FloatToSend,
4327 nrecv_intB, EntierToRecvB, FloatToRecv);
4330 for (
int i = 0; i < nb_proc; i++)
4331 if ((i != rank) && (nrecv_intB(i) > 0))
4333 int nb_col = EntierToRecvB(i)(1);
4336 nsend_intB(i) = nb_col+2;
4337 EntierToSendB(i).Reallocate(nb_col+2);
4338 EntierToSendB(i)(0) = 0;
4339 EntierToSendB(i)(1) = nb_col;
4341 for (
int j = 0; j < nb_col; j++)
4343 int iglob = EntierToRecvB(i)(2+j);
4344 int irow = Glob_to_local(iglob);
4345 if (inv_local_col_numbers(irow) == -1)
4347 cout <<
"impossible case" << endl;
4351 EntierToSendB(i)(2+j) = inv_local_col_numbers(irow);
4357 SendAndReceiveDistributed(comm, nsend_intB, EntierToSendB, FloatToSend,
4358 nrecv_intB, EntierToRecvB, FloatToRecv);
4362 for (
int i = 0; i < nb_proc; i++)
4363 if ((i != rank) && (nrecv_int(i) > 0))
4365 int nb_col = EntierToRecv(i)(1);
4368 nsend_int(i) = 2*nb_col+2;
4369 EntierToSend(i).Reallocate(2*nb_col+2);
4370 EntierToSend(i)(0) = 0;
4371 EntierToSend(i)(1) = 2*nb_col;
4373 for (
int j = 0; j < nb_col; j++)
4375 int iglob = EntierToRecv(i)(2+j);
4376 int irow = Glob_to_local(iglob);
4377 if (inv_local_col_numbers(irow) == -1)
4379 int p = OverlappedCol(irow);
4380 int nproc = OverlapProcNumber(p);
4381 int num = EntierToRecvB(nproc)(2+nsend_intB(nproc));
4382 nsend_intB(nproc)++;
4384 EntierToSend(i)(2+2*j) = num;
4385 EntierToSend(i)(3+2*j) = nproc;
4389 EntierToSend(i)(2+2*j) = inv_local_col_numbers(irow);
4390 EntierToSend(i)(3+2*j) = rank;
4397 SendAndReceiveDistributed(comm, nsend_int, EntierToSend, FloatToSend,
4398 nrecv_int, EntierToRecv, FloatToRecv);
4402 for (
int i = 0; i < nb_proc; i++)
4404 if (EntierToRecv(i).GetM() > 0)
4407 proc_number_to_send(i).Reallocate(nb_col_sent(i));
4408 for (
int j = 0; j < nb_col_overlap(i); j++)
4410 col_send_overlap(i)(j) = EntierToRecv(i)(nrecv_int(i));
4411 if (EntierToRecv(i)(nrecv_int(i)+1) != i)
4413 cout <<
"Impossible case" << endl;
4420 for (
int j = 0; j < nb_col_sent(i); j++)
4422 col_number_to_send(i)(j) = EntierToRecv(i)(nrecv_int(i));
4423 proc_number_to_send(i)(j) = EntierToRecv(i)(nrecv_int(i)+1);
4430 nb_col_overlap.Zero();
4432 OverlapLocalNumber.Fill(-1);
4433 for (
int j = 0; j < OverlapRowNumber.GetM(); j++)
4435 int i = OverlapProcNumber(j);
4438 OverlapLocalNumber(j) = col_send_overlap(i)(nb_col_overlap(i));
4439 nb_col_overlap(i)++;
4445 offset_global.Zero();
4447 MPI_Allgather(&nloc, 1, MPI_INTEGER, &offset_global(1), 1, MPI_INTEGER, comm);
4449 for (
int i = 1; i < nb_proc; i++)
4450 offset_global(i+1) += offset_global(i);
4454 for (
int i = 0; i < n; i++)
4456 if (OverlappedCol(i) == -1)
4458 RowNumber(i) = offset_global(rank) + ncol;
4467 for (
int j = 0; j < n; j++)
4468 if (OverlappedCol(j) == -1)
4470 for (
int k = 0; k < B.GetColumnSize(j); k++)
4472 int jglob = B.Index(j, k);
4473 int i = procB(j)(k);
4478 int irow = Glob_to_local(jglob);
4479 if (OverlappedCol(irow) == -1)
4480 iloc = inv_local_col_numbers(irow);
4483 int p = OverlappedCol(irow);
4484 i = OverlapProcNumber(p);
4486 iloc = OverlapLocalNumber(p);
4491 int ilocC = col_number_sorted(i)(nb_col_sent(i));
4492 ireal = proc_number_to_send(i)(ilocC);
4493 iloc = col_number_to_send(i)(ilocC);
4499 B.Index(j, k) = offset_global(ireal) + iloc;
4503 cout <<
"Impossible case" << endl;
4508 B.AssembleColumn(j);
4512 Glob_to_local.Clear();
4515 col_numbers.Reallocate(nloc);
4516 for (
int i = 0; i < n; i++)
4517 if (OverlappedCol(i) == -1)
4519 col_numbers(ncol) = RowNumber(i);
4526 template<
class T>
template<
class T
int0,
class T
int1>
4533 for (
int i = 0; i < n; i++)
4534 if (OverlappedCol(i) == -1)
4541 PtrA.Reallocate(nloc+1);
4542 int ncol = 0;
long nnz = 0;
4544 for (
int i = 0; i < n; i++)
4545 if (OverlappedCol(i) == -1)
4547 PtrA(ncol+1) = PtrA(ncol) + B.GetColumnSize(i);
4549 nnz += B.GetColumnSize(i);
4552 IndA.Reallocate(nnz);
4553 ValA.Reallocate(nnz);
4555 for (
int i = 0; i < n; i++)
4556 if (OverlappedCol(i) == -1)
4558 for (
int j = 0; j < B.GetColumnSize(i); j++)
4560 IndA(nnz) = B.Index(i, j);
4561 ValA(nnz) = B.Value(i, j);
4577 template<
class T0,
class Allocator0>
4582 int m = this->GetLocalM();
4583 int n = this->GetGlobalM();
4584 int rank; MPI_Comm_rank(this->comm_, &rank);
4586 bool retrieve_proc =
false;
4587 if (procB.GetM() == m)
4588 retrieve_proc =
true;
4593 const IVect& RowNumber = this->GetGlobalRowNumber();
4594 for (
int i = 0; i < m; i++)
4596 int size_row = B.GetRowSize(i);
4597 size_row += dist_col(i).GetM();
4598 IVect index(size_row), proc_loc(size_row);
4601 int num_row = RowNumber(i);
4605 for (
int j = 0; j < B.GetRowSize(i); j++)
4607 int num_col = RowNumber(B.Index(i, j));
4608 if (num_row <= num_col)
4610 index(nb) = num_col;
4611 value(nb) = B.Value(i, j);
4612 proc_loc(nb) = rank;
4618 for (
int j = 0; j < dist_col(i).GetM(); j++)
4620 int num_col = dist_col(i).Index(j);
4621 if (this->local_number_distant_values)
4622 num_col = global_col_to_recv(num_col);
4624 if (num_row <= num_col)
4626 index(nb) = num_col;
4627 value(nb) = dist_col(i).Value(j);
4628 proc_loc(nb) = proc_col(i)(j);
4636 for (
int j = 0; j < B.GetRowSize(i); j++)
4638 int num_col = RowNumber(B.Index(i, j));
4639 index(nb) = num_col;
4640 value(nb) = B.Value(i, j);
4641 proc_loc(nb) = rank;
4646 for (
int j = 0; j < dist_col(i).GetM(); j++)
4648 int num_col = dist_col(i).Index(j);
4649 if (this->local_number_distant_values)
4650 num_col = global_col_to_recv(num_col);
4652 index(nb) = num_col;
4653 value(nb) = dist_col(i).Value(j);
4654 proc_loc(nb) = proc_col(i)(j);
4659 Sort(nb, index, value, proc_loc);
4662 for (
int j = 0; j < nb; j++)
4664 if (index(j) == prec)
4665 value(size_row-1) += value(j);
4668 index(size_row) = index(j);
4669 value(size_row) = value(j);
4670 proc_loc(size_row) = proc_loc(j);
4677 B.ReallocateRow(i, size_row);
4678 for (
int j = 0; j < size_row; j++)
4680 B.Index(i, j) = index(j);
4681 B.Value(i, j) = value(j);
4686 procB(i).Reallocate(size_row);
4687 for (
int j = 0; j < size_row; j++)
4688 procB(i)(j) = proc_loc(j);
4701 template<
class T0,
class Allocator0>
4707 int m = this->GetGlobalM();
4708 int n = this->GetLocalN();
4709 int rank; MPI_Comm_rank(this->comm_, &rank);
4711 bool retrieve_proc =
false;
4712 if (procB.GetM() == n)
4713 retrieve_proc =
true;
4718 B.Clear(); B.Reallocate(m, n);
4719 const IVect& RowNumber = this->GetGlobalRowNumber();
4720 for (
int i = 0; i < n; i++)
4722 int size_col = Ptr(i+1) - Ptr(i);
4723 size_col += dist_row(i).GetM();
4725 size_col += dist_col(i).GetM();
4727 IVect index(size_col), proc_loc(size_col);
4731 for (
int j = Ptr(i); j < Ptr(i+1); j++)
4733 index(nb) = RowNumber(Ind(j));
4735 proc_loc(nb) = rank;
4740 for (
int j = 0; j < dist_row(i).GetM(); j++)
4742 index(nb) = dist_row(i).Index(j);
4743 if (this->local_number_distant_values)
4744 index(nb) = global_row_to_recv(index(nb));
4746 proc_loc(nb) = proc_row(i)(j);
4747 value(nb) = dist_row(i).Value(j);
4753 for (
int j = 0; j < dist_col(i).GetM(); j++)
4755 index(nb) = dist_col(i).Index(j);
4756 if (this->local_number_distant_values)
4757 index(nb) = global_col_to_recv(index(nb));
4759 proc_loc(nb) = proc_col(i)(j);
4764 Sort(nb, index, value, proc_loc);
4767 for (
int j = 0; j < nb; j++)
4769 if (index(j) == prec)
4770 value(size_col-1) += value(j);
4773 index(size_col) = index(j);
4774 value(size_col) = value(j);
4775 proc_loc(size_col) = proc_loc(j);
4782 B.ReallocateColumn(i, size_col);
4783 for (
int j = 0; j < size_col; j++)
4785 B.Index(i, j) = index(j);
4786 B.Value(i, j) = value(j);
4791 procB(i).Reallocate(size_col);
4792 for (
int j = 0; j < size_col; j++)
4793 procB(i)(j) = proc_loc(j);
4808 template<
class T,
class Prop,
class Storage,
class Allocator>
4810 :
Matrix<T, Prop, Storage, Allocator>(),
4821 template<
class T,
class Prop,
class Storage,
class Allocator>
4823 :
Matrix<T, Prop, Storage, Allocator>(i, j),
4830 template<
class T,
class Prop,
class Storage,
class Allocator>
4840 template<
class T,
class Prop,
class Storage,
class Allocator>
4850 template<
class T,
class Prop,
class Storage,
class Allocator>
4859 template<
class T,
class Prop,
class Storage,
class Allocator>
4867 template<
class T,
class Prop,
class Storage,
class Allocator>
4868 template<
class T2,
class Prop2,
class Storage2,
class Allocator2>
4882 template<
class T,
class Prop,
class Storage,
class Allocator>
4895 template<
class T,
class Prop,
class Storage,
class Allocator>
4911 template<
class T,
class Prop,
class Storage,
class Allocator>
4927 template<
class T,
class Prop,
class Storage,
class Allocator>
4942 template<
class T,
class Prop,
class Storage,
class Allocator>
4948 Allocator
>& >(*
this),
4956 template<
class T,
class Prop,
class Storage,
class Allocator>
4961 MPI_Comm& comm = this->comm_;
4962 int nb_proc; MPI_Comm_size(comm, &nb_proc);
4967 const IVect& overlap = this->GetOverlapRowNumber();
4968 T zero; SetComplexZero(zero);
4969 for (
int i = 0; i < overlap.GetM(); i++)
4970 this->Set(overlap(i), overlap(i), zero);
4977 template<
class T,
class Prop,
class Storage,
class Allocator>
4990 template<
class T,
class Prop,
class Storage,
class Allocator>
5003 template<
class T,
class Prop,
class Storage,
class Allocator>
5013 template<
class T,
class Prop,
class Storage,
class Allocator>
5021 template<
class T,
class Prop,
class Storage,
class Allocator>
5025 const MPI_Comm& comm = this->comm_;
5026 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5030 cout <<
"Write not implemented for distributed matrices" << endl;
5036 template<
class T,
class Prop,
class Storage,
class Allocator>
5040 const MPI_Comm& comm = this->comm_;
5041 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5045 cout <<
"Write not implemented for distributed matrices" << endl;
5051 template<
class T,
class Prop,
class Storage,
class Allocator>
5055 const MPI_Comm& comm = this->comm_;
5056 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5057 int rank_proc; MPI_Comm_rank(comm, &rank_proc);
5066 ofstream FileStream(name.c_str());
5067 FileStream.precision(15);
5069 #ifdef SELDON_CHECK_IO
5071 if (!FileStream.is_open())
5072 throw IOError(
"DistributedMatrix::WriteText(string FileName)",
5073 string(
"Unable to open file \"") + name +
"\".");
5077 WriteText(FileStream, cplx);
5085 template<
class T,
class Prop,
class Storage,
class Allocator>
5089 const MPI_Comm& comm = this->comm_;
5090 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5097 ConvertMatrix_to_Coordinates(*
this, IndRow, IndCol, Value, 0,
true);
5100 IndRow, IndCol, Value, cplx);
5105 template<
class T,
class Prop,
class Storage,
class Allocator>
5108 MPI_Comm& comm = this->comm_;
5109 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5113 cout <<
"Read not implemented for distributed matrices" << endl;
5119 template<
class T,
class Prop,
class Storage,
class Allocator>
5123 MPI_Comm& comm = this->comm_;
5124 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5128 cout <<
"Read not implemented for distributed matrices" << endl;
5134 template<
class T,
class Prop,
class Storage,
class Allocator>
5138 MPI_Comm& comm = this->comm_;
5139 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5143 cout <<
"ReadText not implemented for distributed matrices" << endl;
5149 template<
class T,
class Prop,
class Storage,
class Allocator>
5153 MPI_Comm& comm = this->comm_;
5154 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5158 cout <<
"ReadText not implemented for distributed matrices" << endl;
5169 template<
class T,
class Prop,
class Storage,
class Allocator>
5170 template<
class T0,
class Allocator0>
5186 template<
class T,
class Prop,
class Storage,
class Allocator>
5187 template<
class T0,
class Allocator0>
5195 ConvertToCSC(*
this, sym, Ptr, Ind, Val, sym_pattern);
5213 template<
class T0,
class T1,
class Prop1,
class Storage1,
class Allocator1,
5214 class T2,
class Storage2,
class Allocator2,
class T3,
5215 class T4,
class Storage4,
class Allocator4>
5216 void MltAddVector(
const T0& alpha,
5222 bool proceed_distant_row, proceed_distant_col;
5224 M.
InitMltAdd(proceed_distant_row, proceed_distant_col,
5225 X, Xcol, beta, Y, Yres);
5233 X, Xcol, alpha, beta, Y, Yres, assemble);
5238 template<
class T0,
class T1,
class Prop1,
class Storage1,
5240 class T2,
class Storage2,
class Allocator2,
class T3,
5241 class T4,
class Storage4,
class Allocator4>
5242 void MltAddVector(
const T0& alpha,
5249 if (Trans.NoTrans())
5251 MltAddVector(alpha, M, X, beta, Yres, assemble);
5255 bool proceed_distant_row, proceed_distant_col;
5257 M.
InitMltAdd(proceed_distant_row, proceed_distant_col,
5258 Trans, X, Xrow, beta, Y, Yres);
5261 MltVector(Trans,
static_cast<const Matrix<T1, Prop1,
5262 Storage1, Allocator1
>& >(M), X, Y);
5265 Trans, X, Xrow, alpha, beta, Y, Yres, assemble);
5271 template<
class T1,
class Prop1,
class Allocator1>
5275 for (
int i = 0; i < A.GetM(); i++)
5276 for (
int j = 0; j < A.GetRowSize(i); j++)
5278 int col = A.Index(i, j);
5279 if (Yproc(col) < Yproc(i))
5281 Yproc(i) = Yproc(col);
5284 else if (Yproc(col) == Yproc(i))
5293 Yproc(col) = Yproc(i);
5302 template<
class T1,
class Prop1,
class Allocator1>
5306 for (
int i = 0; i < A.GetM(); i++)
5307 for (
int j = 0; j < A.GetRowSize(i); j++)
5309 int col = A.Index(i, j);
5310 if (Yproc(col) < Yproc(i))
5312 Yproc(i) = Yproc(col);
5315 else if (Yproc(col) == Yproc(i))
5324 Yproc(col) = Yproc(i);
5331 #ifdef SELDON_FILE_MATRIX_ARRAY_COMPLEX_SPARSE_HXX
5332 template<
class T1,
class Prop1,
class Allocator1>
5335 void MltMin(
const Matrix<T1, Prop1, ArrayRowComplexSparse, Allocator1>& A,
5336 const IVect& global, IVect& Y, IVect& Yproc)
5338 for (
int i = 0; i < A.GetM(); i++)
5340 for (
int j = 0; j < A.GetRealRowSize(i); j++)
5342 int col = A.IndexReal(i, j);
5343 if (Yproc(col) < Yproc(i))
5345 Yproc(i) = Yproc(col);
5348 else if (Yproc(col) == Yproc(i))
5357 Yproc(col) = Yproc(i);
5362 for (
int j = 0; j < A.GetImagRowSize(i); j++)
5364 int col = A.IndexImag(i, j);
5365 if (Yproc(col) < Yproc(i))
5367 Yproc(i) = Yproc(col);
5370 else if (Yproc(col) == Yproc(i))
5379 Yproc(col) = Yproc(i);
5389 template<
class T1,
class Prop1,
class Allocator1>
5390 void MltMin(
const Matrix<T1, Prop1,
5391 ArrayRowSymComplexSparse, Allocator1>& A,
5392 const IVect& global, IVect& Y, IVect& Yproc)
5394 for (
int i = 0; i < A.GetM(); i++)
5396 for (
int j = 0; j < A.GetRealRowSize(i); j++)
5398 int col = A.IndexReal(i, j);
5399 if (Yproc(col) < Yproc(i))
5401 Yproc(i) = Yproc(col);
5404 else if (Yproc(col) == Yproc(i))
5413 Yproc(col) = Yproc(i);
5418 for (
int j = 0; j < A.GetImagRowSize(i); j++)
5420 int col = A.IndexImag(i, j);
5421 if (Yproc(col) < Yproc(i))
5423 Yproc(i) = Yproc(col);
5426 else if (Yproc(col) == Yproc(i))
5435 Yproc(col) = Yproc(i);
5445 template<
class T1,
class Prop1,
class Storage1,
class Allocator1>
5449 IVect Xcol, Xcol_proc;
5467 template<
class T0,
class T1,
class Prop1,
class Storage1,
class Allocator1,
5468 class T2,
class Prop2,
class Storage2,
class Allocator2>
5488 template<
class T1,
class Prop1,
class Storage1,
class Allocator1>
5489 typename ClassComplexType<T1>::Treal
5492 typename ClassComplexType<T1>::Treal res;
5494 Storage1, Allocator1
>& >(A));
5506 template<
class T0,
class T,
class Prop,
class Storage,
class Allocator>
5523 template<
class T0,
class T,
class Prop,
class Storage,
class Allocator>
5539 template<
class T0,
class T,
class Prop,
class Storage,
class Allocator>
5543 GetRowColSum(sum_row, sum_col,
5555 template<
class T1,
class Prop1,
class Storage1,
class Allocator1>
5556 typename ClassComplexType<T1>::Treal
5560 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5563 Storage1, Allocator1
>& >(A));
5566 GetColSum(sum_col, A);
5568 typename ClassComplexType<T1>::Treal res, amax;
5570 for (
int i = 0; i < sum_col.GetM(); i++)
5571 amax = max(amax, abs(sum_col(i)));
5574 MpiAllreduce(comm, &amax, xtmp, &res, 1, MPI_MAX);
5584 template<
class T1,
class Prop1,
class Storage1,
class Allocator1>
5585 typename ClassComplexType<T1>::Treal
5589 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5592 Storage1, Allocator1
>& >(A));
5595 GetRowSum(sum_row, A);
5597 typename ClassComplexType<T1>::Treal res, amax;
5599 for (
int i = 0; i < sum_row.GetM(); i++)
5600 amax = max(amax, abs(sum_row(i)));
5603 MpiAllreduce(comm, &amax, xtmp, &res, 1, MPI_MAX);
5609 template<
class T1,
class Prop1,
class Storage1,
class Allocator1>
5617 bool local_number_distant_values;
5618 int smax_row, smax_col;
5621 IVect global_row_to_recv, global_col_to_recv;
5622 IVect ptr_global_row_to_recv, ptr_global_col_to_recv;
5624 IVect proc_col_to_recv, proc_col_to_send,
5625 proc_row_to_recv, proc_row_to_send;
5629 dist_row, dist_col, proc_row, proc_col,
5630 global_row_to_recv, global_col_to_recv,
5631 ptr_global_row_to_recv, ptr_global_col_to_recv,
5632 local_row_to_send, local_col_to_send,
5633 proc_row_to_recv, proc_col_to_recv,
5634 proc_row_to_send, proc_col_to_send);
5641 dist_col, dist_row, proc_col, proc_row,
5642 global_col_to_recv, global_row_to_recv,
5643 ptr_global_col_to_recv, ptr_global_row_to_recv,
5644 local_col_to_send, local_row_to_send,
5645 proc_col_to_recv, proc_row_to_recv,
5646 proc_col_to_send, proc_row_to_send);
5651 template<
class T1,
class Prop1,
class Storage1,
class Allocator1>
5661 template<
class T1,
class Prop1,
class Storage1,
class Allocator1>
5673 template<
class T,
class Prop,
class Storage,
class Allocator>
5683 template<
class T,
class Prop,
class Storage,
class Allocator>
5697 template<
class T1,
class Prop1,
class Storage1,
class Allocator1,
5698 class T2,
class Prop2,
class Storage2,
class Allocator2,
5699 class T4,
class Prop4,
class Storage4,
class Allocator4>
5705 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5712 cout <<
"Mlt not implemented for distributed matrices" << endl;
5719 class T1,
class Prop1,
class Storage1,
class Allocator1,
5720 class T2,
class Prop2,
class Storage2,
class Allocator2,
5722 class T4,
class Prop4,
class Storage4,
class Allocator4>
5730 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5739 cout <<
"MltAdd not implemented for distributed matrices" << endl;
5746 class T1,
class Prop1,
class Storage1,
class Allocator1,
5747 class T2,
class Prop2,
class Storage2,
class Allocator2,
5749 class T4,
class Prop4,
class Storage4,
class Allocator4>
5758 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5761 static_cast<const Matrix<T1, Prop1,
5762 Storage1, Allocator1
>& >(A),
5764 static_cast<const Matrix<T2, Prop2,
5765 Storage2, Allocator2
>& >(B),
5767 static_cast<Matrix<T4, Prop4,
5768 Storage4, Allocator4
>& >(C));
5770 cout <<
"MltAdd not implemented for distributed matrices" << endl;
5781 template<
class T0,
class Prop0,
class Storage0,
class Allocator0,
5782 class T1,
class Allocator1>
5787 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5789 return GetRow(
static_cast<const Matrix<T0, Prop0,
5790 Storage0, Allocator0
>& >(A), i, X);
5792 cout <<
"GetRow not implemented for distributed matrices" << endl;
5798 template<
class T0,
class Prop0,
class Storage0,
class Allocator0,
5799 class T1,
class Allocator1>
5804 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5806 return GetCol(
static_cast<const Matrix<T0, Prop0,
5807 Storage0, Allocator0
>& >(A), i, X);
5809 cout <<
"GetCol not implemented for distributed matrices" << endl;
5815 template<
class T0,
class Prop0,
class Storage0,
class Allocator0,
5816 class T1,
class Allocator1>
5821 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5823 return SetRow(X, i,
static_cast<Matrix<T0, Prop0,
5824 Storage0, Allocator0
>& >(A));
5826 cout <<
"SetRow not implemented for distributed matrices" << endl;
5832 template<
class T0,
class Prop0,
class Storage0,
class Allocator0,
5833 class T1,
class Allocator1>
5838 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5840 return SetCol(X, i,
static_cast<Matrix<T0, Prop0,
5841 Storage0, Allocator0
>& >(A));
5843 cout <<
"SetCol not implemented for distributed matrices" << endl;
5849 template<
class T,
class Prop,
class Storage,
class Allocator>
5855 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5857 return ApplyPermutation(
static_cast<Matrix<T, Prop,
5858 Storage, Allocator
>& >(A),
5859 row_perm, col_perm);
5861 cout <<
"ApplyPermutation not implemented for distributed matrices"
5868 template<
class T,
class Prop,
class Storage,
class Allocator>
5870 Storage, Allocator>& A,
5874 MPI_Comm& comm = A.GetCommunicator();
5875 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5877 return ApplyInversePermutation(
static_cast<Matrix<T, Prop, Storage,
5879 row_perm, col_perm);
5881 cout <<
"ApplyInversePermutation not implemented for distributed matrices"
5888 template <
class T0,
class Prop0,
class Storage0,
class Allocator0,
5889 class T1,
class Storage1,
class Allocator1,
5890 class T2,
class Storage2,
class Allocator2,
class T3>
5894 const T3& omega,
int iter,
int type_ssor)
5897 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5900 Storage0, Allocator0
>& >(A),
5901 X, B, omega, iter, type_ssor);
5903 cout <<
"SOR not implemented for distributed matrices" << endl;
5909 template <
class T0,
class Prop0,
class Storage0,
class Allocator0,
5910 class T1,
class Storage1,
class Allocator1,
5911 class T2,
class Storage2,
class Allocator2,
class T3>
5916 const T3& omega,
int iter,
int type_ssor)
5918 if (transM.NoTrans())
5919 return SorVector(A, X, B, omega, iter, type_ssor);
5922 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5925 static_cast<const Matrix<T0, Prop0,
5926 Storage0, Allocator0
>& >(A),
5927 X, B, omega, iter, type_ssor);
5929 cout <<
"SOR not implemented for distributed matrices" << endl;
5935 template<
class T1,
class Prop,
class Storage,
class Allocator,
5936 class T2,
class Allocator2,
class Allocator3>
5938 const IVect& col_number,
5943 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5945 return GetCol(
static_cast<const Matrix<T1, Prop,
5946 Storage, Allocator
>& >(A),
5949 cout <<
"GetCol not implemented for distributed matrices" << endl;
5955 template<
class T,
class Prop1,
class Storage1,
class Allocator1,
5956 class Prop2,
class Storage2,
class Allocator2>
5965 template<
class T,
class Prop1,
class Storage1,
class Allocator1,
5966 class Prop2,
class Storage2,
class Allocator2>
5975 template<
class T1,
class Prop1,
class Storage1,
class Allocator1,
5976 class T2,
class Prop2,
class Storage2,
class Allocator2>
5981 int nb_proc; MPI_Comm_size(comm, &nb_proc);
5984 Storage1, Allocator1
>& >(A),
5985 static_cast<Matrix<T2, Prop2,
5986 Storage2, Allocator2
>& >(B));
5988 cout <<
"CopyReal not implemented for distributed matrices" << endl;
5994 template<
class T,
class Prop,
class Storage,
class Allocator>
5995 typename ClassComplexType<T>::Treal
5999 int nb_proc; MPI_Comm_size(comm, &nb_proc);
6001 return NormFro(
static_cast<const Matrix<T, Prop,
6002 Storage, Allocator
>& >(A));
6004 cout <<
"NormFro not implemented for distributed matrices" << endl;
6010 template<
class T,
class Storage,
class Allocator,
6011 class T1,
class Allocator1>
6016 Storage, Allocator
>& >(A), Drow);
6023 template<
class T,
class Storage,
class Allocator,
6024 class T1,
class Allocator1>
6029 Storage, Allocator
>& >(A), Dcol);
6036 template<
class T,
class Prop,
class Storage,
class Allocator,
6037 class T1,
class Allocator1,
class T2,
class Allocator2>
6062 template<
class Prop,
class Storage,
class Alloc,
class T
int0,
class T
int1,
class T>
6065 IVect& row_numbers,
IVect& local_row_numbers,
6067 Vector<T>& ValA,
bool sym_pattern,
bool reorder)
6069 PtrA.Clear(); IndA.Clear(); ValA.Clear();
6075 procB.Reallocate(A.GetM());
6083 IVect OverlappedCol;
6085 OverlappedCol, sym_pattern, reorder);
6105 template<
class Prop,
class Storage,
class Alloc,
class T
int0,
class T
int1,
class T>
6107 General& prop,
const MPI_Comm& comm,
6108 IVect& col_numbers,
IVect& local_col_numbers,
6110 Vector<T>& ValA,
bool sym_pattern,
bool reorder)
6112 PtrA.Clear(); IndA.Clear(); ValA.Clear();
6118 procB.Reallocate(A.GetN());
6126 IVect OverlappedCol;
6128 OverlappedCol, sym_pattern, reorder);
6142 template<
class T1,
class Prop1,
class Storage1,
class Allocator1>
6160 template<
class T1,
class Prop1,
class Storage1,
class Allocator1>
6172 template<
class T0,
class Prop0,
class Storage0,
class Allocator0,
6173 class T1,
class Prop1,
class Storage1,
class Allocator1>
6179 CopySubMatrix(
static_cast<const Matrix<T0, Prop0,
6180 Storage0, Allocator0
>& >(A),
6181 row, col,
static_cast<Matrix<T1, Prop1,
6182 Storage1, Allocator1
>& >(B));
6189 #define SELDON_FILE_DISTRIBUTED_MATRIX_CXX