Skip to content

Commit

Permalink
Test cases cover KK spiluk, serial implementations and default trisol…
Browse files Browse the repository at this point in the history
…ver and KK sptrsv
  • Loading branch information
vqd8a committed Jul 31, 2020
1 parent b5ad730 commit af18da6
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 276 deletions.
96 changes: 55 additions & 41 deletions packages/ifpack2/test/unit_tests/Ifpack2_UnitTestIlukGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Ifpack2IlukGraph, IlukGraphTest0, LocalOrdinal
<typename lno_row_view_t::const_value_type, typename lno_nonzero_view_t::const_value_type, double,
HandleExecSpace, TemporaryMemorySpace,PersistentMemorySpace > kk_handle_type;

Teuchos::RCP<kk_handle_type> KernelHandle0, KernelHandle2;

std::string version = Ifpack2::Version();
out << "Ifpack2::Version(): " << version << std::endl;

Expand All @@ -99,65 +97,81 @@ TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Ifpack2IlukGraph, IlukGraphTest0, LocalOrdinal
TEST_EQUALITY( crsgraph->getGlobalNumRows(),crsgraph->getRowMap()->getGlobalNumElements())

LocalOrdinal overlap_levels = 2;
LocalOrdinal fill_levels = 0;

#ifdef KOKKOS_ENABLE_SERIAL
if( !std::is_same< HandleExecSpace, Kokkos::Serial >::value ) {
KernelHandle0 = Teuchos::rcp (new kk_handle_type ());
KernelHandle0->create_spiluk_handle( KokkosSparse::Experimental::SPILUKAlgorithm::SEQLVLSCHD_TP1,
crsgraph->getNodeNumRows(),
2*crsgraph->getNodeNumEntries()*(fill_levels+1),
2*crsgraph->getNodeNumEntries()*(fill_levels+1) );
}
#else

//Original Serial implementation
{
LocalOrdinal fill_levels = 0;

Ifpack2::IlukGraph<crs_graph_type, kk_handle_type> iluk0_graph(crsgraph, fill_levels, overlap_levels);
iluk0_graph.initialize();

//The number of nonzeros in an ILU(0) graph should be the same as the
//number of nonzeros in the input graph:

size_t nnz0 = iluk0_graph.getL_Graph()->getGlobalNumEntries() +
iluk0_graph.getU_Graph()->getGlobalNumEntries() +
iluk0_graph.getNumGlobalDiagonals();

fill_levels = 2;

Ifpack2::IlukGraph<crs_graph_type, kk_handle_type> iluk2_graph(crsgraph, fill_levels, overlap_levels);
iluk2_graph.initialize();

//The number of nonzeros in an ILU(2) graph should be greater than the
//number of nonzeros in the ILU(0) graph:

size_t nnz2 = iluk2_graph.getL_Graph()->getGlobalNumEntries() +
iluk2_graph.getU_Graph()->getGlobalNumEntries() +
iluk2_graph.getNumGlobalDiagonals();

bool nnz2_greater_than_nnz0 = nnz2 > nnz0;
TEST_EQUALITY( nnz2_greater_than_nnz0, true)
}

//Kokkos Kernels KSPILUK implementation
{
Teuchos::RCP<kk_handle_type> KernelHandle0, KernelHandle2;

LocalOrdinal fill_levels = 0;

KernelHandle0 = Teuchos::rcp (new kk_handle_type ());
KernelHandle0->create_spiluk_handle( KokkosSparse::Experimental::SPILUKAlgorithm::SEQLVLSCHD_TP1,
crsgraph->getNodeNumRows(),
2*crsgraph->getNodeNumEntries()*(fill_levels+1),
2*crsgraph->getNodeNumEntries()*(fill_levels+1) );
#endif

Ifpack2::IlukGraph<crs_graph_type, kk_handle_type> iluk0_graph(crsgraph, fill_levels, overlap_levels);
iluk0_graph.initialize(KernelHandle0);
Ifpack2::IlukGraph<crs_graph_type, kk_handle_type> iluk0_graph(crsgraph, fill_levels, overlap_levels);
iluk0_graph.initialize(KernelHandle0);

//The number of nonzeros in an ILU(0) graph should be the same as the
//number of nonzeros in the input graph:
//The number of nonzeros in an ILU(0) graph should be the same as the
//number of nonzeros in the input graph:

size_t nnz0 = iluk0_graph.getL_Graph()->getGlobalNumEntries() +
iluk0_graph.getU_Graph()->getGlobalNumEntries() +
iluk0_graph.getNumGlobalDiagonals();
size_t nnz0 = iluk0_graph.getL_Graph()->getGlobalNumEntries() +
iluk0_graph.getU_Graph()->getGlobalNumEntries() +
iluk0_graph.getNumGlobalDiagonals();

fill_levels = 2;
fill_levels = 2;

#ifdef KOKKOS_ENABLE_SERIAL
if( !std::is_same< HandleExecSpace, Kokkos::Serial >::value ) {
KernelHandle2 = Teuchos::rcp (new kk_handle_type ());
KernelHandle2->create_spiluk_handle( KokkosSparse::Experimental::SPILUKAlgorithm::SEQLVLSCHD_TP1,
crsgraph->getNodeNumRows(),
2*crsgraph->getNodeNumEntries()*(fill_levels+1),
2*crsgraph->getNodeNumEntries()*(fill_levels+1) );
}
#else
KernelHandle2 = Teuchos::rcp (new kk_handle_type ());
KernelHandle2->create_spiluk_handle( KokkosSparse::Experimental::SPILUKAlgorithm::SEQLVLSCHD_TP1,
crsgraph->getNodeNumRows(),
2*crsgraph->getNodeNumEntries()*(fill_levels+1),
2*crsgraph->getNodeNumEntries()*(fill_levels+1) );
#endif

Ifpack2::IlukGraph<crs_graph_type, kk_handle_type> iluk2_graph(crsgraph, fill_levels, overlap_levels);

iluk2_graph.initialize(KernelHandle2);
Ifpack2::IlukGraph<crs_graph_type, kk_handle_type> iluk2_graph(crsgraph, fill_levels, overlap_levels);
iluk2_graph.initialize(KernelHandle2);

//The number of nonzeros in an ILU(2) graph should be greater than the
//number of nonzeros in the ILU(0) graph:
//The number of nonzeros in an ILU(2) graph should be greater than the
//number of nonzeros in the ILU(0) graph:

size_t nnz2 = iluk2_graph.getL_Graph()->getGlobalNumEntries() +
iluk2_graph.getU_Graph()->getGlobalNumEntries() +
iluk2_graph.getNumGlobalDiagonals();
size_t nnz2 = iluk2_graph.getL_Graph()->getGlobalNumEntries() +
iluk2_graph.getU_Graph()->getGlobalNumEntries() +
iluk2_graph.getNumGlobalDiagonals();

bool nnz2_greater_than_nnz0 = nnz2 > nnz0;
TEST_EQUALITY( nnz2_greater_than_nnz0, true)
bool nnz2_greater_than_nnz0 = nnz2 > nnz0;
TEST_EQUALITY( nnz2_greater_than_nnz0, true)
}
}

#define UNIT_TEST_GROUP_LO_GO(LocalOrdinal,GlobalOrdinal) \
Expand Down
45 changes: 32 additions & 13 deletions packages/ifpack2/test/unit_tests/Ifpack2_UnitTestRILUK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ namespace {
using Tpetra::global_size_t;
typedef tif_utest::Node Node;

struct IlukImplTypeDetails {
enum Enum { Serial, KSPILUK };
};
// Single-process unit tests for RILUK are located in the file Ifpack2_UnitTestSerialRILUK.cpp.

template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal>
static Teuchos::RCP<Ifpack2::RILUK<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > > setupTest ()
static Teuchos::RCP<Ifpack2::RILUK<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > > setupTest (const IlukImplTypeDetails::Enum ilukimplType)
{
// Test that ILU(k) can be done on a parallel sparse matrix with noncontiguous row map.
// See bug #6033.
Expand Down Expand Up @@ -121,7 +124,10 @@ static Teuchos::RCP<Ifpack2::RILUK<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalO
GlobalOrdinal lof=1;
params.set("fact: iluk level-of-fill", lof);
params.set("fact: iluk level-of-overlap", 0);

if (ilukimplType == IlukImplTypeDetails::Serial)
params.set("fact: type", "Serial");
else
params.set("fact: type", "KSPILUK");
prec->setParameters(params);
return prec;
}
Expand All @@ -130,22 +136,36 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Ifpack2RILUK, Parallel, Scalar, LocalOrdinal,
{
std::string version = Ifpack2::Version();
out << "Ifpack2::Version(): " << version << std::endl;

auto prec = setupTest<Scalar, LocalOrdinal, GlobalOrdinal>();
prec->initialize();
prec->compute();
{
auto prec = setupTest<Scalar, LocalOrdinal, GlobalOrdinal>(IlukImplTypeDetails::Serial);
prec->initialize();
prec->compute();
}
{
auto prec = setupTest<Scalar, LocalOrdinal, GlobalOrdinal>(IlukImplTypeDetails::KSPILUK);
prec->initialize();
prec->compute();
}
}

TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Ifpack2RILUK, ParallelReuse, Scalar, LocalOrdinal, GlobalOrdinal)
{
std::string version = Ifpack2::Version();
out << "Ifpack2::Version(): " << version << std::endl;

auto prec = setupTest<Scalar, LocalOrdinal, GlobalOrdinal>();
prec->initialize();
prec->compute();
// Pretend we've updated some of the numbers in the matrix, but not its structure.
prec->compute();
{
auto prec = setupTest<Scalar, LocalOrdinal, GlobalOrdinal>(IlukImplTypeDetails::Serial);
prec->initialize();
prec->compute();
// Pretend we've updated some of the numbers in the matrix, but not its structure.
prec->compute();
}
{
auto prec = setupTest<Scalar, LocalOrdinal, GlobalOrdinal>(IlukImplTypeDetails::KSPILUK);
prec->initialize();
prec->compute();
// Pretend we've updated some of the numbers in the matrix, but not its structure.
prec->compute();
}
}

#define UNIT_TEST_GROUP_SC_LO_GO( SC, LO, GO ) \
Expand All @@ -162,4 +182,3 @@ IFPACK2_ETI_MANGLING_TYPEDEFS()
IFPACK2_INSTANTIATE_SLG( UNIT_TEST_GROUP_SC_LO_GO )

}//namespace <anonymous>

Loading

0 comments on commit af18da6

Please sign in to comment.