Introduction
This tutorial illustrates how to build vectors and matrices, to apply linear algebra operations and to solve linear systems with solver supporting the Alien SYCL BackEnd.
Direct Linear System assembly on device SYCL Handlers
auto local_size = vdist.localSize();
auto offset = vdist.offset();
{
{
auto xv = x_acc.view(cgh) ;
cgh.parallel_for(engine.maxNumThreads(),
[=](Alien::SYCLParallelEngine::Item<1>::type item)
{
auto id = item.get_id(0);
for (std::size_t index = id; id < local_size; id += item.get_range()[0])
xv[index] = 1.*index;
});
}) ;
{
auto yv = y_acc.view(cgh) ;
auto xcv = x_acc.constView(cgh) ;
cgh.parallel_for(engine.maxNumThreads(),
[=](Alien::SYCLParallelEngine::Item<1>::type item)
{
auto index = item.get_id(0) ;
auto id = item.get_id(0);
for (std::size_t index = id; id < local_size; id += item.get_range()[0])
yv[index] = 2*xcv[index] ;
});
}) ;
{
for (Integer i = 0; i < local_size; ++i) {
Integer row = offset + i;
profiler.addMatrixEntry(row, row);
if (row + 1 < global_size)
profiler.addMatrixEntry(row, row + 1);
if (row - 1 >= 0)
profiler.addMatrixEntry(row, row - 1);
}
}
{
Alien::SYCL::ProfiledMatrixBuilder builder(A, Alien::ProfiledMatrixOptions::eResetValues);
{
auto matrix_acc = builder.view(cgh) ;
cgh.parallel_for(engine.maxNumThreads(),
[=](Alien::SYCLParallelEngine::Item<1>::type item)
{
auto index = item.get_id(0) ;
auto id = item.get_id(0);
for (std::size_t index = id; id < local_size; id += item.get_range()[0])
{
Integer row = offset + index;
matrix_acc[matrix_acc.entryIndex(row,row)] = 2.;
if (row + 1 < global_size)
matrix_acc[matrix_acc.entryIndex(row, row + 1)] = -1.;
if (row - 1 >= 0)
matrix_acc[matrix_acc.entryIndex(row, row - 1)] = -1.;
}
});
}) ;
}
Computes a matrix distribution.
Implementation of an algebraic space.
Computes a vector distribution.
Using SYCL Linear Algebra
Alien::SYCLLinearAlgebra sycl_alg;
auto residual = sycl_alg.
dot(R,R) ;
Real dot(const IVector &x, const IVector &y) const
Compute the dot product of two vectors.
void axpy(Real alpha, const IVector &x, IVector &y) const
Scale a vector by a factor and adds the result to another vector.
void copy(const IVector &x, IVector &r) const
Copy a vector in another one.
void mult(const IMatrix &a, const IVector &x, IVector &r) const
Compute a matrix vector product.
Linear Systems resolution
typedef typename AlgebraType::BackEndType BackEndType ;
AlgebraType sycl_alg;
auto const& true_A = A.impl()->get<BackEndType>() ;
auto const& true_b = b.impl()->get<BackEndType>() ;
auto& true_x = x.impl()->get<BackEndType>(true) ;
StopCriteriaType stop_criteria{alg,true_b,tol,max_iteration,output_level>0?trace_mng:nullptr} ;
SolverType solver{alg,trace_mng} ;
solver.setOutputLevel(output_level) ;
trace_mng->info()<<"CHEBYSHEV PRECONDITIONER";
double polynom_factor = 0.5 ;
int polynom_order = 3 ;
int polynom_factor_max_iter = 10 ;
PrecondType precond{alg,true_A,polynom_factor,polynom_order,polynom_factor_max_iter,trace_mng} ;
precond.init() ;
solver.solve(precond,stop_criteria,true_A,true_b,true_x) ;
if(stop_criteria.getStatus())
{
trace_mng->info()<<"Solver has converged";
trace_mng->info()<<"Nb iterations : "<<stop_criteria();
trace_mng->info()<<"Criteria value : "<<stop_criteria.getValue();
}
else
{
trace_mng->info()<<"Solver convergence failed";
}
Alien universe. Common structure to store shared objects between all elements of the library Alien.
Arccore::ITraceMng * traceMng() const
Get the trace manager.