General, high performance algebraic multigrid solver
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Build Status


RAPtor is a general, high performance algebraic multigrid solver.


  • MPI
  • cmake

Build Instructions

  1. Create a build directory
mkdir build
  1. Configure the build
cd build
cmake [OPTIONS] ..

Note: make VERBOSE=1 if you want to see what flags are being used.


  • WITH_HYPRE: Includes hypre_wrapper in the build. Hypre must be installed before building with this option. If not installed to /usr/local, set the HYPRE_DIR option.

  • WITH_MFEM: Includes mfem_wrapper, mfem files, and hypre_wrapper in the build. Mfem, Metis, and Hypre must be installed before building with this option. For any packages not installed to /usr/local, set the directory option (_DIR).

  • HYPRE_DIR: Sets the directory of hypre containing the include and lib folders

  • METIS_DIR: Sets the directory of metis containing the include and libmetis folders

  • MFEM_DIR: Sets the directory of mfem containing mfem.h and libmfem

Unit Testing

The build system uses GoogleTest. The build searches the source tree and adds any test directory to ctest. For a simple example, see raptor/core/tests/ParVector.cpp.

To test:

make test


      author = {Bienz, Amanda and Olson, Luke N.},
      title = {{RAPtor}: parallel algebraic multigrid v0.1},
      year = {2017},
      url = {},
      note = {Release 0.1}

Full Example

This example is maintained in raptor/examples/example.cpp

// Copyright (c) 2015-2017, Raptor Developer Team
// License: Simplified BSD,
#include <mpi.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <iostream>

// Include raptor
#include "raptor.hpp"

// This is a basic use case.
int main(int argc, char *argv[])

    // set rank and number of processors
    int rank, num_procs;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &num_procs);

    // Create parallel matrix and vectors
    ParCSRMatrix* A;
    ParVector x;
    ParVector b;

    // Timers
    double time_setup, time_solve, time_base;

    // Problems size and type
    int dim = 2;
    int n = 100;

    std::vector<int> grid;
    grid.resize(dim, n);

    // Anisotropic diffusion
    double eps = 0.001;
    double theta = M_PI/8.0;
    double* stencil = NULL;
    stencil = diffusion_stencil_2d(eps, theta);
    A = par_stencil_grid(stencil,, dim);
    delete[] stencil;

    x = ParVector(A->global_num_cols, A->on_proc_num_cols, A->partition->first_local_col);
    b = ParVector(A->global_num_rows, A->local_num_rows, A->partition->first_local_row);

    A->mult(x, b);

    // AMG parameters
    double strong_threshold = 0.25;

    // Create a multilevel object
    ParMultilevel* ml;

    // Setup Raptor Hierarchy
    time_base = MPI_Wtime();
    ml = new ParMultilevel(A, strong_threshold, Falgout, Direct, SOR);
    time_setup = MPI_Wtime() - time_base;

    // Print out information on the AMG hierarchy
    int64_t lcl_nnz;
    int64_t nnz;

    if (rank == 0) std::cout << "Level\tNumRows\tNNZ" << std::endl;
    if (rank == 0) std::cout << "-----\t-------\t---" << std::endl;
    for (int64_t i = 0; i < ml->num_levels; i++)
        ParCSRMatrix* Al = ml->levels[i]->A;
        lcl_nnz = Al->local_nnz;
        MPI_Reduce(&lcl_nnz, &nnz, 1, MPI_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
        if (rank == 0) std::cout << i << "\t" << Al->global_num_rows << "\t" << nnz << std::endl;

    // Solve Raptor Hierarchy
    time_base = MPI_Wtime();
    ml->solve(x, b);
    time_solve = MPI_Wtime() - time_base;

    MPI_Reduce(&time_setup, &time_base, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
    if (rank == 0) printf("Raptor AMG Setup Time: %e\n", time_base);
    MPI_Reduce(&time_solve, &time_base, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
    if (rank == 0) printf("Raptor AMG Solve Time: %e\n", time_base);

    // Delete AMG hierarchy
    delete ml;
    delete A;

    return 0;

To Build,

g++ -std=c++11 -std=gnu++11 -O3
-o example.cpp.o -c example.cpp

To Link,

g++ -std=c++11 -O3 -Wl,-search_paths_first -Wl,-headerpad_max_install_names
example.cpp.o -o example


This code is distributed under BSD:

Please see LICENSE.txt and COPYRIGHT.txt for more information.