#include "ml_config.h"
#include "ml_common.h"
#ifdef HAVE_ML_MLAPI
#include "MLAPI.h"
using namespace Teuchos;
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
#endif
try {
DistributedMatrix A(MySpace, MySpace);
for (int i = 0 ; i < MySpace.GetNumGlobalElements() ; ++i) {
if (i)
A(i, i - 1) = -1.0;
if (i + 1 != A.NumGlobalCols())
A(i, i + 1) = -1.0;
A(i, i) = 2.0;
}
}
A.FillComplete();
std::cout << A;
MultiVector x(MySpace);
MultiVector y(MySpace);
MultiVector z;
x = 1.0;
y.Random();
for (int i = 0 ; i < y.GetMyLength() ; ++i)
y(i) = 1.0 * i + x(i);
z = x + y;
double norm = sqrt(z * z);
double Anorm = sqrt(z * (A * z));
x = x / (x * y);
std::cout << "2-norm of z = " << norm << std::endl;
std::cout << "A-norm of z = " << Anorm << std::endl;
}
Operator C = A * B;
C = A + B;
C = 1.0 * A - B * 2.0;
InverseOperator invA(A,"Amesos-KLU");
x = invA * (A * x) - x;
double NormX = sqrt(x * x);
std::cout << "Norm of inv(A) * A * x - x = " << NormX << std::endl;
std::cout << MySpace;
std::cout << x;
std::cout << A;
MultiVector ER, EI;
for (int i = 0 ; i < ER.GetMyLength() ; ++i)
std::cout << "ER(" << MySpace(i) << ") = " << ER(i) << std::endl;
MATLABStream matlab("Blackboard.m", false);
matlab << "% you can add any MATLAB command this way\n";
x.SetLabel("x");
matlab << x;
A.SetLabel("A");
matlab << A;
ER.SetLabel("ER");
EI.SetLabel("EI");
matlab << ER;
matlab << EI;
matlab << "plot(ER, EI, 'o')\n";
}
catch (const int e) {
std::cout << "Integer exception, code = " << e << std::endl;
}
catch (...) {
std::cout << "problems here..." << std::endl;
}
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return(0);
}
#else
#include "ml_include.h"
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
#endif
puts("This MLAPI example requires the following configuration options:");
puts("\t--enable-epetra");
puts("\t--enable-teuchos");
puts("\t--enable-ifpack");
puts("\t--enable-amesos");
puts("Please check your configure line.");
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return(0);
}
#endif
MLAPI: Default namespace for all MLAPI objects and functions.
Definition: MLAPI_Aggregation.h:24
int GetNumProcs()
Returns the total number of processes in the computation.
int GetMyPID()
Returns the ID of the calling process.
void Eig(const Operator &Op, MultiVector &ER, MultiVector &EI)
Computes eigenvalues and eigenvectors using LAPACK (w/ one process only).
void Finalize()
Destroys the MLAPI workspace.
MultiVector GetDiagonal(const Operator &A)
Returns a vector containing the diagonal elements of A.
void Init()
Initialize the MLAPI workspace.