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 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; }