43 #include "Ifpack_ConfigDefs.h"
44 #include "Ifpack_OverlappingRowMatrix.h"
45 #include "Epetra_RowMatrix.h"
46 #include "Epetra_Map.h"
47 #include "Epetra_CrsMatrix.h"
48 #include "Epetra_Comm.h"
49 #include "Epetra_MultiVector.h"
51 #ifdef IFPACK_SUBCOMM_CODE
52 #include "Epetra_IntVector.h"
53 #include "Epetra_MpiComm.h"
54 #include "Teuchos_Hashtable.hpp"
55 #include "Teuchos_Array.hpp"
56 #include "EpetraExt_OperatorOut.h"
57 #include "EpetraExt_BlockMapOut.h"
59 # ifdef IFPACK_NODE_AWARE_CODE
60 # include "Epetra_IntVector.h"
61 # include "Epetra_MpiComm.h"
62 # include "Teuchos_Hashtable.hpp"
63 # include "Teuchos_Array.hpp"
64 # include "EpetraExt_OperatorOut.h"
65 # include "EpetraExt_BlockMapOut.h"
66 extern int ML_NODE_ID;
71 using namespace Teuchos;
75 Ifpack_OverlappingRowMatrix::
76 Ifpack_OverlappingRowMatrix(
const RCP<const Epetra_RowMatrix>& Matrix_in,
77 int OverlapLevel_in) :
79 OverlapLevel_(OverlapLevel_in)
82 if (OverlapLevel_in == 0)
86 if (
Comm().NumProc() == 1)
89 NumMyRowsA_ = A().NumMyRows();
92 vector<int> ExtElements;
94 RCP<Epetra_Map> TmpMap;
95 RCP<Epetra_CrsMatrix> TmpMatrix;
96 RCP<Epetra_Import> TmpImporter;
100 const Epetra_Map *RowMap;
101 const Epetra_Map *ColMap;
103 for (
int overlap = 0 ; overlap < OverlapLevel_in ; ++overlap) {
104 if (TmpMatrix != Teuchos::null) {
105 RowMap = &(TmpMatrix->RowMatrixRowMap());
106 ColMap = &(TmpMatrix->RowMatrixColMap());
109 RowMap = &(A().RowMatrixRowMap());
110 ColMap = &(A().RowMatrixColMap());
113 int size = ColMap->NumMyElements() - RowMap->NumMyElements();
114 vector<int> list(size);
119 for (
int i = 0 ; i < ColMap->NumMyElements() ; ++i) {
120 int GID = ColMap->GID(i);
121 if (A().RowMatrixRowMap().LID(GID) == -1) {
122 vector<int>::iterator pos
123 = find(ExtElements.begin(),ExtElements.end(),GID);
124 if (pos == ExtElements.end()) {
125 ExtElements.push_back(GID);
132 const int *listptr = NULL;
133 if ( ! list.empty() ) listptr = &list[0];
134 TmpMap = rcp(
new Epetra_Map(-1,count, listptr,0,
Comm()) );
136 TmpMatrix = rcp(
new Epetra_CrsMatrix(Copy,*TmpMap,0) );
138 TmpImporter = rcp(
new Epetra_Import(*TmpMap,A().RowMatrixRowMap()) );
140 TmpMatrix->Import(A(),*TmpImporter,Insert);
141 TmpMatrix->FillComplete(A().OperatorDomainMap(),*TmpMap);
147 vector<int> list(NumMyRowsA_ + ExtElements.size());
148 for (
int i = 0 ; i < NumMyRowsA_ ; ++i)
149 list[i] = A().RowMatrixRowMap().GID(i);
150 for (
int i = 0 ; i < (int)ExtElements.size() ; ++i)
151 list[i + NumMyRowsA_] = ExtElements[i];
153 const int *listptr = NULL;
154 if ( ! list.empty() ) listptr = &list[0];
156 Map_ = rcp(
new Epetra_Map(-1, NumMyRowsA_ + ExtElements.size(),
157 listptr, 0,
Comm()) );
159 #ifdef IFPACK_SUBCOMM_CODE
162 # ifdef IFPACK_NODE_AWARE_CODE
169 const int * extelsptr = NULL;
170 if ( ! ExtElements.empty() ) extelsptr = &ExtElements[0];
171 ExtMap_ = rcp(
new Epetra_Map(-1,ExtElements.size(),
172 extelsptr,0,A().Comm()) );
174 ExtMatrix_ = rcp(
new Epetra_CrsMatrix(Copy,*ExtMap_,*Map_,0) );
176 ExtImporter_ = rcp(
new Epetra_Import(*ExtMap_,A().RowMatrixRowMap()) );
177 ExtMatrix_->Import(A(),*ExtImporter_,Insert);
178 ExtMatrix_->FillComplete(A().OperatorDomainMap(),*Map_);
180 Importer_ = rcp(
new Epetra_Import(*Map_,A().RowMatrixRowMap()) );
183 NumMyRowsB_ = B().NumMyRows();
184 NumMyRows_ = NumMyRowsA_ + NumMyRowsB_;
185 NumMyCols_ = NumMyRows_;
187 NumMyDiagonals_ = A().NumMyDiagonals() + B().NumMyDiagonals();
189 NumMyNonzeros_ = A().NumMyNonzeros() + B().NumMyNonzeros();
190 long long NumMyNonzeros_tmp = NumMyNonzeros_;
191 Comm().SumAll(&NumMyNonzeros_tmp,&NumGlobalNonzeros_,1);
192 MaxNumEntries_ = A().MaxNumEntries();
195 MaxNumEntries_ = B().MaxNumEntries();
199 #ifdef IFPACK_SUBCOMM_CODE
203 Ifpack_OverlappingRowMatrix::
204 Ifpack_OverlappingRowMatrix(
const RCP<const Epetra_RowMatrix>& Matrix_in,
205 int OverlapLevel_in,
int subdomainID) :
207 OverlapLevel_(OverlapLevel_in)
211 #ifdef IFPACK_OVA_TIME_BUILD
212 double t0 = MPI_Wtime();
213 double t1, true_t0=t0;
217 const int votesMax = INT_MAX;
220 if (OverlapLevel_in == 0)
224 if (
Comm().NumProc() == 1)
231 const Epetra_MpiComm *pComm =
dynamic_cast<const Epetra_MpiComm*
>( &
Comm() );
232 assert(pComm != NULL);
233 MPI_Comm nodeMPIComm;
234 MPI_Comm_split(pComm->Comm(),subdomainID,pComm->MyPID(),&nodeMPIComm);
235 Epetra_MpiComm *nodeComm =
new Epetra_MpiComm(nodeMPIComm);
237 Epetra_SerialComm *nodeComm =
dynamic_cast<Epetra_MpiComm*
>( &(Matrix_in->RowMatrixRowMap().Comm()) );
240 NumMyRowsA_ = A().NumMyRows();
242 RCP<Epetra_Map> TmpMap;
243 RCP<Epetra_CrsMatrix> TmpMatrix;
244 RCP<Epetra_Import> TmpImporter;
248 const Epetra_Map *RowMap;
249 const Epetra_Map *ColMap;
250 const Epetra_Map *DomainMap;
256 #ifdef IFPACK_OVA_TIME_BUILD
258 fprintf(stderr,
"[node %d]: time for initialization %2.3e\n", subdomainID, t1-t0);
263 #ifdef IFPACK_OVA_TIME_BUILD
265 fprintf(stderr,
"[node %d]: overlap hash table allocs %2.3e\n", subdomainID, t1-t0);
269 Teuchos::Hashtable<int,int> colMapTable(3 * A().RowMatrixColMap().NumMyElements() );
273 Teuchos::Hashtable<int,int> ghostTable(3 * A().RowMatrixColMap().NumMyElements() );
278 for (
int overlap = 0 ; overlap < OverlapLevel_in ; ++overlap)
283 if (TmpMatrix != Teuchos::null) {
284 RowMap = &(TmpMatrix->RowMatrixRowMap());
285 ColMap = &(TmpMatrix->RowMatrixColMap());
286 DomainMap = &(TmpMatrix->OperatorDomainMap());
289 RowMap = &(A().RowMatrixRowMap());
290 ColMap = &(A().RowMatrixColMap());
291 DomainMap = &(A().OperatorDomainMap());
294 #ifdef IFPACK_OVA_TIME_BUILD
296 fprintf(stderr,
"[node %d]: overlap pointer pulls %2.3e\n", subdomainID, t1-t0);
302 Epetra_IntVector colIdList( *ColMap );
303 Epetra_IntVector rowIdList(*DomainMap);
304 rowIdList.PutValue(subdomainID);
305 Teuchos::RCP<Epetra_Import> nodeIdImporter = rcp(
new Epetra_Import( *ColMap, *DomainMap ));
307 #ifdef IFPACK_OVA_TIME_BUILD
309 fprintf(stderr,
"[node %d]: overlap intvector/importer allocs %2.3e\n", subdomainID, t1-t0);
313 colIdList.Import(rowIdList,*nodeIdImporter,Insert);
315 int size = ColMap->NumMyElements() - RowMap->NumMyElements();
318 #ifdef IFPACK_OVA_TIME_BUILD
320 fprintf(stderr,
"[node %d]: overlap col/row ID imports %2.3e\n", subdomainID, t1-t0);
327 for (
int i = 0 ; i < ColMap->NumMyElements() ; ++i) {
328 int GID = ColMap->GID(i);
330 if (ghostTable.containsKey(GID)) myvotes = ghostTable.get(GID);
331 if ( colIdList[i] != subdomainID && myvotes < votesMax)
334 if (ghostTable.containsKey(GID)) {
335 votes = ghostTable.get(GID);
337 ghostTable.put(GID,votes);
339 ghostTable.put(GID,1);
344 Teuchos::Array<int> gidsarray,votesarray;
345 ghostTable.arrayify(gidsarray,votesarray);
346 int *gids = gidsarray.getRawPtr();
347 int *votes = votesarray.getRawPtr();
358 # ifdef HAVE_MPI //FIXME What if we build in serial?! This file will likely not compile.
364 #ifdef IFPACK_OVA_TIME_BUILD
366 fprintf(stderr,
"[node %d]: overlap before culling %2.3e\n", subdomainID, t1-t0);
372 if (nodeComm->MyPID() == 0)
376 int *lengths =
new int[nodeComm->NumProc()+1];
378 lengths[1] = ghostTable.size();
379 for (
int i=1; i<nodeComm->NumProc(); i++) {
381 MPI_Recv( &leng, 1, MPI_INT, i, MPI_ANY_TAG, nodeComm->Comm(), &status);
382 lengths[i+1] = lengths[i] + leng;
384 int total = lengths[nodeComm->NumProc()];
386 int* ghosts =
new int[total];
387 for (
int i=0; i<total; i++) ghosts[i] = -9;
388 int *round =
new int[total];
389 int *owningpid =
new int[total];
391 for (
int i=1; i<nodeComm->NumProc(); i++) {
392 int count = lengths[i+1] - lengths[i];
393 MPI_Recv( ghosts+lengths[i], count, MPI_INT, i, MPI_ANY_TAG, nodeComm->Comm(), &status);
394 MPI_Recv( round+lengths[i], count, MPI_INT, i, MPI_ANY_TAG, nodeComm->Comm(), &status);
398 for (
int i=0; i<lengths[1]; i++) {
405 for (
int j=1; j<nodeComm->NumProc(); j++) {
406 for (
int i=lengths[j]; i<lengths[j+1]; i++) {
413 roundpid[0] = round; roundpid[1] = owningpid;
414 Epetra_Util epetraUtil;
415 epetraUtil.Sort(
true,total,ghosts,0,0,2,roundpid);
418 int *nlosers =
new int[nodeComm->NumProc()];
419 int** losers =
new int*[nodeComm->NumProc()];
420 for (
int i=0; i<nodeComm->NumProc(); i++) {
422 losers[i] =
new int[ lengths[i+1]-lengths[i] ];
434 for (
int i=1; i<total; i++) {
435 if (ghosts[i] == ghosts[i-1]) {
437 if (round[i] > round[max]) {
441 int j = owningpid[idx];
442 losers[j][nlosers[j]++] = ghosts[idx];
453 for (
int i=1; i<nodeComm->NumProc(); i++) {
454 MPI_Send( nlosers+i, 1, MPI_INT, i, 8675, nodeComm->Comm());
455 MPI_Send( losers[i], nlosers[i], MPI_INT, i, 8675, nodeComm->Comm());
462 cullList =
new int[ncull+1];
463 for (
int i=0; i<nlosers[0]; i++)
464 cullList[i] = losers[0][i];
466 for (
int i=0; i<nodeComm->NumProc(); i++)
476 int hashsize = ghostTable.size();
477 MPI_Send( &hashsize, 1, MPI_INT, 0, 8675, nodeComm->Comm());
478 MPI_Send( gids, hashsize, MPI_INT, 0, 8675, nodeComm->Comm());
479 MPI_Send( votes, hashsize, MPI_INT, 0, 8675, nodeComm->Comm());
483 MPI_Recv( &ncull, 1, MPI_INT, 0, 8675, nodeComm->Comm(), &status);
484 cullList =
new int[ncull+1];
485 MPI_Recv( cullList, ncull, MPI_INT, 0, 8675, nodeComm->Comm(), &status);
492 for (
int i=0; i<ncull; i++) {
493 try{ghostTable.remove(cullList[i]);}
496 printf(
"pid %d: In OverlappingRowMatrix ctr, problem removing ghost elt %d from ghostTable\n",
497 Comm().MyPID(),cullList[i]);
506 gidsarray.clear(); votesarray.clear();
507 ghostTable.arrayify(gidsarray,votesarray);
509 vector<int> list(size);
511 for (
int i=0; i<ghostTable.size(); i++) {
513 if (votesarray[i] < votesMax) {
514 list[count] = gidsarray[i];
515 ghostTable.put(gidsarray[i],votesMax);
521 #ifdef IFPACK_OVA_TIME_BUILD
523 fprintf(stderr,
"[node %d]: overlap duplicate removal %2.3e\n", subdomainID, t1-t0);
528 # endif //ifdef HAVE_MPI
530 TmpMap = rcp(
new Epetra_Map(-1,count, &list[0],0,
Comm()) );
532 TmpMatrix = rcp(
new Epetra_CrsMatrix(Copy,*TmpMap,0) );
534 TmpImporter = rcp(
new Epetra_Import(*TmpMap,A().RowMatrixRowMap()) );
536 TmpMatrix->Import(A(),*TmpImporter,Insert);
537 TmpMatrix->FillComplete(A().OperatorDomainMap(),*TmpMap);
540 #ifdef IFPACK_OVA_TIME_BUILD
542 fprintf(stderr,
"[node %d]: overlap TmpMatrix fillcomplete %2.3e\n", subdomainID, t1-t0);
553 Epetra_IntVector ov_colIdList( TmpMatrix->ColMap() );
554 ov_colIdList.PutValue(-1);
555 Epetra_IntVector ov_rowIdList( TmpMatrix->RowMap() );
556 ov_rowIdList.PutValue(subdomainID);
557 Teuchos::RCP<Epetra_Import> ov_nodeIdImporter = rcp(
new Epetra_Import( TmpMatrix->ColMap(), TmpMatrix->RowMap()));
558 ov_colIdList.Import(ov_rowIdList,*ov_nodeIdImporter,Insert);
560 for (
int i=0 ; i<ov_colIdList.MyLength(); i++) {
561 if (ov_colIdList[i] == subdomainID) {
562 int GID = (ov_colIdList.Map()).GID(i);
563 colMapTable.put(GID,1);
570 ov_colIdList.PutValue(-1);
571 Epetra_IntVector ArowIdList( A().RowMatrixRowMap() );
572 ArowIdList.PutValue(subdomainID);
573 nodeIdImporter = rcp(
new Epetra_Import( TmpMatrix->ColMap(), A().RowMatrixRowMap() ));
574 ov_colIdList.Import(ArowIdList,*nodeIdImporter,Insert);
576 for (
int i=0 ; i<ov_colIdList.MyLength(); i++) {
577 if (ov_colIdList[i] == subdomainID) {
578 int GID = (ov_colIdList.Map()).GID(i);
579 colMapTable.put(GID,1);
584 #ifdef IFPACK_OVA_TIME_BUILD
586 fprintf(stderr,
"[node %d]: overlap 2 imports to fix up colmap %2.3e\n", subdomainID, t1-t0);
598 vector<int> ghostElements;
600 Teuchos::Array<int> gidsarray,votesarray;
601 ghostTable.arrayify(gidsarray,votesarray);
602 for (
int i=0; i<ghostTable.size(); i++) {
603 ghostElements.push_back(gidsarray[i]);
606 for (
int i = 0 ; i < A().RowMatrixColMap().NumMyElements() ; ++i) {
607 int GID = A().RowMatrixColMap().GID(i);
609 if (colMapTable.containsKey(GID)) {
610 try{colMapTable.remove(GID);}
612 printf(
"pid %d: In OverlappingRowMatrix ctr, problem removing entry %d from colMapTable\n",
Comm().MyPID(),GID);
619 vector<int> colMapElements;
621 gidsarray.clear(); votesarray.clear();
622 colMapTable.arrayify(gidsarray,votesarray);
623 for (
int i=0; i<colMapTable.size(); i++)
624 colMapElements.push_back(gidsarray[i]);
637 vector<int> rowList(NumMyRowsA_ + ghostElements.size());
638 for (
int i = 0 ; i < NumMyRowsA_ ; ++i)
639 rowList[i] = A().RowMatrixRowMap().GID(i);
640 for (
int i = 0 ; i < (int)ghostElements.size() ; ++i)
641 rowList[i + NumMyRowsA_] = ghostElements[i];
644 Map_ = rcp(
new Epetra_Map(-1, NumMyRowsA_ + ghostElements.size(), &rowList[0], 0,
Comm()) );
652 vector<int> colList(A().RowMatrixColMap().NumMyElements() + colMapElements.size());
653 int nc = A().RowMatrixColMap().NumMyElements();
654 for (
int i = 0 ; i < nc; i++)
655 colList[i] = A().RowMatrixColMap().GID(i);
656 for (
int i = 0 ; i < (int)colMapElements.size() ; i++)
657 colList[nc+i] = colMapElements[i];
661 colMap_ =
new Epetra_Map(-1, A().RowMatrixColMap().NumMyElements() + colMapElements.size(), &colList[0], 0,
Comm());
665 #ifdef IFPACK_OVA_TIME_BUILD
667 fprintf(stderr,
"[node %d]: time to init B() col/row maps %2.3e\n", subdomainID, t1-t0);
679 Epetra_Map* nodeMap =
new Epetra_Map(-1,NumMyRowsA_ + ghostElements.size(),&rowList[0],0,*nodeComm);
680 int numMyElts = colMap_->NumMyElements();
681 assert(numMyElts!=0);
687 int* myGlobalElts =
new int[numMyElts];
688 colMap_->MyGlobalElements(myGlobalElts);
689 int* pidList =
new int[numMyElts];
690 nodeMap->RemoteIDList(numMyElts, myGlobalElts, pidList, 0);
695 tt[0] = myGlobalElts;
696 Util.Sort(
true, numMyElts, pidList, 0, (
double**)0, 1, tt);
701 while (localStart<numMyElts) {
702 int currPID = (pidList)[localStart];
704 while (i<numMyElts && (pidList)[i] == currPID) i++;
705 if (currPID != nodeComm->MyPID())
706 Util.Sort(
true, i-localStart, (myGlobalElts)+localStart, 0, 0, 0, 0);
712 while (localStart<numMyElts && (pidList)[localStart] != nodeComm->MyPID()) localStart++;
713 assert(localStart != numMyElts);
714 int localEnd=localStart;
715 while (localEnd<numMyElts && (pidList)[localEnd] == nodeComm->MyPID()) localEnd++;
716 int* mySortedGlobalElts =
new int[numMyElts];
717 int leng = localEnd - localStart;
721 int *rowGlobalElts = nodeMap->MyGlobalElements();
741 for (
int i=0; i<leng; i++) {
743 (mySortedGlobalElts)[i] = rowGlobalElts[i];
747 for (
int i=leng; i< localEnd; i++) {
748 (mySortedGlobalElts)[i] = (myGlobalElts)[i-leng];
750 for (
int i=localEnd; i<numMyElts; i++) {
751 (mySortedGlobalElts)[i] = (myGlobalElts)[i];
755 #ifdef IFPACK_OVA_TIME_BUILD
757 fprintf(stderr,
"[node %d]: time to sort col map arrays (cp=1) %2.3e\n", subdomainID, t1-t0);
762 int indexBase = colMap_->IndexBase();
763 if (colMap_)
delete colMap_;
764 colMap_ =
new Epetra_Map(-1,numMyElts,mySortedGlobalElts,indexBase,
Comm());
767 delete [] myGlobalElts;
769 delete [] mySortedGlobalElts;
773 printf(
"** * Ifpack_OverlappingRowmatrix ctor: problem creating column map * **\n\n");
781 #ifdef IFPACK_OVA_TIME_BUILD
783 fprintf(stderr,
"[node %d]: time to sort col map arrays (cp=2) %2.3e\n", subdomainID, t1-t0);
813 ExtMap_ = rcp(
new Epetra_Map(-1,ghostElements.size(), &ghostElements[0],0,
Comm()) );
814 ExtMatrix_ = rcp(
new Epetra_CrsMatrix(Copy,*ExtMap_,*colMap_,0) );
816 ExtImporter_ = rcp(
new Epetra_Import(*ExtMap_,A().RowMatrixRowMap()) );
817 ExtMatrix_->Import(A(),*ExtImporter_,Insert);
820 #ifdef IFPACK_OVA_TIME_BUILD
822 fprintf(stderr,
"[node %d]: time to import and setup ExtMap_ %2.3e\n", subdomainID, t1-t0);
835 ExtMatrix_->FillComplete( *colMap_ , *Map_ );
838 #ifdef IFPACK_OVA_TIME_BUILD
840 fprintf(stderr,
"[node %d]: time to FillComplete B() %2.3e\n", subdomainID, t1-t0);
848 Importer_ = rcp(
new Epetra_Import(*Map_,A().RowMatrixRowMap()) );
851 NumMyRowsB_ = B().NumMyRows();
852 NumMyRows_ = NumMyRowsA_ + NumMyRowsB_;
855 NumMyCols_ = B().NumMyCols();
859 NumMyDiagonals_ = A().NumMyDiagonals() + B().NumMyDiagonals();
861 NumMyNonzeros_ = A().NumMyNonzeros() + B().NumMyNonzeros();
862 long long NumMyNonZerosTemp = NumMyNonzeros_;
863 Comm().SumAll(&NumMyNonZerosTemp,&NumGlobalNonzeros_,1);
864 MaxNumEntries_ = A().MaxNumEntries();
867 MaxNumEntries_ = B().MaxNumEntries();
874 #ifdef IFPACK_OVA_TIME_BUILD
876 fprintf(stderr,
"[node %d]: time for final calcs %2.3e\n", subdomainID, t1-t0);
877 fprintf(stderr,
"[node %d]: total IORM ctor time %2.3e\n", subdomainID, t1-true_t0);
885 # ifdef IFPACK_NODE_AWARE_CODE
889 Ifpack_OverlappingRowMatrix::
890 Ifpack_OverlappingRowMatrix(
const RCP<const Epetra_RowMatrix>& Matrix_in,
891 int OverlapLevel_in,
int nodeID) :
893 OverlapLevel_(OverlapLevel_in)
897 #ifdef IFPACK_OVA_TIME_BUILD
898 double t0 = MPI_Wtime();
899 double t1, true_t0=t0;
903 const int votesMax = INT_MAX;
906 if (OverlapLevel_in == 0)
910 if (
Comm().NumProc() == 1)
917 const Epetra_MpiComm *pComm =
dynamic_cast<const Epetra_MpiComm*
>( &
Comm() );
918 assert(pComm != NULL);
919 MPI_Comm nodeMPIComm;
920 MPI_Comm_split(pComm->Comm(),nodeID,pComm->MyPID(),&nodeMPIComm);
921 Epetra_MpiComm *nodeComm =
new Epetra_MpiComm(nodeMPIComm);
923 Epetra_SerialComm *nodeComm =
dynamic_cast<Epetra_MpiComm*
>( &(Matrix_in->RowMatrixRowMap().Comm()) );
926 NumMyRowsA_ = A().NumMyRows();
928 RCP<Epetra_Map> TmpMap;
929 RCP<Epetra_CrsMatrix> TmpMatrix;
930 RCP<Epetra_Import> TmpImporter;
934 const Epetra_Map *RowMap;
935 const Epetra_Map *ColMap;
936 const Epetra_Map *DomainMap;
942 #ifdef IFPACK_OVA_TIME_BUILD
944 fprintf(stderr,
"[node %d]: time for initialization %2.3e\n", nodeID, t1-t0);
949 #ifdef IFPACK_OVA_TIME_BUILD
951 fprintf(stderr,
"[node %d]: overlap hash table allocs %2.3e\n", nodeID, t1-t0);
955 Teuchos::Hashtable<int,int> colMapTable(3 * A().RowMatrixColMap().NumMyElements() );
959 Teuchos::Hashtable<int,int> ghostTable(3 * A().RowMatrixColMap().NumMyElements() );
964 for (
int overlap = 0 ; overlap < OverlapLevel_in ; ++overlap)
969 if (TmpMatrix != Teuchos::null) {
970 RowMap = &(TmpMatrix->RowMatrixRowMap());
971 ColMap = &(TmpMatrix->RowMatrixColMap());
972 DomainMap = &(TmpMatrix->OperatorDomainMap());
975 RowMap = &(A().RowMatrixRowMap());
976 ColMap = &(A().RowMatrixColMap());
977 DomainMap = &(A().OperatorDomainMap());
980 #ifdef IFPACK_OVA_TIME_BUILD
982 fprintf(stderr,
"[node %d]: overlap pointer pulls %2.3e\n", nodeID, t1-t0);
988 Epetra_IntVector colIdList( *ColMap );
989 Epetra_IntVector rowIdList(*DomainMap);
990 rowIdList.PutValue(nodeID);
991 Teuchos::RCP<Epetra_Import> nodeIdImporter = rcp(
new Epetra_Import( *ColMap, *DomainMap ));
993 #ifdef IFPACK_OVA_TIME_BUILD
995 fprintf(stderr,
"[node %d]: overlap intvector/importer allocs %2.3e\n", nodeID, t1-t0);
999 colIdList.Import(rowIdList,*nodeIdImporter,Insert);
1001 int size = ColMap->NumMyElements() - RowMap->NumMyElements();
1004 #ifdef IFPACK_OVA_TIME_BUILD
1006 fprintf(stderr,
"[node %d]: overlap col/row ID imports %2.3e\n", nodeID, t1-t0);
1013 for (
int i = 0 ; i < ColMap->NumMyElements() ; ++i) {
1014 int GID = ColMap->GID(i);
1016 if (ghostTable.containsKey(GID)) myvotes = ghostTable.get(GID);
1017 if ( colIdList[i] != nodeID && myvotes < votesMax)
1020 if (ghostTable.containsKey(GID)) {
1021 votes = ghostTable.get(GID);
1023 ghostTable.put(GID,votes);
1025 ghostTable.put(GID,1);
1030 Teuchos::Array<int> gidsarray,votesarray;
1031 ghostTable.arrayify(gidsarray,votesarray);
1032 int *gids = gidsarray.getRawPtr();
1033 int *votes = votesarray.getRawPtr();
1044 # ifdef HAVE_MPI //FIXME What if we build in serial?! This file will likely not compile.
1050 #ifdef IFPACK_OVA_TIME_BUILD
1052 fprintf(stderr,
"[node %d]: overlap before culling %2.3e\n", nodeID, t1-t0);
1058 if (nodeComm->MyPID() == 0)
1062 int *lengths =
new int[nodeComm->NumProc()+1];
1064 lengths[1] = ghostTable.size();
1065 for (
int i=1; i<nodeComm->NumProc(); i++) {
1067 MPI_Recv( &leng, 1, MPI_INT, i, MPI_ANY_TAG, nodeComm->Comm(), &status);
1068 lengths[i+1] = lengths[i] + leng;
1070 int total = lengths[nodeComm->NumProc()];
1072 int* ghosts =
new int[total];
1073 for (
int i=0; i<total; i++) ghosts[i] = -9;
1074 int *round =
new int[total];
1075 int *owningpid =
new int[total];
1077 for (
int i=1; i<nodeComm->NumProc(); i++) {
1078 int count = lengths[i+1] - lengths[i];
1079 MPI_Recv( ghosts+lengths[i], count, MPI_INT, i, MPI_ANY_TAG, nodeComm->Comm(), &status);
1080 MPI_Recv( round+lengths[i], count, MPI_INT, i, MPI_ANY_TAG, nodeComm->Comm(), &status);
1084 for (
int i=0; i<lengths[1]; i++) {
1085 ghosts[i] = gids[i];
1086 round[i] = votes[i];
1091 for (
int j=1; j<nodeComm->NumProc(); j++) {
1092 for (
int i=lengths[j]; i<lengths[j+1]; i++) {
1099 roundpid[0] = round; roundpid[1] = owningpid;
1100 Epetra_Util epetraUtil;
1101 epetraUtil.Sort(
true,total,ghosts,0,0,2,roundpid);
1104 int *nlosers =
new int[nodeComm->NumProc()];
1105 int** losers =
new int*[nodeComm->NumProc()];
1106 for (
int i=0; i<nodeComm->NumProc(); i++) {
1108 losers[i] =
new int[ lengths[i+1]-lengths[i] ];
1120 for (
int i=1; i<total; i++) {
1121 if (ghosts[i] == ghosts[i-1]) {
1123 if (round[i] > round[max]) {
1127 int j = owningpid[idx];
1128 losers[j][nlosers[j]++] = ghosts[idx];
1136 delete [] owningpid;
1139 for (
int i=1; i<nodeComm->NumProc(); i++) {
1140 MPI_Send( nlosers+i, 1, MPI_INT, i, 8675, nodeComm->Comm());
1141 MPI_Send( losers[i], nlosers[i], MPI_INT, i, 8675, nodeComm->Comm());
1148 cullList =
new int[ncull+1];
1149 for (
int i=0; i<nlosers[0]; i++)
1150 cullList[i] = losers[0][i];
1152 for (
int i=0; i<nodeComm->NumProc(); i++)
1153 delete [] losers[i];
1162 int hashsize = ghostTable.size();
1163 MPI_Send( &hashsize, 1, MPI_INT, 0, 8675, nodeComm->Comm());
1164 MPI_Send( gids, hashsize, MPI_INT, 0, 8675, nodeComm->Comm());
1165 MPI_Send( votes, hashsize, MPI_INT, 0, 8675, nodeComm->Comm());
1169 MPI_Recv( &ncull, 1, MPI_INT, 0, 8675, nodeComm->Comm(), &status);
1170 cullList =
new int[ncull+1];
1171 MPI_Recv( cullList, ncull, MPI_INT, 0, 8675, nodeComm->Comm(), &status);
1178 for (
int i=0; i<ncull; i++) {
1179 try{ghostTable.remove(cullList[i]);}
1182 printf(
"pid %d: In OverlappingRowMatrix ctr, problem removing ghost elt %d from ghostTable\n",
1183 Comm().MyPID(),cullList[i]);
1192 gidsarray.clear(); votesarray.clear();
1193 ghostTable.arrayify(gidsarray,votesarray);
1195 vector<int> list(size);
1197 for (
int i=0; i<ghostTable.size(); i++) {
1199 if (votesarray[i] < votesMax) {
1200 list[count] = gidsarray[i];
1201 ghostTable.put(gidsarray[i],votesMax);
1207 #ifdef IFPACK_OVA_TIME_BUILD
1209 fprintf(stderr,
"[node %d]: overlap duplicate removal %2.3e\n", nodeID, t1-t0);
1214 # endif //ifdef HAVE_MPI
1216 TmpMap = rcp(
new Epetra_Map(-1,count, &list[0],0,
Comm()) );
1218 TmpMatrix = rcp(
new Epetra_CrsMatrix(Copy,*TmpMap,0) );
1220 TmpImporter = rcp(
new Epetra_Import(*TmpMap,A().RowMatrixRowMap()) );
1222 TmpMatrix->Import(A(),*TmpImporter,Insert);
1223 TmpMatrix->FillComplete(A().OperatorDomainMap(),*TmpMap);
1226 #ifdef IFPACK_OVA_TIME_BUILD
1228 fprintf(stderr,
"[node %d]: overlap TmpMatrix fillcomplete %2.3e\n", nodeID, t1-t0);
1239 Epetra_IntVector ov_colIdList( TmpMatrix->ColMap() );
1240 ov_colIdList.PutValue(-1);
1241 Epetra_IntVector ov_rowIdList( TmpMatrix->RowMap() );
1242 ov_rowIdList.PutValue(nodeID);
1243 Teuchos::RCP<Epetra_Import> ov_nodeIdImporter = rcp(
new Epetra_Import( TmpMatrix->ColMap(), TmpMatrix->RowMap()));
1244 ov_colIdList.Import(ov_rowIdList,*ov_nodeIdImporter,Insert);
1246 for (
int i=0 ; i<ov_colIdList.MyLength(); i++) {
1247 if (ov_colIdList[i] == nodeID) {
1248 int GID = (ov_colIdList.Map()).GID(i);
1249 colMapTable.put(GID,1);
1256 ov_colIdList.PutValue(-1);
1257 Epetra_IntVector ArowIdList( A().RowMatrixRowMap() );
1258 ArowIdList.PutValue(nodeID);
1259 nodeIdImporter = rcp(
new Epetra_Import( TmpMatrix->ColMap(), A().RowMatrixRowMap() ));
1260 ov_colIdList.Import(ArowIdList,*nodeIdImporter,Insert);
1262 for (
int i=0 ; i<ov_colIdList.MyLength(); i++) {
1263 if (ov_colIdList[i] == nodeID) {
1264 int GID = (ov_colIdList.Map()).GID(i);
1265 colMapTable.put(GID,1);
1270 #ifdef IFPACK_OVA_TIME_BUILD
1272 fprintf(stderr,
"[node %d]: overlap 2 imports to fix up colmap %2.3e\n", nodeID, t1-t0);
1284 vector<int> ghostElements;
1286 Teuchos::Array<int> gidsarray,votesarray;
1287 ghostTable.arrayify(gidsarray,votesarray);
1288 for (
int i=0; i<ghostTable.size(); i++) {
1289 ghostElements.push_back(gidsarray[i]);
1292 for (
int i = 0 ; i < A().RowMatrixColMap().NumMyElements() ; ++i) {
1293 int GID = A().RowMatrixColMap().GID(i);
1295 if (colMapTable.containsKey(GID)) {
1296 try{colMapTable.remove(GID);}
1298 printf(
"pid %d: In OverlappingRowMatrix ctr, problem removing entry %d from colMapTable\n",
Comm().MyPID(),GID);
1305 vector<int> colMapElements;
1307 gidsarray.clear(); votesarray.clear();
1308 colMapTable.arrayify(gidsarray,votesarray);
1309 for (
int i=0; i<colMapTable.size(); i++)
1310 colMapElements.push_back(gidsarray[i]);
1323 vector<int> rowList(NumMyRowsA_ + ghostElements.size());
1324 for (
int i = 0 ; i < NumMyRowsA_ ; ++i)
1325 rowList[i] = A().RowMatrixRowMap().GID(i);
1326 for (
int i = 0 ; i < (int)ghostElements.size() ; ++i)
1327 rowList[i + NumMyRowsA_] = ghostElements[i];
1330 Map_ = rcp(
new Epetra_Map(-1, NumMyRowsA_ + ghostElements.size(), &rowList[0], 0,
Comm()) );
1338 vector<int> colList(A().RowMatrixColMap().NumMyElements() + colMapElements.size());
1339 int nc = A().RowMatrixColMap().NumMyElements();
1340 for (
int i = 0 ; i < nc; i++)
1341 colList[i] = A().RowMatrixColMap().GID(i);
1342 for (
int i = 0 ; i < (int)colMapElements.size() ; i++)
1343 colList[nc+i] = colMapElements[i];
1347 colMap_ =
new Epetra_Map(-1, A().RowMatrixColMap().NumMyElements() + colMapElements.size(), &colList[0], 0,
Comm());
1351 #ifdef IFPACK_OVA_TIME_BUILD
1353 fprintf(stderr,
"[node %d]: time to init B() col/row maps %2.3e\n", nodeID, t1-t0);
1365 Epetra_Map* nodeMap =
new Epetra_Map(-1,NumMyRowsA_ + ghostElements.size(),&rowList[0],0,*nodeComm);
1366 int numMyElts = colMap_->NumMyElements();
1367 assert(numMyElts!=0);
1373 int* myGlobalElts =
new int[numMyElts];
1374 colMap_->MyGlobalElements(myGlobalElts);
1375 int* pidList =
new int[numMyElts];
1376 nodeMap->RemoteIDList(numMyElts, myGlobalElts, pidList, 0);
1381 tt[0] = myGlobalElts;
1382 Util.Sort(
true, numMyElts, pidList, 0, (
double**)0, 1, tt);
1387 while (localStart<numMyElts) {
1388 int currPID = (pidList)[localStart];
1390 while (i<numMyElts && (pidList)[i] == currPID) i++;
1391 if (currPID != nodeComm->MyPID())
1392 Util.Sort(
true, i-localStart, (myGlobalElts)+localStart, 0, 0, 0, 0);
1398 while (localStart<numMyElts && (pidList)[localStart] != nodeComm->MyPID()) localStart++;
1399 assert(localStart != numMyElts);
1400 int localEnd=localStart;
1401 while (localEnd<numMyElts && (pidList)[localEnd] == nodeComm->MyPID()) localEnd++;
1402 int* mySortedGlobalElts =
new int[numMyElts];
1403 int leng = localEnd - localStart;
1407 int *rowGlobalElts = nodeMap->MyGlobalElements();
1427 for (
int i=0; i<leng; i++) {
1429 (mySortedGlobalElts)[i] = rowGlobalElts[i];
1433 for (
int i=leng; i< localEnd; i++) {
1434 (mySortedGlobalElts)[i] = (myGlobalElts)[i-leng];
1436 for (
int i=localEnd; i<numMyElts; i++) {
1437 (mySortedGlobalElts)[i] = (myGlobalElts)[i];
1441 #ifdef IFPACK_OVA_TIME_BUILD
1443 fprintf(stderr,
"[node %d]: time to sort col map arrays (cp=1) %2.3e\n", nodeID, t1-t0);
1448 int indexBase = colMap_->IndexBase();
1449 if (colMap_)
delete colMap_;
1450 colMap_ =
new Epetra_Map(-1,numMyElts,mySortedGlobalElts,indexBase,
Comm());
1453 delete [] myGlobalElts;
1455 delete [] mySortedGlobalElts;
1459 printf(
"** * Ifpack_OverlappingRowmatrix ctor: problem creating column map * **\n\n");
1467 #ifdef IFPACK_OVA_TIME_BUILD
1469 fprintf(stderr,
"[node %d]: time to sort col map arrays (cp=2) %2.3e\n", nodeID, t1-t0);
1499 ExtMap_ = rcp(
new Epetra_Map(-1,ghostElements.size(), &ghostElements[0],0,
Comm()) );
1500 ExtMatrix_ = rcp(
new Epetra_CrsMatrix(Copy,*ExtMap_,*colMap_,0) );
1502 ExtImporter_ = rcp(
new Epetra_Import(*ExtMap_,A().RowMatrixRowMap()) );
1503 ExtMatrix_->Import(A(),*ExtImporter_,Insert);
1506 #ifdef IFPACK_OVA_TIME_BUILD
1508 fprintf(stderr,
"[node %d]: time to import and setup ExtMap_ %2.3e\n", nodeID, t1-t0);
1521 ExtMatrix_->FillComplete( *colMap_ , *Map_ );
1524 #ifdef IFPACK_OVA_TIME_BUILD
1526 fprintf(stderr,
"[node %d]: time to FillComplete B() %2.3e\n", nodeID, t1-t0);
1534 Importer_ = rcp(
new Epetra_Import(*Map_,A().RowMatrixRowMap()) );
1537 NumMyRowsB_ = B().NumMyRows();
1538 NumMyRows_ = NumMyRowsA_ + NumMyRowsB_;
1541 NumMyCols_ = B().NumMyCols();
1545 NumMyDiagonals_ = A().NumMyDiagonals() + B().NumMyDiagonals();
1547 NumMyNonzeros_ = A().NumMyNonzeros() + B().NumMyNonzeros();
1548 Comm().SumAll(&NumMyNonzeros_,&NumGlobalNonzeros_,1);
1549 MaxNumEntries_ = A().MaxNumEntries();
1552 MaxNumEntries_ = B().MaxNumEntries();
1559 #ifdef IFPACK_OVA_TIME_BUILD
1561 fprintf(stderr,
"[node %d]: time for final calcs %2.3e\n", nodeID, t1-t0);
1562 fprintf(stderr,
"[node %d]: total IORM ctor time %2.3e\n", nodeID, t1-true_t0);
1570 Ifpack_OverlappingRowMatrix::~Ifpack_OverlappingRowMatrix() {
1574 # endif //ifdef IFPACK_NODE_AWARE_CODE
1575 #endif // ifdef IFPACK_SUBCOMM_CODE
1582 if (MyRow < NumMyRowsA_)
1588 #ifdef IFPACK_SUBCOMM_CODE
1592 int * Indices)
const
1596 const Epetra_Map *Themap;
1597 if (LocRow < NumMyRowsA_) {
1598 ierr = A().ExtractMyRowCopy(LocRow,Length,NumEntries,Values,Indices);
1599 Themap=&A().RowMatrixColMap();
1602 ierr = B().ExtractMyRowCopy(LocRow-NumMyRowsA_,Length,NumEntries,Values,Indices);
1603 Themap=&B().RowMatrixColMap();
1606 IFPACK_RETURN(ierr);
1610 int Ifpack_OverlappingRowMatrix::
1611 ExtractGlobalRowCopy(
int GlobRow,
int Length,
int & NumEntries,
double *Values,
1612 int * Indices)
const
1615 const Epetra_Map *Themap;
1616 int LocRow = A().RowMatrixRowMap().LID(GlobRow);
1617 if (LocRow < NumMyRowsA_ && LocRow != -1) {
1618 ierr = A().ExtractMyRowCopy(LocRow,Length,NumEntries,Values,Indices);
1619 Themap=&A().RowMatrixColMap();
1622 LocRow = B().RowMatrixRowMap().LID(GlobRow);
1625 ierr = B().ExtractMyRowCopy(LocRow,Length,NumEntries,Values,Indices);
1626 Themap=&B().RowMatrixColMap();
1629 for (
int i=0; i<NumEntries; i++) {
1630 Indices[i]=Themap->GID(Indices[i]);
1631 assert(Indices[i] != -1);
1634 IFPACK_RETURN(ierr);
1637 # ifdef IFPACK_NODE_AWARE_CODE
1641 int * Indices)
const
1645 const Epetra_Map *Themap;
1646 if (LocRow < NumMyRowsA_) {
1647 ierr = A().ExtractMyRowCopy(LocRow,Length,NumEntries,Values,Indices);
1648 Themap=&A().RowMatrixColMap();
1651 ierr = B().ExtractMyRowCopy(LocRow-NumMyRowsA_,Length,NumEntries,Values,Indices);
1652 Themap=&B().RowMatrixColMap();
1655 IFPACK_RETURN(ierr);
1659 int Ifpack_OverlappingRowMatrix::
1660 ExtractGlobalRowCopy(
int GlobRow,
int Length,
int & NumEntries,
double *Values,
1661 int * Indices)
const
1664 const Epetra_Map *Themap;
1665 int LocRow = A().RowMatrixRowMap().LID(GlobRow);
1666 if (LocRow < NumMyRowsA_ && LocRow != -1) {
1667 ierr = A().ExtractMyRowCopy(LocRow,Length,NumEntries,Values,Indices);
1668 Themap=&A().RowMatrixColMap();
1671 LocRow = B().RowMatrixRowMap().LID(GlobRow);
1674 ierr = B().ExtractMyRowCopy(LocRow,Length,NumEntries,Values,Indices);
1675 Themap=&B().RowMatrixColMap();
1678 for (
int i=0; i<NumEntries; i++) {
1679 Indices[i]=Themap->GID(Indices[i]);
1680 assert(Indices[i] != -1);
1683 IFPACK_RETURN(ierr);
1690 int * Indices)
const
1693 if (MyRow < NumMyRowsA_)
1694 ierr = A().ExtractMyRowCopy(MyRow,Length,NumEntries,Values,Indices);
1696 ierr = B().ExtractMyRowCopy(MyRow - NumMyRowsA_,Length,NumEntries,
1699 IFPACK_RETURN(ierr);
1701 # endif // ifdef IFPACK_NODE_AWARE_CODE
1702 #endif // ifdef IFPACK_SUBCOMM_CODE
1714 Multiply(
bool TransA,
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const
1716 int NumVectors = X.NumVectors();
1717 vector<int> Ind(MaxNumEntries_);
1718 vector<double> Val(MaxNumEntries_);
1723 for (
int i = 0 ; i < NumMyRowsA_ ; ++i) {
1724 for (
int k = 0 ; k < NumVectors ; ++k) {
1728 for (
int j = 0 ; j < Nnz ; ++j) {
1729 Y[k][i] += Val[j] * X[k][Ind[j]];
1735 for (
int i = 0 ; i < NumMyRowsB_ ; ++i) {
1736 for (
int k = 0 ; k < NumVectors ; ++k) {
1740 for (
int j = 0 ; j < Nnz ; ++j) {
1741 Y[k][i + NumMyRowsA_] += Val[j] * X[k][Ind[j]];
1749 int Ifpack_OverlappingRowMatrix::
1750 Apply(
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const
1757 int Ifpack_OverlappingRowMatrix::
1758 ApplyInverse(
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const
1764 #ifndef IFPACK_SUBCOMM_CODE
1765 # ifndef IFPACK_NODE_AWARE_CODE
1766 Epetra_RowMatrix& Ifpack_OverlappingRowMatrix::B()
const
1768 return(*ExtMatrix_);
1773 const Epetra_BlockMap& Ifpack_OverlappingRowMatrix::Map()
const
1779 int Ifpack_OverlappingRowMatrix::
1780 ImportMultiVector(
const Epetra_MultiVector& X, Epetra_MultiVector& OvX,
1781 Epetra_CombineMode CM)
1783 OvX.Import(X,*Importer_,CM);
1788 int Ifpack_OverlappingRowMatrix::
1789 ExportMultiVector(
const Epetra_MultiVector& OvX, Epetra_MultiVector& X,
1790 Epetra_CombineMode CM)
1792 X.Export(OvX,*Importer_,CM);
virtual int NumMyRowEntries(int MyRow, int &NumEntries) const
Returns the number of nonzero entries in MyRow.
int MaxNumEntries() const
Returns the max number of local entries in a row.
virtual int ExtractDiagonalCopy(Epetra_Vector &Diagonal) const
Returns a copy of the main diagonal in a user-provided vector.
virtual int ExtractMyRowCopy(int MyRow, int Length, int &NumEntries, double *Values, int *Indices) const
Returns a copy of the specified local row in user-provided arrays.
virtual int Multiply(bool TransA, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_RowMatrix multiplied by a Epetra_MultiVector X in Y.
const Epetra_Comm & Comm() const
Returns the communicator object of Graph.
bool UseTranspose() const
Returns the current UseTranspose setting.