Ginkgo: The minimal-cuda-solver program

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
The minimal-cuda-solver program

The minimal CUDA solver example.

This example depends on simple-solver.

Table of contents
Introduction About the example The commented program | Results Comments about programming and debugging The plain program

# Introduction

This is a minimal example that solves a system with Ginkgo. The matrix, right hand side and initial guess are read from standard input, and the result is written to standard output. The system matrix is stored in CSR format, and the system solved using the CG method, preconditioned with the block-Jacobi preconditioner. All computations are done on the GPU.

The easiest way to use the example data from the data/ folder is to concatenate the matrix, the right hand side and the initial solution (in that exact order), and pipe the result to the minimal_solver_cuda executable:

cat data/A.mtx data/b.mtx data/x0.mtx | ./minimal-cuda-solver

### About the example

# The commented program

# Results

The following is the expected result when using the data contained in the folder data as input:

%%MatrixMarket matrix array real general
19 1
0.252218
0.108645
0.0662811
0.0630433
0.0384088
0.0396536
0.0402648
0.0338935
0.0193098
0.0234653
0.0211499
0.0196413
0.0199151
0.0181674
0.0162722
0.0150714
0.0107016
0.0121141
0.0123025

### Comments about programming and debugging

# The plain program

#include <iostream>
#include <ginkgo/ginkgo.hpp>
int main()
{
auto gpu = gko::CudaExecutor::create(0, gko::OmpExecutor::create());
auto A = gko::read<gko::matrix::Csr<>>(std::cin, gpu);
auto b = gko::read<gko::matrix::Dense<>>(std::cin, gpu);
auto x = gko::read<gko::matrix::Dense<>>(std::cin, gpu);
auto solver =
gko::solver::Cg<>::build()
.with_preconditioner(gko::preconditioner::Jacobi<>::build())
.with_criteria(
gko::stop::Iteration::build().with_max_iters(20u),
gko::stop::ResidualNorm<>::build().with_reduction_factor(1e-15))
.on(gpu);
solver->generate(give(A))->apply(b, x);
write(std::cout, x);
}
gko::CudaExecutor::create
static std::shared_ptr< CudaExecutor > create(int device_id, std::shared_ptr< Executor > master, bool device_reset, allocation_mode alloc_mode=default_cuda_alloc_mode, CUstream_st *stream=nullptr)
Creates a new CudaExecutor.
gko::OmpExecutor::create
static std::shared_ptr< OmpExecutor > create(std::shared_ptr< CpuAllocatorBase > alloc=std::make_shared< CpuAllocator >())
Creates a new OmpExecutor.
Definition executor.hpp:1396
gko::read
std::unique_ptr< MatrixType > read(StreamType &&is, MatrixArgs &&... args)
Reads a matrix stored in matrix market format from an input stream.
Definition mtx_io.hpp:160