Fork me on GitHub
 All Classes Files Functions Variables Groups Pages
ainv.cu
#include <cusp/monitor.h>
#include <cusp/krylov/cg.h>
#include <iostream>
int main(void)
{
typedef int IndexType;
typedef float ValueType;
typedef cusp::device_memory MemorySpace;
// create an empty sparse matrix structure
// create 2D Poisson problem
// set stopping criteria (iteration_limit = 1000, relative_tolerance = 1e-6)
// solve without preconditioning
{
std::cout << "\nSolving with no preconditioner" << std::endl;
// allocate storage for solution (x)
// solve
cusp::krylov::cg(A, x, b, monitor);
// report status
monitor.print();
}
// solve AINV preconditioner, using standard drop tolerance strategy
{
std::cout << "\nSolving with scaled bridson preconditioner (drop tolerance .1)" << std::endl;
// allocate storage for solution (x)
// reset the monitor
monitor.reset(b);
// setup preconditioner
// solve
cusp::krylov::cg(A, x, b, monitor, M);
// report status
monitor.print();
}
// solve AINV preconditioner, using static dropping strategy
{
std::cout << "\nSolving with scaled bridson preconditioner (10 nonzeroes per row)" << std::endl;
// allocate storage for solution (x)
// reset the monitor
monitor.reset(b);
// setup preconditioner
// solve
cusp::krylov::cg(A, x, b, monitor, M);
// report status
monitor.print();
}
// solve AINV preconditioner, using novel dropping strategy
{
std::cout << "\nSolving with AINV preconditioner (Lin strategy, p=2)" << std::endl;
// allocate storage for solution (x)
// reset the monitor
monitor.reset(b);
// setup preconditioner
// solve
cusp::krylov::cg(A, x, b, monitor, M);
// report status
monitor.print();
}
return 0;
}