C++ Interface

The C++ interface is a header-only C++17 wrapper over the public HYPREDRV_ C API. It provides RAII ownership for HYPREDRV_t, throwing error handling, a YAML-driven configuration path, and an idiomatic snake_case method mirror of the C API.

Build

cmake -S . -B build-cpp \
  -DHYPREDRV_ENABLE_CPP=ON \
  -DHYPREDRV_ENABLE_TESTING=ON \
  -DHYPREDRV_ENABLE_EXAMPLES=ON
cmake --build build-cpp --target cpp-test --parallel

Usage

#include <hypredrive.hpp>

hypredrive::initialize();
hypredrive::driver drv(MPI_COMM_SELF);
drv.set_library_mode();
drv.parse_yaml(R"yaml(
general:
  statistics: 0
solver:
  pcg:
    max_iter: 100
    relative_tol: 1.0e-8
preconditioner:
  amg:
    print_level: 0
)yaml");
drv.set_matrix_from_csr(row_start, row_end, indptr, cols, values);
drv.set_rhs_from_array(row_start, row_end, rhs);
drv.set_zero_initial_guess();
drv.solve();
hypredrive::finalize();

hypredrive::driver is move-only and destroys its underlying HYPREDRV_t in its destructor. Methods throw hypredrive::error when the underlying C API returns a nonzero status. The original status is available through error::code(). Call hypredrive::describe_error(e.code()) if a caught exception should also print the C-side diagnostic. Explicit destroy_linear_solver() calls are only needed to release solver state before the driver goes out of scope.

Configuration

Solver configuration is intentionally YAML-driven. The C++ wrapper does not mirror the full solver option schema with C++ setters, because the YAML schema is the project-owned source of truth and supports new HYPREDRV options immediately. Use parse_yaml() for YAML from a string, string literal, input stream, or file path; use parse_args(argc, argv) for the same command-line style parsing exposed by the C API. String-like inputs are treated as file paths when they look like paths, otherwise as inline YAML text. YAML text is passed to the C parser as a C string, so embedded NUL bytes are rejected.

Example

The laplacian-cpp example assembles a distributed 3D 7-point Laplacian and solves it through the wrapper:

mpiexec -n 4 ./build-cpp/laplacian-cpp -n 16 16 16 -P 2 2 1 -s 7

Pass a custom YAML file with -i/--input options.yml.

API correspondence

The C++ interface is a thin throwing wrapper over the public C API. The table below maps each C++ entry point to the C API it forwards to. C API names link to the generated API reference.

C++ and C API correspondence

C++ API

C API

hypredrive::initialize

HYPREDRV_Initialize()

hypredrive::finalize

HYPREDRV_Finalize()

hypredrive::describe_error

HYPREDRV_ErrorCodeDescribe()

hypredrive::throw_invalid_value

HYPREDRV_ErrorInvalidValue()

hypredrive::print_lib_info

HYPREDRV_PrintLibInfo()

hypredrive::print_system_info

HYPREDRV_PrintSystemInfo()

hypredrive::print_exit_info

HYPREDRV_PrintExitInfo()

hypredrive::register_solver_preset

HYPREDRV_SolverPresetRegister()

hypredrive::register_precon_preset

HYPREDRV_PreconPresetRegister()

hypredrive::driver::driver

HYPREDRV_Create()

hypredrive::driver::~driver

HYPREDRV_Destroy()

hypredrive::driver::destroy

HYPREDRV_Destroy()

hypredrive::driver::parse_args

HYPREDRV_InputArgsParse()

hypredrive::driver::parse_yaml

HYPREDRV_InputArgsParse()

hypredrive::driver::set_library_mode

HYPREDRV_SetLibraryMode()

hypredrive::driver::set_object_name

HYPREDRV_ObjectSetName()

hypredrive::driver::get_warmup

HYPREDRV_InputArgsGetWarmup()

hypredrive::driver::get_num_repetitions

HYPREDRV_InputArgsGetNumRepetitions()

hypredrive::driver::get_num_linear_systems

HYPREDRV_InputArgsGetNumLinearSystems()

hypredrive::driver::get_num_precon_variants

HYPREDRV_InputArgsGetNumPreconVariants()

hypredrive::driver::set_precon_variant

HYPREDRV_InputArgsSetPreconVariant()

hypredrive::driver::set_precon_preset

HYPREDRV_InputArgsSetPreconPreset()

hypredrive::driver::set_solver_preset

HYPREDRV_InputArgsSetSolverPreset()

hypredrive::driver::build_system

HYPREDRV_LinearSystemBuild()

hypredrive::driver::read_matrix

HYPREDRV_LinearSystemReadMatrix()

hypredrive::driver::set_matrix

HYPREDRV_LinearSystemSetMatrix()

hypredrive::driver::set_rhs

HYPREDRV_LinearSystemSetRHS()

hypredrive::driver::set_matrix_from_csr

HYPREDRV_LinearSystemSetMatrixFromCSR()

hypredrive::driver::set_rhs_from_array

HYPREDRV_LinearSystemSetRHSFromArray()

hypredrive::driver::set_initial_guess

HYPREDRV_LinearSystemSetInitialGuess()

hypredrive::driver::set_zero_initial_guess

HYPREDRV_LinearSystemSetInitialGuess()

hypredrive::driver::set_solution

HYPREDRV_LinearSystemSetSolution()

hypredrive::driver::set_reference_solution

HYPREDRV_LinearSystemSetReferenceSolution()

hypredrive::driver::reset_initial_guess

HYPREDRV_LinearSystemResetInitialGuess()

hypredrive::driver::set_prec_matrix

HYPREDRV_LinearSystemSetPrecMatrix()

hypredrive::driver::set_dofmap

HYPREDRV_LinearSystemSetDofmap()

hypredrive::driver::set_interleaved_dofmap

HYPREDRV_LinearSystemSetInterleavedDofmap()

hypredrive::driver::set_contiguous_dofmap

HYPREDRV_LinearSystemSetContiguousDofmap()

hypredrive::driver::read_dofmap

HYPREDRV_LinearSystemReadDofmap()

hypredrive::driver::print_dofmap

HYPREDRV_LinearSystemPrintDofmap()

hypredrive::driver::print_system

HYPREDRV_LinearSystemPrint()

hypredrive::driver::set_near_null_space

HYPREDRV_LinearSystemSetNearNullSpace()

hypredrive::driver::get_solution_values_raw

HYPREDRV_LinearSystemGetSolutionValues()

hypredrive::driver::get_solution_length

HYPREDRV_LinearSystemGetSolutionLength()

hypredrive::driver::get_solution_values

HYPREDRV_LinearSystemGetSolutionValues()

hypredrive::driver::get_solution_norm

HYPREDRV_LinearSystemGetSolutionNorm()

hypredrive::driver::get_solution

HYPREDRV_LinearSystemGetSolution()

hypredrive::driver::get_rhs_values

HYPREDRV_LinearSystemGetRHSValues()

hypredrive::driver::get_rhs

HYPREDRV_LinearSystemGetRHS()

hypredrive::driver::get_matrix

HYPREDRV_LinearSystemGetMatrix()

hypredrive::driver::set_state_vector

HYPREDRV_StateVectorSet()

hypredrive::driver::get_state_vector_values

HYPREDRV_StateVectorGetValues()

hypredrive::driver::copy_state_vector

HYPREDRV_StateVectorCopy()

hypredrive::driver::update_all_state_vectors

HYPREDRV_StateVectorUpdateAll()

hypredrive::driver::apply_state_vector_correction

HYPREDRV_StateVectorApplyCorrection()

hypredrive::driver::create_precon

HYPREDRV_PreconCreate()

hypredrive::driver::create_linear_solver

HYPREDRV_LinearSolverCreate()

hypredrive::driver::setup_precon

HYPREDRV_PreconSetup()

hypredrive::driver::setup_linear_solver

HYPREDRV_LinearSolverSetup()

hypredrive::driver::apply_linear_solver

HYPREDRV_LinearSolverApply()

hypredrive::driver::solve

HYPREDRV_LinearSolverCreate(), HYPREDRV_LinearSolverSetup(), HYPREDRV_LinearSolverApply()

hypredrive::driver::apply_precon

HYPREDRV_PreconApply()

hypredrive::driver::destroy_precon

HYPREDRV_PreconDestroy()

hypredrive::driver::destroy_linear_solver

HYPREDRV_LinearSolverDestroy()

hypredrive::driver::print_stats

HYPREDRV_StatsPrint()

hypredrive::driver::begin_annotation

HYPREDRV_AnnotateBegin()

hypredrive::driver::end_annotation

HYPREDRV_AnnotateEnd()

hypredrive::driver::begin_level_annotation

HYPREDRV_AnnotateLevelBegin()

hypredrive::driver::end_level_annotation

HYPREDRV_AnnotateLevelEnd()

hypredrive::driver::compute_eigenspectrum

HYPREDRV_LinearSystemComputeEigenspectrum()

hypredrive::driver::get_linear_solver_num_iter

HYPREDRV_LinearSolverGetNumIter()

hypredrive::driver::get_linear_solver_setup_time

HYPREDRV_LinearSolverGetSetupTime()

hypredrive::driver::get_linear_solver_solve_time

HYPREDRV_LinearSolverGetSolveTime()

hypredrive::driver::get_stats_level_count

HYPREDRV_StatsLevelGetCount()

hypredrive::driver::get_stats_level_entry

HYPREDRV_StatsLevelGetEntry()

hypredrive::driver::print_stats_level

HYPREDRV_StatsLevelPrint()

Installation

When HYPREDRV_ENABLE_CPP=ON, CMake installs hypredrive.hpp and exports the HYPREDRV::CXX target. Downstream projects should link that target instead of manually adding include directories.