Tpetra Matrix/Vector Services Version of the Day
Support for custom sparse mat-vec kernels.

Tpetra::CrsGraph and Tpetra::CrsMatrix provide support for externally changing the sparse matrix kernels used by the classes. This is done by providing a new sparse kernels class, according to the Kokkos CRS kernel API. The Tpetra::CrsGraph and Tpetra::CrsMatrix classes are then templated on the new sparse kernels class, which dictates not only the kernel for the sparse matrix-vector product, but also any associated storage for the kernel object and the underlying local sparse graph and matrix objects.

At that point, using the new kernel is as simple as templating the Tpetra CrsMatrix and CrsGraph objects on the sparse kernel class. An example of this is in the file tpetra/examples/LocalMatOps/LocalMatOpExample.cpp, included here:

#include <Teuchos_GlobalMPISession.hpp>
#include <Teuchos_oblackholestream.hpp>

#include <examples/Kokkos_DummySparseKernelClass.hpp>
#include <Kokkos_DefaultNode.hpp>

#include "Tpetra_DefaultPlatform.hpp"
#include "Tpetra_CrsMatrix.hpp"

int main(int argc, char *argv[]) {
  Teuchos::oblackholestream blackhole;
  Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole);

  typedef Tpetra::DefaultPlatform::DefaultPlatformType           Platform;
  typedef Tpetra::DefaultPlatform::DefaultPlatformType::NodeType Node;
  typedef KokkosExamples::DummySparseKernel<Node>                SparseOps;
  typedef Tpetra::Map<int,int,Node>                              Map;
  typedef Tpetra::CrsMatrix<float,int,int,Node,SparseOps>        Matrix;
  typedef Tpetra::MultiVector<float,int,int,Node>                MultiVector;

  // Get the default communicator and node
  Platform &platform = Tpetra::DefaultPlatform::getDefaultPlatform();
  Teuchos::RCP<const Teuchos::Comm<int> > comm = platform.getComm();
  Teuchos::RCP<Node>             node = platform.getNode();

  std::cout << "Note, this class doesn't actually do anything. We are only testing that it compiles." << std::endl;

  // create the matrix with a custom sparse mat-vec kernel
  const size_t numRows = 5;
  const Tpetra::global_size_t numGlobalRows = numRows*comm->getSize();
  Teuchos::RCP<const Map> map = Tpetra::createUniformContigMapWithNode<int,int,Node>(numGlobalRows, comm, node);
  Teuchos::RCP<Matrix> matrix = Teuchos::rcp( new Matrix(map,1,Tpetra::DynamicProfile) );

  Teuchos::RCP<MultiVector> X = Tpetra::createMultiVector<float>(map, 2),
                            Y = Tpetra::createMultiVector<float>(map, 2);
  matrix->apply(*X, *Y);

  std::cout << "End Result: TEST PASSED" << std::endl;
  return 0;
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines