Debian Codegraph @

packages/trilinoscouplings/src/epetraext/EpetraExt_AmesosAMDGlobal_CrsGraph.cpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Trilinos: An Object-Oriented Solver Framework
4 //
5 // Copyright 2001-2024 NTESS and the Trilinos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #include <EpetraExt_AmesosAMDGlobal_CrsGraph.h>
11
12 #include <Epetra_Import.h>
13 #include <Epetra_CrsGraph.h>
14 #include <Epetra_Map.h>
15
16 #include <trilinos_btf_decl.h>
17 #include <trilinos_amd.h>
18
19 using std::vector;
20
21 namespace EpetraExt {
22
23 AmesosAMDGlobal_CrsGraph::
24 ~AmesosAMDGlobal_CrsGraph()
25 {
26 }
27
28 AmesosAMDGlobal_CrsGraph::NewTypeRef
29 AmesosAMDGlobal_CrsGraph::
30 operator()( OriginalTypeRef orig )
31 {
32 origObj_ = &orig;
33
34 if( orig.RowMap().DistributedGlobal() )
35 { std::cout << "FAIL for Global!\n"; abort(); }
36 if( orig.IndicesAreGlobal() )
37 { std::cout << "FAIL for Global Indices!\n"; abort(); }
38
39 // Extract the CCS information
40 int n = orig.NumMyRows();
41 int nnz = orig.NumMyNonzeros();
42
43 vector<int> Ap(n+1,0); // column pointers
44 vector<int> Ai(nnz); // row indices
45 int cnt;
46 for( int i = 0; i < n; ++i )
47 {
48 int * tmpP = &Ai[Ap[i]];
49 orig.ExtractMyRowCopy( i, nnz-Ap[i], cnt, tmpP );
50 Ap[i+1] = Ap[i] + cnt;
51 }
52
53 if (verbose_)
54 {
55 std::cout << "-----------------------------------------\n";
56 std::cout << "CRS Format Graph\n";
57 std::cout << "-----------------------------------------\n";
58 for( int i = 0; i < n; ++i )
59 {
60 std::cout << Ap[i] << " - " << Ap[i+1] << " : ";
61 for( int j = Ap[i]; j<Ap[i+1]; ++j )
62 std::cout << " " << Ai[j];
63 std::cout << std::endl;
64 }
65 std::cout << "-----------------------------------------\n";
66 }
67
68 // Control and information vector
69 double control[TRILINOS_AMD_CONTROL];
70 double info[TRILINOS_AMD_INFO];
71
72 // Storage for the permutation.
73 perm_.resize( n );
74
75 // Call AMD permutation.
76
77 int ret = trilinos_amd_order( n, &Ap[0], &Ai[0], &perm_[0], control, info );
78
79 if( debug_ ) {
80 std::cout << "-----------------------------------------\n";
81 std::cout << "AMD Output (ret = " << ret << ", n = " << n << ")\n";
82 std::cout << "-----------------------------------------\n";
83 std::cout << "Perm\n";
84 for( int i = 0; i<n; ++i )
85 std::cout << perm_[i] << std::endl;
86 std::cout << "-----------------------------------------\n";
87 }
88
89 //Generate New Domain and Range Maps
90 //for now, assume they start out as identical
91 const Epetra_BlockMap & OldMap = orig.RowMap();
92
93 NewRowMap_ = Teuchos::rcp( new Epetra_Map( n, n, &perm_[0], OldMap.IndexBase(), OldMap.Comm() ) );
94 NewColMap_ = NewRowMap_;
95
96 if (verbose_)
97 {
98 std::cout << "New Row Map\n";
99 std::cout << *NewRowMap_ << std::endl;
100 std::cout << "New Col Map\n";
101 std::cout << *NewColMap_ << std::endl;
102 }
103
104 //Generate New Graph
105 NewGraph_ = Teuchos::rcp( new Epetra_CrsGraph( Copy, *NewRowMap_, *NewColMap_, 0 ) );
106 Epetra_Import Importer( *NewRowMap_, OldMap );
107 NewGraph_->Import( orig, Importer, Insert );
108 NewGraph_->FillComplete();
109
110 if (verbose_)
111 {
112 std::cout << "New CrsGraph\n";
113 std::cout << *NewGraph_ << std::endl;
114 }
115
116 newObj_ = &*NewGraph_;
117
118 return *NewGraph_;
119 }
120
121 } //namespace EpetraExt