![]() |
cuLite v0.3.1
A lite CUDA C++ Interface
|
This section demonstrates how to solve dense systems of linear equations on GPU using standard factorization methods.
Performs LU factorization with partial pivoting for general matrices on GPU.
| Source Code | Console Output |
|---|---|
#include <iostream>
#include <cla3p/dense.hpp>
#include <cla3p/algebra.hpp>
#include <culite/dense.hpp>
#include <culite/linsol.hpp>
int main()
{
/*
* Create a random dense objects on host
*/
/*
* Transfer to device
*/
HostA >> A;
HostBv >> b;
HostBm >> B;
/*
* Instantiate LU solver
*/
culite::LapackLU<culite::dns::RdMatrix> luSolver;
/*
* Decompose A into LU product
*/
luSolver.decompose(A);
{
/*
* Single column (vector) rhs
* Overwrite x with the solution (A^{-1} * Bv)
*/
culite::dns::RdVector x = b;
luSolver.solve(x);
// Check error norm on host
cla3p::dns::RdVector HostX;
x >> HostX;
std::cout << "Dense Vector rhs::Absolute Error: "
<< (HostBv - HostA * HostX).evaluate().normOne() << std::endl;
}
{
/*
* Multiple column (matrix) rhs
* Overwrite X with the solution (A^{-1} * B)
*/
culite::dns::RdMatrix X = B;
luSolver.solve(X);
// Check error norm on host
cla3p::dns::RdMatrix HostX;
X >> HostX;
std::cout << "Dense Matrix rhs::Absolute Error: "
<< (HostBm - HostA * HostX).evaluate().normOne() << std::endl;
}
return 0;
}
static XxMatrix< T_Scalar > random(int_t nr, int_t nc, const Property &pr=Property::General(), T_RScalar lo=T_RScalar(0), T_RScalar hi=T_RScalar(1)) T_RScalar normOne() const T_RScalar normOne() const static XxVector< T_Scalar > random(int_t n, T_RScalar lo=T_RScalar(0), T_RScalar hi=T_RScalar(1)) The partial pivoting LU linear solver for dense device matrices. Definition lapack_lu.hpp:40 XxMatrix< real_t > RdMatrix XxVector< real_t > RdVector XxMatrix< real_t > RdMatrix Double precision real matrix. Definition dense.hpp:55 XxVector< real_t > RdVector Double precision real device vector. Definition dense.hpp:31 | Dense Vector rhs::Absolute Error: 1.7656e-16
Dense Matrix rhs::Absolute Error: 6.66134e-16
|