本文整理汇总了C++中Epetra_CrsGraph::ExtractMyRowView方法的典型用法代码示例。如果您正苦于以下问题:C++ Epetra_CrsGraph::ExtractMyRowView方法的具体用法?C++ Epetra_CrsGraph::ExtractMyRowView怎么用?C++ Epetra_CrsGraph::ExtractMyRowView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Epetra_CrsGraph
的用法示例。
在下文中一共展示了Epetra_CrsGraph::ExtractMyRowView方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tmpIndices
//==============================================================================
int Ifpack_CrsRiluk::BlockGraph2PointGraph(const Epetra_CrsGraph & BG, Epetra_CrsGraph & PG, bool Upper) {
if (!BG.IndicesAreLocal()) {EPETRA_CHK_ERR(-1);} // Must have done FillComplete on BG
int * ColFirstPointInElementList = BG.RowMap().FirstPointInElementList();
int * ColElementSizeList = BG.RowMap().ElementSizeList();
if (BG.Importer()!=0) {
ColFirstPointInElementList = BG.ImportMap().FirstPointInElementList();
ColElementSizeList = BG.ImportMap().ElementSizeList();
}
int Length = (BG.MaxNumIndices()+1) * BG.ImportMap().MaxMyElementSize();
vector<int> tmpIndices(Length);
int BlockRow, BlockOffset, NumEntries;
int NumBlockEntries;
int * BlockIndices;
int NumMyRows_tmp = PG.NumMyRows();
for (int i=0; i<NumMyRows_tmp; i++) {
EPETRA_CHK_ERR(BG.RowMap().FindLocalElementID(i, BlockRow, BlockOffset));
EPETRA_CHK_ERR(BG.ExtractMyRowView(BlockRow, NumBlockEntries, BlockIndices));
int * ptr = &tmpIndices[0]; // Set pointer to beginning of buffer
int RowDim = BG.RowMap().ElementSize(BlockRow);
NumEntries = 0;
// This next line make sure that the off-diagonal entries in the block diagonal of the
// original block entry matrix are included in the nonzero pattern of the point graph
if (Upper) {
int jstart = i+1;
int jstop = EPETRA_MIN(NumMyRows_tmp,i+RowDim-BlockOffset);
for (int j= jstart; j< jstop; j++) {*ptr++ = j; NumEntries++;}
}
for (int j=0; j<NumBlockEntries; j++) {
int ColDim = ColElementSizeList[BlockIndices[j]];
NumEntries += ColDim;
assert(NumEntries<=Length); // Sanity test
int Index = ColFirstPointInElementList[BlockIndices[j]];
for (int k=0; k < ColDim; k++) *ptr++ = Index++;
}
// This next line make sure that the off-diagonal entries in the block diagonal of the
// original block entry matrix are included in the nonzero pattern of the point graph
if (!Upper) {
int jstart = EPETRA_MAX(0,i-RowDim+1);
int jstop = i;
for (int j = jstart; j < jstop; j++) {*ptr++ = j; NumEntries++;}
}
EPETRA_CHK_ERR(PG.InsertMyIndices(i, NumEntries, &tmpIndices[0]));
}
SetAllocated(true);
return(0);
}
示例2:
//EpetraCrsMatrix_To_TpetraCrsMatrix: copies Epetra_CrsMatrix to its analogous Tpetra_CrsMatrix
Teuchos::RCP<Tpetra_CrsMatrix> Petra::EpetraCrsMatrix_To_TpetraCrsMatrix(const Epetra_CrsMatrix& epetraCrsMatrix_,
const Teuchos::RCP<const Teuchos::Comm<int> >& commT_)
{
//get row map of Epetra::CrsMatrix & convert to Tpetra::Map
auto tpetraRowMap_ = EpetraMap_To_TpetraMap(epetraCrsMatrix_.RowMap(), commT_);
//get col map of Epetra::CrsMatrix & convert to Tpetra::Map
auto tpetraColMap_ = EpetraMap_To_TpetraMap(epetraCrsMatrix_.ColMap(), commT_);
//get CrsGraph of Epetra::CrsMatrix & convert to Tpetra::CrsGraph
const Epetra_CrsGraph epetraCrsGraph_ = epetraCrsMatrix_.Graph();
std::size_t maxEntries = epetraCrsGraph_.GlobalMaxNumIndices();
Teuchos::RCP<Tpetra_CrsGraph> tpetraCrsGraph_ = Teuchos::rcp(new Tpetra_CrsGraph(tpetraRowMap_, tpetraColMap_, maxEntries));
for (LO i=0; i<epetraCrsGraph_.NumMyRows(); i++) {
LO NumEntries; LO *Indices;
epetraCrsGraph_.ExtractMyRowView(i, NumEntries, Indices);
tpetraCrsGraph_->insertLocalIndices(i, NumEntries, Indices);
}
tpetraCrsGraph_->fillComplete();
//convert Epetra::CrsMatrix to Tpetra::CrsMatrix, after creating Tpetra::CrsMatrix based on above Tpetra::CrsGraph
Teuchos::RCP<Tpetra_CrsMatrix> tpetraCrsMatrix_ = Teuchos::rcp(new Tpetra_CrsMatrix(tpetraCrsGraph_));
tpetraCrsMatrix_->setAllToScalar(0.0);
for (LO i=0; i<epetraCrsMatrix_.NumMyRows(); i++) {
LO NumEntries; LO *Indices; ST *Values;
epetraCrsMatrix_.ExtractMyRowView(i, NumEntries, Values, Indices);
tpetraCrsMatrix_->replaceLocalValues(i, NumEntries, Values, Indices);
}
tpetraCrsMatrix_->fillComplete();
return tpetraCrsMatrix_;
}
示例3: setupAcceleratedMatrixIndexing
//-----------------------------------------------------------------------------
// Function : Indexor::setupAcceleratedMatrixIndexing
// Purpose :
// Special Notes :
// Scope : public
// Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
// Creation Date : 08/23/02
//-----------------------------------------------------------------------------
bool Indexor::setupAcceleratedMatrixIndexing( const std::string & graph_name )
{
Epetra_CrsGraph * graph = 0;
assert( pdsMgr_ != 0 );
// Never, EVER do work inside an assert argument, or that work will not
// be done when asserts are disabled.
graph = pdsMgr_->getMatrixGraph( graph_name );
assert( graph != 0 );
int NumRows = graph->NumMyRows();
matrixIndexMap_.clear();
matrixIndexMap_.resize( NumRows );
int NumElements;
int * Elements;
for( int i = 0; i < NumRows; ++i )
{
graph->ExtractMyRowView( i, NumElements, Elements );
for( int j = 0; j < NumElements; ++j ) matrixIndexMap_[i][ Elements[j] ] = j;
}
accelMatrixIndex_ = true;
return true;
}
示例4: matrixGlobalToLocal
//-----------------------------------------------------------------------------
// Function : Indexor::matrixGlobalToLocal
// Purpose :
// Special Notes :
// Scope : public
// Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
// Creation Date : 08/23/02
//-----------------------------------------------------------------------------
bool Indexor::matrixGlobalToLocal( const std::string & graph_name,
const std::vector<int> & gids,
std::vector< std::vector<int> > & stamp )
{
Epetra_CrsGraph * graph = 0;
assert( pdsMgr_ != 0 );
// Never, EVER do work inside an assert argument, or that work will not
// be done when asserts are disabled.
graph = pdsMgr_->getMatrixGraph( graph_name );
assert( graph != 0 );
int numRows = stamp.size();
int numElements;
int * elements;
if( accelMatrixIndex_ )
{
for( int i = 0; i < numRows; ++i )
{
int RowLID = graph->LRID(gids[i]);
int NumCols = stamp[i].size();
for( int j = 0; j < NumCols; ++j )
{
int lid = graph->LCID(stamp[i][j]);
stamp[i][j] = matrixIndexMap_[RowLID][lid];
}
}
}
else
{
for( int i = 0; i < numRows; ++i )
{
graph->ExtractMyRowView( graph->LRID(gids[i]), numElements, elements );
std::map<int,int> indexToOffsetMap;
for( int j = 0; j < numElements; ++j ) indexToOffsetMap[ elements[j] ] = j;
int numCols = stamp[i].size();
for( int j = 0; j < numCols; ++j )
{
int lid = graph->LCID(stamp[i][j]);
// assert( indexToOffsetMap.count(lid) );
stamp[i][j] = indexToOffsetMap[lid];
}
}
}
return true;
}
示例5: abort
Teuchos::RCP<Epetra_CrsGraph> BlockAdjacencyGraph::compute( Epetra_CrsGraph& B, int nbrr, std::vector<int>&r, std::vector<double>& weights, bool verbose)
{
// Check if the graph is on one processor.
int myMatProc = -1, matProc = -1;
int myPID = B.Comm().MyPID();
for (int proc=0; proc<B.Comm().NumProc(); proc++)
{
if (B.NumGlobalEntries() == B.NumMyEntries())
myMatProc = myPID;
}
B.Comm().MaxAll( &myMatProc, &matProc, 1 );
if( matProc == -1)
{ cout << "FAIL for Global! All CrsGraph entries must be on one processor!\n"; abort(); }
int i= 0, j = 0, k, l = 0, p, pm, q = -1, ns;
int tree_height;
int error = -1; /* error detected, possibly a problem with the input */
int nrr; /* number of rows in B */
int nzM = 0; /* number of edges in graph */
int m = 0; /* maximum number of nonzeros in any block row of B */
int* colstack = 0; /* stack used to process each block row */
int* bstree = 0; /* binary search tree */
std::vector<int> Mi, Mj, Mnum(nbrr+1,0);
nrr = B.NumMyRows();
if ( matProc == myPID && verbose )
std::printf(" Matrix Size = %d Number of Blocks = %d\n",nrr, nbrr);
else
nrr = -1; /* Prevent processor from doing any computations */
bstree = csr_bst(nbrr); /* 0 : nbrr-1 */
tree_height = ceil31log2(nbrr) + 1;
error = -1;
l = 0; j = 0; m = 0;
for( i = 0; i < nrr; i++ ){
if( i >= r[l+1] ){
++l; /* new block row */
m = EPETRA_MAX(m,j) ; /* nonzeros in block row */
j = B.NumGlobalIndices(i);
}else{
j += B.NumGlobalIndices(i);
}
}
/* one more time for the final block */
m = EPETRA_MAX(m,j) ; /* nonzeros in block row */
colstack = (int*) malloc( EPETRA_MAX(m,1) * sizeof(int) );
// The compressed graph is actually computed twice,
// due to concerns about memory limitations. First,
// without memory allocation, just nzM is computed.
// Next Mj is allocated. Then, the second time, the
// arrays are actually populated.
nzM = 0; q = -1; l = 0;
int * indices;
int numEntries;
for( i = 0; i <= nrr; i++ ){
if( i >= r[l+1] ){
if( q > 0 ) std::qsort(colstack,q+1,sizeof(int),compare_ints); /* sort stack */
if( q >= 0 ) ns = 1; /* l, colstack[0] M */
for( j=1; j<=q ; j++ ){ /* delete copies */
if( colstack[j] > colstack[j-1] ) ++ns;
}
nzM += ns; /*M->p[l+1] = M->p[l] + ns;*/
++l;
q = -1;
}
if( i < nrr ){
B.ExtractMyRowView( i, numEntries, indices );
for( k = 0; k < numEntries; k++){
j = indices[k]; ns = 0; p = 0;
while( (r[bstree[p]] > j) || (j >= r[bstree[p]+1]) ){
if( r[bstree[p]] > j){
p = 2*p+1;
}else{
if( r[bstree[p]+1] <= j) p = 2*p+2;
}
++ns;
if( p > nbrr || ns > tree_height ) {
error = j;
std::printf("error: p %d nbrr %d ns %d %d\n",p,nbrr,ns,j); break;
}
}
colstack[++q] = bstree[p];
}
//if( error >-1 ){ std::printf("%d\n",error); break; }
// p > nbrr is a fatal error that is ignored
}
}
if ( matProc == myPID && verbose )
std::printf("nzM = %d \n", nzM );
Mi.resize( nzM );
Mj.resize( nzM );
q = -1; l = 0; pm = -1;
for( i = 0; i <= nrr; i++ ){
if( i >= r[l+1] ){
if( q > 0 ) std::qsort(colstack,q+1,sizeof(colstack[0]),compare_ints); /* sort stack */
if( q >= 0 ){
Mi[++pm] = l;
Mj[pm] = colstack[0];
//.........这里部分代码省略.........
示例6: check
int check(Epetra_CrsGraph& L, Epetra_CrsGraph& U, Ifpack_IlukGraph& LU,
int NumGlobalRows1, int NumMyRows1, int LevelFill1, bool verbose) {
using std::cout;
using std::endl;
int i, j;
int NumIndices, * Indices;
int NumIndices1, * Indices1;
bool debug = true;
Epetra_CrsGraph& L1 = LU.L_Graph();
Epetra_CrsGraph& U1 = LU.U_Graph();
// Test entries and count nonzeros
int Nout = 0;
for (i=0; i<LU.NumMyRows(); i++) {
assert(L.ExtractMyRowView(i, NumIndices, Indices)==0);
assert(L1.ExtractMyRowView(i, NumIndices1, Indices1)==0);
assert(NumIndices==NumIndices1);
for (j=0; j<NumIndices1; j++) {
if (debug &&(Indices[j]!=Indices1[j])) {
int MyPID = L.RowMap().Comm().MyPID();
cout << "Proc " << MyPID
<< " Local Row = " << i
<< " L.Indices["<< j <<"] = " << Indices[j]
<< " L1.Indices["<< j <<"] = " << Indices1[j] << endl;
}
assert(Indices[j]==Indices1[j]);
}
Nout += (NumIndices-NumIndices1);
assert(U.ExtractMyRowView(i, NumIndices, Indices)==0);
assert(U1.ExtractMyRowView(i, NumIndices1, Indices1)==0);
assert(NumIndices==NumIndices1);
for (j=0; j<NumIndices1; j++) {
if (debug &&(Indices[j]!=Indices1[j])) {
int MyPID = L.RowMap().Comm().MyPID();
cout << "Proc " << MyPID
<< " Local Row = " << i
<< " U.Indices["<< j <<"] = " << Indices[j]
<< " U1.Indices["<< j <<"] = " << Indices1[j] << endl;
}
assert(Indices[j]==Indices1[j]);
}
Nout += (NumIndices-NumIndices1);
}
// Test query functions
int NumGlobalRows = LU.NumGlobalRows();
if (verbose) cout << "\n\nNumber of Global Rows = " << NumGlobalRows << endl<< endl;
assert(NumGlobalRows==NumGlobalRows1);
int NumGlobalNonzeros = LU.NumGlobalNonzeros();
if (verbose) cout << "\n\nNumber of Global Nonzero entries = "
<< NumGlobalNonzeros << endl<< endl;
int NoutG = 0;
L.RowMap().Comm().SumAll(&Nout, &NoutG, 1);
assert(NumGlobalNonzeros==L.NumGlobalNonzeros()+U.NumGlobalNonzeros()-NoutG);
int NumMyRows = LU.NumMyRows();
if (verbose) cout << "\n\nNumber of Rows = " << NumMyRows << endl<< endl;
assert(NumMyRows==NumMyRows1);
int NumMyNonzeros = LU.NumMyNonzeros();
if (verbose) cout << "\n\nNumber of Nonzero entries = " << NumMyNonzeros << endl<< endl;
assert(NumMyNonzeros==L.NumMyNonzeros()+U.NumMyNonzeros()-Nout);
if (verbose) cout << "\n\nLU check OK" << endl<< endl;
return(0);
}
示例7: show_matrix
void show_matrix(const char *txt, const Epetra_CrsGraph &graph, const Epetra_Comm &comm)
{
int me = comm.MyPID();
if (comm.NumProc() > 10){
if (me == 0){
std::cerr << txt << std::endl;
std::cerr << "Printed matrix format only works for 10 or fewer processes" << std::endl;
}
return;
}
const Epetra_BlockMap &rowmap = graph.RowMap();
const Epetra_BlockMap &colmap = graph.ColMap();
int myRows = rowmap.NumMyElements();
int numRows = graph.NumGlobalRows();
int numCols = graph.NumGlobalCols();
int base = rowmap.IndexBase();
if ((numRows > 200) || (numCols > 500)){
if (me == 0){
std::cerr << txt << std::endl;
std::cerr << "show_matrix: problem is too large to display" << std::endl;
}
return;
}
int *myA = new int [numRows * numCols];
memset(myA, 0, sizeof(int) * numRows * numCols);
int *myIndices;
int *myRowGIDs = rowmap.MyGlobalElements();
for (int i=0; i< myRows; i++){
int myRowLID = rowmap.LID(myRowGIDs[i]);
int numEntries = graph.NumMyIndices(myRowLID);
if (numEntries > 0){
int rc = graph.ExtractMyRowView(myRowLID, numEntries, myIndices);
if (rc){
std::cerr << txt << std::endl;
std::cerr << "extract graph error" << std::endl;
return;
}
int *row = myA + (numCols * (myRowGIDs[i] - base));
for (int j=0; j < numEntries; j++){
int gid = colmap.GID(myIndices[j]);
row[gid-base] = me+1;
}
}
}
printMatrix(txt, myA, NULL, NULL, numRows, numCols, comm);
delete [] myA;
}
示例8: check
//==============================================================================
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);
}
示例9: TotalTime
//.........这里部分代码省略.........
std::vector< std::vector<int> > NodesOfAggregate(NumAggregates);
for (int i = 0; i < Graph.NumMyBlockRows(); ++i)
{
int AID = BlockAggr_ML->aggr_info[0][i];
NodesOfAggregate[AID].push_back(i);
}
int MaxAggrSize = 0;
for (int i = 0; i < NumAggregates; ++i)
{
const int& MySize = NodesOfAggregate[i].size();
if (MySize > MaxAggrSize) MaxAggrSize = MySize;
}
// collect aggregate information, and mark all nodes that are
// connected with each aggregate. These nodes will have a possible
// nonzero entry after the matrix-matrix product between the Operator_
// and the tentative prolongator.
std::vector<vector<int> > aggregates(NumAggregates);
std::vector<int>::iterator iter;
for (int i = 0; i < NumAggregates; ++i)
aggregates[i].reserve(MaxAggrSize);
for (int i = 0; i < Graph.NumMyBlockRows(); ++i)
{
int AID = BlockAggr_ML->aggr_info[0][i];
int NumEntries;
int* Indices;
Graph.ExtractMyRowView(i, NumEntries, Indices);
for (int k = 0; k < NumEntries; ++k)
{
// FIXME: use hash??
const int& GCID = Graph.ColMap().GID(Indices[k]);
iter = find(aggregates[AID].begin(), aggregates[AID].end(), GCID);
if (iter == aggregates[AID].end())
aggregates[AID].push_back(GCID);
}
}
int* BlockNodeList = Graph.ColMap().MyGlobalElements();
// finally get rid of the ML_Aggregate structure.
ML_Aggregate_Destroy(&BlockAggr_ML);
const Epetra_Map& FineMap = Operator_.OperatorDomainMap();
Epetra_Map CoarseMap(-1, NumAggregates * NullSpaceDim, 0, Comm());
RefCountPtr<Epetra_Map> BlockNodeListMap =
rcp(new Epetra_Map(-1, Graph.ColMap().NumMyElements(),
BlockNodeList, 0, Comm()));
std::vector<int> NodeList(Graph.ColMap().NumMyElements() * NumPDEEqns_);
for (int i = 0; i < Graph.ColMap().NumMyElements(); ++i)
for (int m = 0; m < NumPDEEqns_; ++m)
NodeList[i * NumPDEEqns_ + m] = BlockNodeList[i] * NumPDEEqns_ + m;
RefCountPtr<Epetra_Map> NodeListMap =
rcp(new Epetra_Map(-1, NodeList.size(), &NodeList[0], 0, Comm()));
AddAndResetStartTime("data structures", true);