Ginkgo Generated from branch based on main. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
The ginkgo-overhead program

The ginkgo overhead measurement example.

Table of contents
  1. Introduction
  2. The commented program
  1. Results
  2. The plain program

Introduction

About the example

The commented program

num_iters = std::atol(argv[1]);
if (num_iters == 0) {
print_usage_and_exit(argv[0]);
}
}
std::cout << gko::version_info::get() << std::endl;
auto exec = gko::ReferenceExecutor::create();
auto cg_factory =
cg::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(num_iters))
.on(exec);
auto A = gko::initialize<mtx>({1.0}, exec);
auto b = gko::initialize<vec>({std::nan("")}, exec);
auto x = gko::initialize<vec>({0.0}, exec);
auto tic = std::chrono::steady_clock::now();
auto solver = cg_factory->generate(gko::give(A));
solver->apply(x, b);
exec->synchronize();
auto tac = std::chrono::steady_clock::now();
auto time = std::chrono::duration_cast<std::chrono::nanoseconds>(tac - tic);
std::cout << "Running " << num_iters
<< " iterations of the CG solver took a total of "
<< static_cast<double>(time.count()) /
static_cast<double>(std::nano::den)
<< " seconds." << std::endl
<< "\tAverage library overhead: "
<< static_cast<double>(time.count()) /
static_cast<double>(num_iters)
<< " [nanoseconds / iteration]" << std::endl;
}
static const version_info & get()
Returns an instance of version_info.
Definition version.hpp:139
std::unique_ptr< Matrix > initialize(size_type stride, std::initializer_list< typename Matrix::value_type > vals, std::shared_ptr< const Executor > exec, TArgs &&... create_args)
Creates and initializes a column-vector.
Definition dense.hpp:1565
std::remove_reference< OwningPointer >::type && give(OwningPointer &&p)
Marks that the object pointed to by p can be given to the callee.
Definition utils_helper.hpp:247

Results

This is the expected output:

Running 1000000 iterations of the CG solver took a total of 1.60337 seconds.
Average library overhead: 1603.37 [nanoseconds / iteration]

Comments about programming and debugging

The plain program

#include <chrono>
#include <cmath>
#include <iostream>
#include <ginkgo/ginkgo.hpp>
[[noreturn]] void print_usage_and_exit(const char* name)
{
std::cerr << "Usage: " << name << " [NUM_ITERS]" << std::endl;
std::exit(-1);
}
int main(int argc, char* argv[])
{
using ValueType = double;
using IndexType = int;
long unsigned num_iters = 1000000;
if (argc > 2) {
print_usage_and_exit(argv[0]);
}
if (argc == 2) {
num_iters = std::atol(argv[1]);
if (num_iters == 0) {
print_usage_and_exit(argv[0]);
}
}
std::cout << gko::version_info::get() << std::endl;
auto exec = gko::ReferenceExecutor::create();
auto cg_factory =
cg::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(num_iters))
.on(exec);
auto A = gko::initialize<mtx>({1.0}, exec);
auto b = gko::initialize<vec>({std::nan("")}, exec);
auto x = gko::initialize<vec>({0.0}, exec);
auto tic = std::chrono::steady_clock::now();
auto solver = cg_factory->generate(gko::give(A));
solver->apply(x, b);
exec->synchronize();
auto tac = std::chrono::steady_clock::now();
auto time = std::chrono::duration_cast<std::chrono::nanoseconds>(tac - tic);
std::cout << "Running " << num_iters
<< " iterations of the CG solver took a total of "
<< static_cast<double>(time.count()) /
static_cast<double>(std::nano::den)
<< " seconds." << std::endl
<< "\tAverage library overhead: "
<< static_cast<double>(time.count()) /
static_cast<double>(num_iters)
<< " [nanoseconds / iteration]" << std::endl;
}
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition sparsity_csr.hpp:21
Dense is a matrix format which explicitly stores all values of the matrix.
Definition sparsity_csr.hpp:25
CG or the conjugate gradient method is an iterative type Krylov subspace method which is suitable for...
Definition cg.hpp:50