Skip to content

SPARSE 3::spadd

ndellingwood edited this page Mar 20, 2019 · 13 revisions

KokkosSparse::spadd()

Header File: KokkosSparse_spadd.hpp

Usage: KokkosSparse::spadd_symbolic(handle, a_rowmap, a_entries, b_rowmap, b_entries, c_rowmap);

Usage: KokkosSparse::spadd_numeric(handle, a_rowmap, a_entries, a_values, alpha, b_rowmap, b_entries, b_values, beta, c_rowmap, c_entries, c_values);

Add two sparse matrices.

Interface

  template <typename KernelHandle,
            typename alno_row_view_t_,
            typename alno_nnz_view_t_,
            typename blno_row_view_t_,
            typename blno_nnz_view_t_,
            typename clno_row_view_t_,
            typename clno_nnz_view_t_>
  void spadd_symbolic(
      KernelHandle* handle, 
      const alno_row_view_t_ a_rowmap,
      const alno_nnz_view_t_ a_entries,
      const blno_row_view_t_ b_rowmap,
      const blno_nnz_view_t_ b_entries,
      clno_row_view_t_ c_rowmap);

  template <typename KernelHandle,
            typename alno_row_view_t_,
            typename alno_nnz_view_t_,
            typename ascalar_t_,
            typename ascalar_nnz_view_t_,
            typename blno_row_view_t_,
            typename blno_nnz_view_t_,
            typename bscalar_t_,
            typename bscalar_nnz_view_t_,
            typename clno_row_view_t_,
            typename clno_nnz_view_t_,
            typename cscalar_nnz_view_t_>
  void spadd_numeric(
      KernelHandle* kernel_handle,
      const alno_row_view_t_ a_rowmap,
      const alno_nnz_view_t_ a_entries,
      const ascalar_nnz_view_t_ a_values,
      const ascalar_t_ alpha,
      const blno_row_view_t_ b_rowmap,
      const blno_nnz_view_t_ b_entries,
      const bscalar_nnz_view_t_ b_values,
      const bscalar_t_ beta,
      const clno_row_view_t_ c_rowmap,
      clno_nnz_view_t_ c_entries,
      cscalar_nnz_view_t_ c_values);

Parameters:

spadd_symbolic
  • KernelHandle
  • InputMatrixRowMap: A rank-1 Kokkos::View
  • InputMatrixEntries: A rank-1 Kokkos::View
  • InputMatrixRowMap: A rank-1 Kokkos::View
  • InputMatrixEntries: A rank-1 Kokkos::View
  • Input/OutputRowMap: A rank-1 Kokkos::View with non-const data type.
spadd_numeric
  • KernelHandle
  • InputMatrixRowMap: A rank-1 Kokkos::View
  • InputMatrixEntries: A rank-1 Kokkos::View
  • InputMatrixValues: A rank-1 Kokkos::View
  • InputScalarType: Scalar multiplier for first input matrix
  • InputMatrixRowMap: A rank-1 Kokkos::View
  • InputMatrixEntries: A rank-1 Kokkos::View
  • InputMatrixValues: A rank-1 Kokkos::View
  • InputScalarType: Scalar multiplier for second input matrix
  • Input/OutputRowMap: A rank-1 Kokkos::View with non-const data type.
  • Input/OutputEntries: A rank-1 Kokkos::View with non-const data type.
  • Input/OutputValues: A rank-1 Kokkos::View with non-const data type.

Requirements:

  • Creation of a KernelHandle
  • Matrix::value_type == Matrix::non_const_value_type

Example

#include<Kokkos_Core.hpp>
#include<KokkosSparse_CrsMatrix.hpp>
#include<KokkosSparse_spadd.hpp>

int main(int argc, char* argv[]) {
   Kokkos::initialize();

   int numRows = atoi(argv[1]);

   typedef scalar_t double;
   typedef lno_t int;
   typedef Kokkos::DefaultExecutionSpace Device;

   typedef typename KokkosSparse::CrsMatrix<scalar_t, lno_t, Device> crsMat_t;

   typedef typename crsMat_t::size_type size_t;

   typedef typename crsMat_t::row_map_type::non_const_type row_map_type;
   typedef typename crsMat_t::index_type::non_const_type entries_type;
   typedef typename crsMat_t::values_type::non_const_type values_type;
   // Now create and fill crsMat_t matrices A and B
   // ...
   

   // Create a KokkosKernelsHandle
   typedef typename KokkosKernels::Experimental::KokkosKernelsHandle<size_type, lno_t, scalar_t,
     typename Device::execution_space, typename Device::memory_space, typename Device::memory_space> KernelHandle;

   KernelHandle handle;
   handle.create_spadd_handle(false);
   auto addHandle = handle.get_spadd_handle();

   // Create View components for result crsMat_t matrix C
   row_map_type c_row_map("C row map", numRows + 1);

   KokkosSparse::Experimental::spadd_symbolic<
    KernelHandle,
    typename row_map_type::const_type,
    typename entries_type::const_type,
    typename row_map_type::const_type,
    typename entries_type::const_type,
    row_map_type,
    entries_type>
    (&handle, A.graph.row_map, A.graph.entries, B.graph.row_map, B.graph.entries, c_row_map);

   values_type c_values("C values", addHandle->get_max_result_nnz());
   entries_type c_entries("C entries", addHandle->get_max_result_nnz());

   KokkosSparse::Experimental::spadd_numeric<
    KernelHandle,
    typename row_map_type::const_type,
    typename entries_type::const_type,
    scalar_t, typename values_type::const_type,
    typename row_map_type::const_type,
    typename entries_type::const_type,
    scalar_t, typename values_type::const_type,
    row_map_type, entries_type, values_type>
    (&handle, A.graph.row_map, A.graph.entries, A.values, 1,
     B.graph.row_map, B.graph.entries, B.values, 1,
     c_row_map, c_entries, c_values);


   // Create a CrsMatrix to store the resultant matrix C
   crsMat_t C("C", numRows, numRows, addHandle->get_max_result_nnz(), c_values, c_row_map, c_entries);

   // Destroy the handle
   handle.destroy_spadd_handle();

   Kokkos::finalize();
}
Clone this wiki locally