Fork me on GitHub
 All Classes Files Functions Variables Groups Pages
diagonal.cu
#include <cusp/krylov/cg.h>
#include <iostream>
int main(void)
{
// where to perform the computation
typedef cusp::device_memory MemorySpace;
// which floating point type to use
typedef float ValueType;
// create an empty sparse matrix structure (HYB format)
// load a matrix stored in MatrixMarket format
// Note: A has poorly scaled rows & columns
// set stopping criteria (iteration_limit = 100, relative_tolerance = 1e-6, absolute_tolerance = 0, verbose = true)
cusp::monitor<ValueType> monitor(b, 100, 1e-6, 0, true);
// solve without preconditioning
{
std::cout << "\nSolving with no preconditioner" << std::endl;
// allocate storage for solution (x)
// solve
cusp::krylov::cg(A, x, b, monitor);
}
// solve with diagonal preconditioner
{
std::cout << "\nSolving with diagonal preconditioner (M = D^-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);
}
return 0;
}