void Epetra_OffsetIndex::GenerateLocalOffsets_( const Epetra_CrsGraph & SourceGraph, const Epetra_CrsGraph & TargetGraph, const int * PermuteLIDs ) { const int GlobalMaxNumSourceIndices = SourceGraph.GlobalMaxNumIndices(); int NumSourceIndices; int_type * SourceIndices = 0; if( GlobalMaxNumSourceIndices>0 ) SourceIndices = new int_type[GlobalMaxNumSourceIndices]; //setup Same Offsets SameOffsets_ = new int*[NumSame_]; for( int i = 0; i < NumSame_; ++i ) SameOffsets_[i] = 0; for( int i = 0; i < NumSame_; ++i ) { int_type GID = (int_type) SourceGraph.GRID64(i); SourceGraph.ExtractGlobalRowCopy( GID, GlobalMaxNumSourceIndices, NumSourceIndices, SourceIndices ); if( NumSourceIndices > 0 ) SameOffsets_[i] = new int[NumSourceIndices]; int Loc = 0; int Start = 0; for( int j = 0; j < NumSourceIndices; ++j ) { Start = Loc; if( TargetGraph.FindGlobalIndexLoc(i,SourceIndices[j],Start,Loc) ) SameOffsets_[i][j] = Loc; else SameOffsets_[i][j] = -1; } } //do also for permuted ids PermuteOffsets_ = new int*[NumPermute_]; for( int i = 0; i < NumPermute_; ++i ) PermuteOffsets_[i] = 0; for( int i = 0; i < NumPermute_; ++i ) { int_type GID = (int_type) SourceGraph.GRID64(PermuteLIDs[i]); SourceGraph.ExtractGlobalRowCopy( GID, GlobalMaxNumSourceIndices, NumSourceIndices, SourceIndices ); if( NumSourceIndices > 0 ) PermuteOffsets_[i] = new int[NumSourceIndices]; int Loc = 0; int Start = 0; for( int j = 0; j < NumSourceIndices; ++j ) { Start = Loc; if( TargetGraph.FindGlobalIndexLoc(PermuteLIDs[i],SourceIndices[j],Start,Loc) ) PermuteOffsets_[i][j] = Loc; else PermuteOffsets_[i][j] = -1; } } if( GlobalMaxNumSourceIndices>0 ) delete [] SourceIndices; }
void BlockUtility::TGenerateRowStencil(const Epetra_CrsGraph& LocalBlockGraph, std::vector<int_type> RowIndices, std::vector< std::vector<int_type> >& RowStencil) { // Get row indices int NumMyRows = LocalBlockGraph.NumMyRows(); RowIndices.resize(NumMyRows); const Epetra_BlockMap& RowMap = LocalBlockGraph.RowMap(); RowMap.MyGlobalElements(&RowIndices[0]); // Get stencil RowStencil.resize(NumMyRows); if (LocalBlockGraph.IndicesAreGlobal()) { for (int i=0; i<NumMyRows; i++) { int_type Row = RowIndices[i]; int NumCols = LocalBlockGraph.NumGlobalIndices(Row); RowStencil[i].resize(NumCols); LocalBlockGraph.ExtractGlobalRowCopy(Row, NumCols, NumCols, &RowStencil[i][0]); for (int k=0; k<NumCols; k++) RowStencil[i][k] -= Row; } } else { for (int i=0; i<NumMyRows; i++) { int NumCols = LocalBlockGraph.NumMyIndices(i); std::vector<int> RowStencil_local(NumCols); RowStencil[i].resize(NumCols); LocalBlockGraph.ExtractMyRowCopy(i, NumCols, NumCols, &RowStencil_local[0]); for (int k=0; k<NumCols; k++) RowStencil[i][k] = (int_type) ((int) (LocalBlockGraph.GCID64(RowStencil_local[k]) - RowIndices[i])); } } }
//============================================================================== int check(Epetra_CrsGraph& A, int NumMyRows1, long long NumGlobalRows1, int NumMyNonzeros1, long long NumGlobalNonzeros1, long long* MyGlobalElements, bool verbose) { (void)MyGlobalElements; int ierr = 0; int i; int j; int forierr = 0; int NumGlobalIndices; int NumMyIndices; int* MyViewIndices; int MaxNumIndices = A.MaxNumIndices(); int* MyCopyIndices = new int[MaxNumIndices]; long long* GlobalCopyIndices = new long long[MaxNumIndices]; // Test query functions int NumMyRows = A.NumMyRows(); if(verbose) cout << "Number of local Rows = " << NumMyRows << endl; EPETRA_TEST_ERR(!(NumMyRows==NumMyRows1),ierr); int NumMyNonzeros = A.NumMyNonzeros(); if(verbose) cout << "Number of local Nonzero entries = " << NumMyNonzeros << endl; EPETRA_TEST_ERR(!(NumMyNonzeros==NumMyNonzeros1),ierr); long long NumGlobalRows = A.NumGlobalRows64(); if(verbose) cout << "Number of global Rows = " << NumGlobalRows << endl; EPETRA_TEST_ERR(!(NumGlobalRows==NumGlobalRows1),ierr); long long NumGlobalNonzeros = A.NumGlobalNonzeros64(); if(verbose) cout << "Number of global Nonzero entries = " << NumGlobalNonzeros << endl; EPETRA_TEST_ERR(!(NumGlobalNonzeros==NumGlobalNonzeros1),ierr); // GlobalRowView should be illegal (since we have local indices) EPETRA_TEST_ERR(!(A.ExtractGlobalRowView(A.RowMap().MaxMyGID64(), NumGlobalIndices, GlobalCopyIndices)==-2),ierr); // Other binary tests EPETRA_TEST_ERR(A.NoDiagonal(),ierr); EPETRA_TEST_ERR(!(A.Filled()),ierr); EPETRA_TEST_ERR(!(A.MyGRID(A.RowMap().MaxMyGID64())),ierr); EPETRA_TEST_ERR(!(A.MyGRID(A.RowMap().MinMyGID64())),ierr); EPETRA_TEST_ERR(A.MyGRID(1+A.RowMap().MaxMyGID64()),ierr); EPETRA_TEST_ERR(A.MyGRID(-1+A.RowMap().MinMyGID64()),ierr); EPETRA_TEST_ERR(!(A.MyLRID(0)),ierr); EPETRA_TEST_ERR(!(A.MyLRID(NumMyRows-1)),ierr); EPETRA_TEST_ERR(A.MyLRID(-1),ierr); EPETRA_TEST_ERR(A.MyLRID(NumMyRows),ierr); forierr = 0; for(i = 0; i < NumMyRows; i++) { long long Row = A.GRID64(i); A.ExtractGlobalRowCopy(Row, MaxNumIndices, NumGlobalIndices, GlobalCopyIndices); A.ExtractMyRowView(i, NumMyIndices, MyViewIndices); forierr += !(NumGlobalIndices==NumMyIndices); for(j = 1; j < NumMyIndices; j++) EPETRA_TEST_ERR(!(MyViewIndices[j-1]<MyViewIndices[j]),ierr); for(j = 0; j < NumGlobalIndices; j++) { forierr += !(GlobalCopyIndices[j]==A.GCID64(MyViewIndices[j])); forierr += !(A.LCID(GlobalCopyIndices[j])==MyViewIndices[j]); } } EPETRA_TEST_ERR(forierr,ierr); forierr = 0; for(i = 0; i < NumMyRows; i++) { long long Row = A.GRID64(i); A.ExtractGlobalRowCopy(Row, MaxNumIndices, NumGlobalIndices, GlobalCopyIndices); A.ExtractMyRowCopy(i, MaxNumIndices, NumMyIndices, MyCopyIndices); forierr += !(NumGlobalIndices==NumMyIndices); for(j = 1; j < NumMyIndices; j++) EPETRA_TEST_ERR(!(MyCopyIndices[j-1]<MyCopyIndices[j]),ierr); for(j = 0; j < NumGlobalIndices; j++) { forierr += !(GlobalCopyIndices[j]==A.GCID64(MyCopyIndices[j])); forierr += !(A.LCID(GlobalCopyIndices[j])==MyCopyIndices[j]); } } EPETRA_TEST_ERR(forierr,ierr); delete[] MyCopyIndices; delete[] GlobalCopyIndices; if(verbose) cout << "Rows sorted check OK" << endl; return(ierr); }
void Epetra_OffsetIndex::GenerateRemoteOffsets_( const Epetra_CrsGraph & SourceGraph, const Epetra_CrsGraph & TargetGraph, const int * ExportLIDs, const int * RemoteLIDs, Epetra_Distributor & Distor ) { int numProcs = SourceGraph.RowMap().Comm().NumProc(); if (numProcs < 2) { return; } const int GlobalMaxNumIndices = SourceGraph.GlobalMaxNumIndices(); int NumIndices; /* "Indices" appears to be unused -- [email protected] int * Indices = 0; if( GlobalMaxNumIndices>0 ) Indices = new int[GlobalMaxNumIndices]; */ //Pack Source Rows int * Sizes = 0; if( NumExport_ > 0 ) Sizes = new int[NumExport_]; int TotalSize = 0; for( int i = 0; i < NumExport_; ++i ) { Sizes[i] = SourceGraph.NumMyIndices(ExportLIDs[i]) + 1; TotalSize += Sizes[i]; } int_type * SourceArray = new int_type[TotalSize+1]; int Loc = 0; for( int i = 0; i < NumExport_; ++i ) { int_type GID = (int_type) SourceGraph.GRID64(ExportLIDs[i]); SourceArray[Loc] = Sizes[i]-1; SourceGraph.ExtractGlobalRowCopy( GID, GlobalMaxNumIndices, NumIndices, &(SourceArray[Loc+1]) ); Loc += Sizes[i]; } //Push to Target char * cRecvArray = 0; int_type * RecvArray = 0; int RecvArraySize = 0; Distor.Do( reinterpret_cast<char *>(SourceArray), (int)sizeof(int_type), Sizes, RecvArraySize, cRecvArray ); RecvArray = reinterpret_cast<int_type*>(cRecvArray); //Construct RemoteOffsets if( NumRemote_ > 0 ) RemoteOffsets_ = new int*[NumRemote_]; for( int i = 0; i < NumRemote_; ++i ) RemoteOffsets_[i] = 0; Loc = 0; for( int i = 0; i < NumRemote_; ++i ) { NumIndices = (int) RecvArray[Loc]; RemoteOffsets_[i] = new int[NumIndices]; ++Loc; int FLoc = 0; int Start = 0; for( int j = 0; j < NumIndices; ++j ) { Start = FLoc; if( TargetGraph.FindGlobalIndexLoc(RemoteLIDs[i],RecvArray[Loc],Start,FLoc) ) RemoteOffsets_[i][j] = FLoc; else RemoteOffsets_[i][j] = -1; ++Loc; } } /* "Indices" appears to be unused -- [email protected] if( GlobalMaxNumIndices>0 ) delete [] Indices; */ if( Sizes ) delete [] Sizes; if( SourceArray ) delete [] SourceArray; if( RecvArraySize ) delete [] cRecvArray; }