5 #include "Epetra_MpiComm.h" 7 #include "Epetra_SerialComm.h" 9 #include "Epetra_Map.h" 10 #include "Epetra_Vector.h" 11 #include "Epetra_Time.h" 12 #include "Epetra_CrsMatrix.h" 13 #include "Epetra_Util.h" 21 const Epetra_MultiVector& x,
22 const Epetra_MultiVector& b,
23 const Epetra_MultiVector& x_exact)
25 std::vector<double> Norm;
26 int NumVectors = x.NumVectors();
27 Norm.resize(NumVectors);
28 Epetra_MultiVector Ax(x);
29 A.Multiply(
false,x,Ax);
30 Ax.Update(1.0,b,-1.0);
32 bool TestPassed =
false;
33 double TotalNorm = 0.0;
34 for (
int i = 0 ; i < NumVectors ; ++i) {
37 if (
A.Comm().MyPID() == 0)
38 std::cout <<
"||Ax - b|| = " << TotalNorm << std::endl;
39 if (TotalNorm < 1e-5 )
44 Ax.Update (1.0,x,-1.0,x_exact,0.0);
46 for (
int i = 0 ; i < NumVectors ; ++i) {
49 if (
A.Comm().MyPID() == 0)
50 std::cout <<
"||Ax - b|| = " << TotalNorm << std::endl;
51 #ifdef HAVE_AMESOS_SMUMPS 52 if (TotalNorm < 1e-2 )
54 if (TotalNorm < 1e-5 )
64 int main(
int argc,
char *argv[]) {
67 MPI_Init(&argc, &argv);
68 Epetra_MpiComm
Comm(MPI_COMM_WORLD);
70 Epetra_SerialComm
Comm;
73 int NumGlobalElements = 100;
80 int* part =
new int[NumGlobalElements];
82 if (
Comm.MyPID() == 0) {
85 for(
int i=0 ; i<NumGlobalElements ; ++i ) {
86 unsigned int r = Util.RandomInt();
87 part[i] = r%(
Comm.NumProc());
91 Comm.Broadcast(part,NumGlobalElements,0);
94 int NumMyElements = 0;
95 for (
int i = 0 ; i < NumGlobalElements ; ++i) {
96 if (part[i] ==
Comm.MyPID())
101 int* MyGlobalElements =
new int[NumMyElements];
103 for (
int i = 0 ; i < NumGlobalElements ; ++i) {
104 if (part[i] ==
Comm.MyPID() )
105 MyGlobalElements[count++] = i;
108 Epetra_Map Map(NumGlobalElements,NumMyElements,MyGlobalElements,
117 Epetra_CrsMatrix Matrix(
Copy,Map,NumGlobalElements);
119 int* Indices =
new int[NumGlobalElements];
120 double* Values =
new double[NumGlobalElements];
122 for (
int i = 0 ; i < NumGlobalElements ; ++i)
125 for (
int i = 0 ; i < NumMyElements ; ++i) {
126 int iGlobal = MyGlobalElements[i];
127 for (
int jGlobal = 0 ; jGlobal < NumGlobalElements ; ++jGlobal) {
128 if (iGlobal >= jGlobal)
129 Values[jGlobal] = 1.0 * (jGlobal + 1);
131 Values[jGlobal] = 1.0 * (iGlobal + 1);
133 Matrix.InsertGlobalValues(MyGlobalElements[i],
134 NumGlobalElements, Values, Indices);
138 Matrix.FillComplete();
148 Epetra_MultiVector x(Map,NumVectors);
149 Epetra_MultiVector x_exact(Map,NumVectors);
150 Epetra_MultiVector b(Map,NumVectors);
152 A.Multiply(
false,x_exact,b);
158 Epetra_LinearProblem Problem;
161 Problem.SetOperator(&
A);
166 List.
set(
"MaxProcs",2);
173 bool TestPassed =
true;
175 TestPassed = TestPassed &&
186 return(EXIT_SUCCESS);
int Solve()
Solves A X = B (or AT x = B)
int NumericFactorization()
Performs NumericFactorization on the matrix A.
Amesos_Mumps: An object-oriented wrapper for the double precision version of MUMPS.
int SymbolicFactorization()
Performs SymbolicFactorization on the matrix A.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Amesos_TestRowMatrix: a class to test Epetra_RowMatrix based codes.
int SetParameters(Teuchos::ParameterList &ParameterList)
Updates internal variables.
bool CheckError(const Epetra_RowMatrix &A, const Epetra_MultiVector &x, const Epetra_MultiVector &b, const Epetra_MultiVector &x_exact)
int main(int argc, char *argv[])
#define AMESOS_CHK_ERR(a)