| 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 |
// CrsGraph_BTF Test routine |
| 11 |
|
| 12 |
#include <EpetraExt_ConfigDefs.h> |
| 13 |
#include "EpetraExt_Version.h" |
| 14 |
|
| 15 |
#include "Epetra_Time.h" |
| 16 |
#ifdef EPETRA_MPI |
| 17 |
#include "Epetra_MpiComm.h" |
| 18 |
#include <mpi.h> |
| 19 |
#endif |
| 20 |
|
| 21 |
#include "Epetra_SerialComm.h" |
| 22 |
#include "Epetra_Map.h" |
| 23 |
#include "Epetra_CrsGraph.h" |
| 24 |
#include "Epetra_CrsMatrix.h" |
| 25 |
#include "Epetra_MultiVector.h" |
| 26 |
#include "EpetraExt_AmesosBTF_CrsMatrix.h" |
| 27 |
|
| 28 |
int main(int argc, char *argv[]) { |
| 29 |
|
| 30 |
int returnierr=0; |
| 31 |
|
| 32 |
using std::cout; |
| 33 |
using std::endl; |
| 34 |
using std::flush; |
| 35 |
|
| 36 |
#ifdef EPETRA_MPI |
| 37 |
|
| 38 |
// Initialize MPI |
| 39 |
|
| 40 |
MPI_Init(&argc,&argv); |
| 41 |
int size; // Number of MPI processes, My process ID |
| 42 |
|
| 43 |
MPI_Comm_size(MPI_COMM_WORLD, &size); |
| 44 |
|
| 45 |
if (size > 1) { |
| 46 |
cout << "This example cannot be run on more than one processor!" << endl; |
| 47 |
MPI_Finalize(); |
| 48 |
returnierr = -1; |
| 49 |
return returnierr; |
| 50 |
} |
| 51 |
|
| 52 |
#endif |
| 53 |
|
| 54 |
bool verbose = false; |
| 55 |
|
| 56 |
// Check if we should print results to standard out |
| 57 |
if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true; |
| 58 |
|
| 59 |
|
| 60 |
#ifdef EPETRA_MPI |
| 61 |
Epetra_MpiComm Comm(MPI_COMM_WORLD); |
| 62 |
#else |
| 63 |
Epetra_SerialComm Comm; |
| 64 |
#endif |
| 65 |
if (!verbose) Comm.SetTracebackMode(0); // This should shut down any error traceback reporting |
| 66 |
|
| 67 |
if (verbose) { |
| 68 |
cout << EpetraExt::EpetraExt_Version() << endl << endl; |
| 69 |
cout << Comm << endl << flush; |
| 70 |
} |
| 71 |
|
| 72 |
Comm.Barrier(); |
| 73 |
|
| 74 |
int NumMyElements = 3; |
| 75 |
|
| 76 |
Epetra_Map Map( NumMyElements, 0, Comm ); |
| 77 |
|
| 78 |
Epetra_CrsGraph Graph( Copy, Map, 1 ); |
| 79 |
|
| 80 |
int index[2]; |
| 81 |
index[0] = 2; |
| 82 |
Graph.InsertGlobalIndices( 0, 1, &index[0] ); |
| 83 |
index[0] = 0; |
| 84 |
index[1] = 2; |
| 85 |
Graph.InsertGlobalIndices( 1, 2, &index[0] ); |
| 86 |
index[0] = 1; |
| 87 |
Graph.InsertGlobalIndices( 2, 1, &index[0] ); |
| 88 |
|
| 89 |
Graph.FillComplete(); |
| 90 |
|
| 91 |
// Create an Epetra::CrsMatrix |
| 92 |
Epetra_CrsMatrix Matrix( Copy, Graph ); |
| 93 |
double value[2]; |
| 94 |
index[0] = 2; value[0] = 3.0; |
| 95 |
Matrix.ReplaceMyValues( 0, 1, &value[0], &index[0] ); |
| 96 |
index[0] = 0; index[1] = 2; |
| 97 |
value[0] = 2.0; value[1] = 2.5; |
| 98 |
Matrix.ReplaceMyValues( 1, 2, &value[0], &index[0] ); |
| 99 |
index[0] = 1; value[0] = 1.0; |
| 100 |
Matrix.ReplaceMyValues( 2, 1, &value[0], &index[0] ); |
| 101 |
Matrix.FillComplete(); |
| 102 |
|
| 103 |
EpetraExt::AmesosBTF_CrsMatrix BTFTrans( 0.0, true, verbose ); |
| 104 |
Epetra_CrsMatrix & NewMatrix = BTFTrans( Matrix ); |
| 105 |
|
| 106 |
if (verbose) { |
| 107 |
cout << "*************** PERFORMING BTF TRANSFORM ON CRS_MATRIX **************" <<endl<<endl; |
| 108 |
cout << "CrsMatrix *before* BTF transform: " << endl << endl; |
| 109 |
cout << Matrix << endl; |
| 110 |
} |
| 111 |
|
| 112 |
BTFTrans.fwd(); |
| 113 |
|
| 114 |
if (verbose) { |
| 115 |
cout << "CrsMatrix *after* BTF transform: " << endl << endl; |
| 116 |
cout << NewMatrix << endl; |
| 117 |
} |
| 118 |
|
| 119 |
#ifdef EPETRA_MPI |
| 120 |
MPI_Finalize(); |
| 121 |
#endif |
| 122 |
|
| 123 |
return returnierr; |
| 124 |
} |
| 125 |
|