Skip to content

Commit

Permalink
Tpetra: Attempt to fix trilinos#5117
Browse files Browse the repository at this point in the history
@trilinos/tpetra

TpetraCore's tests and examples build, but some tests still fail.
  • Loading branch information
Mark Hoemmen committed May 7, 2019
1 parent b36b727 commit ad792be
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 66 deletions.
25 changes: 17 additions & 8 deletions packages/tpetra/core/src/Tpetra_CrsGraph_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2568,21 +2568,30 @@ namespace Tpetra {
/// \brief Nonmember function to create an empty CrsGraph given a
/// row Map and the max number of entries allowed locally per row.
///
/// \return A dynamically allocated (DynamicProfile) graph with
/// specified number of nonzeros per row (defaults to zero).
/// \return A graph with a specified maximum number of nonzeros per
/// row (defaults to zero, which is generally not useful).
/// \relatesalso CrsGraph
template <class LocalOrdinal, class GlobalOrdinal, class Node>
Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
createCrsGraph (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map,
size_t maxNumEntriesPerRow = 0,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
createCrsGraph (const Teuchos::RCP<const Map<LocalOrdinal,
GlobalOrdinal, Node> >& map,
const size_t maxNumEntriesPerRow = 0,
const Teuchos::RCP<Teuchos::ParameterList>& params =
Teuchos::null)
{
using Teuchos::rcp;
typedef CrsGraph<LocalOrdinal, GlobalOrdinal, Node> graph_type;
return rcp (new graph_type (map, maxNumEntriesPerRow, DynamicProfile, params));
using graph_type = CrsGraph<LocalOrdinal, GlobalOrdinal, Node>;
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
const ProfileType profileType = DynamicProfile;
#else
const ProfileType profileType = StaticProfile;
#endif // TPETRA_ENABLE_DEPRECATED_CODE
return rcp (new graph_type (map, maxNumEntriesPerRow,
profileType, params));
}

/// \brief Nonmember CrsGraph constructor that fuses Import and fillComplete().
/// \brief Nonmember CrsGraph constructor that fuses Import and
/// fillComplete().
/// \relatesalso CrsGraph
/// \tparam CrsGraphType A specialization of CrsGraph.
///
Expand Down
9 changes: 7 additions & 2 deletions packages/tpetra/core/src/Tpetra_CrsMatrix_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5034,9 +5034,14 @@ namespace Tpetra {
size_t maxNumEntriesPerRow = 0,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
{
typedef CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> matrix_type;
using matrix_type = CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
const ProfileType profileType = DynamicProfile;
#else
const ProfileType profileType = StaticProfile;
#endif // TPETRA_ENABLE_DEPRECATED_CODE
return Teuchos::rcp (new matrix_type (map, maxNumEntriesPerRow,
DynamicProfile, params));
profileType, params));
}

template<class CrsMatrixType>
Expand Down
4 changes: 2 additions & 2 deletions packages/tpetra/core/test/BugTests/BlankRowBugTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace {
}
destRowMap = Tpetra::createNonContigMap<LO, GO> (tuple<GO> (0, 1), comm);

RCP<crs_matrix_type> srcMat = Tpetra::createCrsMatrix<SC>(sourceRowMap);
RCP<crs_matrix_type> srcMat = Tpetra::createCrsMatrix<SC>(sourceRowMap, 1);
if (rank == 0) {
srcMat->insertGlobalValues (static_cast<GO> (0), tuple<GO> (0), tuple<SC> (1.0));
}
Expand All @@ -91,7 +91,7 @@ namespace {
TEST_EQUALITY_CONST( srcMat->getNumEntriesInGlobalRow(1), static_cast<size_t> (0) );
}

RCP<crs_matrix_type> dstMat = Tpetra::createCrsMatrix<SC> (destRowMap);
RCP<crs_matrix_type> dstMat = Tpetra::createCrsMatrix<SC> (destRowMap, 1);
RCP<const import_type> importer = Tpetra::createImport (sourceRowMap, destRowMap);
// global row 1 in srcMat is empty: this is a null communication to dstMat
dstMat->doImport (*srcMat, *importer, Tpetra::INSERT);
Expand Down
2 changes: 1 addition & 1 deletion packages/tpetra/core/test/BugTests/BugTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace {
// this is what the file looks like: 1 3 4 9
RCP<const map_type> rng = Tpetra::createUniformContigMap<LO, GO>(1,comm);
RCP<const map_type> dom = Tpetra::createUniformContigMap<LO, GO>(4,comm);
RCP<crs_matrix_type> A = Tpetra::createCrsMatrix<SC, LO, GO>(rng);
RCP<crs_matrix_type> A = Tpetra::createCrsMatrix<SC, LO, GO>(rng, 4);
if (myImageID == 0) {
A->insertGlobalValues( 0, Teuchos::tuple<GO>(0,1,2,3), Teuchos::tuple<SC>(1.0,3.0,4.0,9.0) );
}
Expand Down
14 changes: 12 additions & 2 deletions packages/tpetra/core/test/CrsGraph/CrsGraph_Issue601.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,25 @@ namespace { // (anonymous)
RCP<const map_type> rowMap =
rcp (new map_type (INV, myGblRowInds (), indexBase, comm));

#ifdef TPETRA_ENABLE_DEPRECATED_CODE
Tpetra::ProfileType profileTypes[] = { Tpetra::DynamicProfile, Tpetra::StaticProfile };
#else
Tpetra::ProfileType profileTypes[] = { Tpetra::StaticProfile };
#endif // TPETRA_ENABLE_DEPRECATED_CODE
bool insertLocalEntryValues[] = { true, false };

// Test both dynamic and static profile.
for (Tpetra::ProfileType profileType : profileTypes) {

out << "ProfileType: "
<< ((profileType == Tpetra::DynamicProfile) ? "Dynamic" : "Static")
out << "ProfileType: ";
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
out << ((profileType == Tpetra::DynamicProfile) ?
"Dynamic" :
"Static")
<< "Profile" << endl;
#else
out << "StaticProfile" << endl;
#endif // TPETRA_ENABLE_DEPRECATED_CODE
Teuchos::OSTab tab2 (out);

// Test both with no local entries before globalAssemble(), and
Expand Down
44 changes: 36 additions & 8 deletions packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ namespace {
return determineLocalTriangularStructure (G_lcl, lclRowMap, lclColMap, true);
}

#ifdef TPETRA_ENABLE_DEPRECATED_CODE
using Tpetra::DynamicProfile;
#endif // TPETRA_ENABLE_DEPRECATED_CODE
using Tpetra::ProfileType;
using Tpetra::StaticProfile;
using Teuchos::arcp;
Expand Down Expand Up @@ -303,8 +305,11 @@ namespace {
params->set ("compute local triangular constants", true);
}

// create dynamic-profile graph, fill-complete without inserting (and therefore, without allocating)
GRPH graph (map, 3, DynamicProfile);
// create graph (used to be DynamicProfile, before that was
// deprecated), fill-complete without inserting (and therefore,
// without allocating)
GRPH graph (map, 3);

for (GO i = map->getMinGlobalIndex(); i <= map->getMaxGlobalIndex(); ++i) {
graph.insertGlobalIndices (i, tuple<GO> (i));
}
Expand Down Expand Up @@ -443,9 +448,19 @@ namespace {
}

for (int T=0; T<4; ++T) {
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
ProfileType pftype = ( (T & 1) == 1 ) ? StaticProfile : DynamicProfile;
#else
ProfileType pftype = StaticProfile;
#endif // TPETRA_ENABLE_DEPRECATED_CODE

params->set("Optimize Storage",((T & 2) == 2));
GRAPH trigraph(rmap,cmap, ginds.size(),pftype); // only allocate as much room as necessary
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
GRAPH trigraph(rmap,cmap, ginds.size(), pftype);
#else
GRAPH trigraph(rmap,cmap, ginds.size());
#endif // TPETRA_ENABLE_DEPRECATED_CODE

Array<GO> GCopy(4); Array<LO> LCopy(4);
ArrayView<const GO> GView;
ArrayView<const LO> LView;
Expand Down Expand Up @@ -837,7 +852,13 @@ namespace {
GO mymiddle = map->getGlobalElement(1); // get my middle row

for (int T=0; T<4; ++T) {
ProfileType pftype = ( (T & 1) == 1 ) ? StaticProfile : DynamicProfile;
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
ProfileType pftype = ( (T & 1) == 1 ) ?
StaticProfile : DynamicProfile;
#else
ProfileType pftype = StaticProfile;
#endif // TPETRA_ENABLE_DEPRECATED_CODE

RCP<ParameterList> params = parameterList ();
params->set("Optimize Storage",((T & 2) == 2));

Expand Down Expand Up @@ -937,10 +958,17 @@ namespace {
}
Teuchos::OSTab tab1 (out);

for (ProfileType pftype : {StaticProfile, DynamicProfile}) {
const ProfileType profileTypes[] = {
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
DynamicProfile,
#endif // TPETRA_ENABLE_DEPRECATED_CODE
StaticProfile
};

for (ProfileType pftype : profileTypes) {
out << "ProfileType: "
<< (pftype == StaticProfile ? "StaticProfile" : "DynamicProfile")
<< endl;
<< (pftype == StaticProfile ? "StaticProfile" :
"DynamicProfile") << endl;
Teuchos::OSTab tab2 (out);
for (bool optimizeStorage : {false, true}) {
out << "Optimize Storage: " << (optimizeStorage ? "true" : "false")
Expand Down Expand Up @@ -1043,7 +1071,7 @@ namespace {
ArrayView<const GO> myrow_gbl;
ngraph.getGlobalRowView (myrowind, myrow_gbl);
TEST_EQUALITY_CONST( myrow_gbl.size(),
( numProcs == 1 && pftype == DynamicProfile ? 3 : 1 ));
( numProcs == 1 && pftype == StaticProfile ? 1 : 3 ));

// after globalAssemble(), storage should be maxed out
out << "Calling globalAssemble()" << endl;
Expand Down
15 changes: 14 additions & 1 deletion packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@

namespace { // (anonymous)
using Tpetra::TestingUtilities::getDefaultComm;
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
using Tpetra::DynamicProfile;
#endif // TPETRA_ENABLE_DEPRECATED_CODE
using Tpetra::ProfileType;
using Tpetra::StaticProfile;
using Teuchos::arcp;
Expand Down Expand Up @@ -137,12 +139,14 @@ namespace { // (anonymous)
GRAPH graph(map,1,StaticProfile);
graph.fillComplete();
}
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
{
// create dynamic-profile graph, fill-complete without inserting
// (and therefore, without allocating)
GRAPH graph(map,1,DynamicProfile);
graph.fillComplete();
}
#endif // TPETRA_ENABLE_DEPRECATED_CODE

int lclSuccess = success ? 1 : 0;
int gblSuccess = 1;
Expand Down Expand Up @@ -456,7 +460,12 @@ namespace { // (anonymous)
RCP<const map_type> map = rcp (new map_type (INVALID, 1, 0, comm));
RCP<ParameterList> params = parameterList();
{
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
GRAPH graph(map,map,0,DynamicProfile);
#else
GRAPH graph(map,map,1,StaticProfile);
#endif // TPETRA_ENABLE_DEPRECATED_CODE

TEST_EQUALITY_CONST( graph.isFillActive(), true );
TEST_EQUALITY_CONST( graph.isFillComplete(), false );
graph.insertLocalIndices( 0, tuple<LO>(0) );
Expand All @@ -471,7 +480,12 @@ namespace { // (anonymous)
TEST_THROW( graph.fillComplete(), std::runtime_error );
}
{
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
GRAPH graph(map,map,0,DynamicProfile);
#else
GRAPH graph(map,map,1,StaticProfile);
#endif // TPETRA_ENABLE_DEPRECATED_CODE

TEST_EQUALITY_CONST( graph.isFillActive(), true );
TEST_EQUALITY_CONST( graph.isFillComplete(), false );
graph.insertLocalIndices( 0, tuple<LO>(0) );
Expand Down Expand Up @@ -681,4 +695,3 @@ namespace { // (anonymous)
TPETRA_INSTANTIATE_LGN( UNIT_TEST_GROUP_DEBUG_AND_RELEASE )

} // namespace (anonymous)

Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,6 @@ using Teuchos::VERB_HIGH;
using Teuchos::VERB_LOW;
using Teuchos::VERB_MEDIUM;
using Teuchos::VERB_NONE;
using Tpetra::DynamicProfile;
using Tpetra::ProfileType;
using Tpetra::StaticProfile;
using Tpetra::TestingUtilities::getDefaultComm;
typedef Tpetra::global_size_t GST;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,13 @@ namespace { // (anonymous)
// Buffer for storing output of getGlobalRowCopy.
Teuchos::Array<GO> gblColIndsBuf (maxNumEntPerRow);

#ifdef TPETRA_ENABLE_DEPRECATED_CODE
const Tpetra::ProfileType profileTypes[2] =
{Tpetra::DynamicProfile, Tpetra::StaticProfile};
#else
const Tpetra::ProfileType profileTypes[1] =
{Tpetra::StaticProfile};
#endif // TPETRA_ENABLE_DEPRECATED_CODE
for (auto profileType_src : profileTypes) {
crs_graph_type graph_src (rowMap_src, maxNumEntPerRow, profileType_src);
for (LO lclRow = 0; lclRow < lclNumRows; ++lclRow) {
Expand Down Expand Up @@ -191,5 +196,3 @@ namespace { // (anonymous)
TPETRA_INSTANTIATE_LGN( UNIT_TEST_GROUP )

} // namespace (anonymous)


Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ namespace {
using Tpetra::createUniformContigMapWithNode;
using Tpetra::createVector;
using Tpetra::createCrsMatrix;
using Tpetra::ProfileType;
using Tpetra::StaticProfile;
using Tpetra::DynamicProfile;
using Tpetra::OptimizeOption;
using Tpetra::GloballyDistributed;
using Tpetra::INSERT;

TEUCHOS_STATIC_SETUP()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ namespace {
using Tpetra::createCrsMatrix;
using Tpetra::ProfileType;
using Tpetra::StaticProfile;
using Tpetra::DynamicProfile;
using Tpetra::OptimizeOption;
using Tpetra::DoOptimizeStorage;
using Tpetra::DoNotOptimizeStorage;
Expand Down Expand Up @@ -164,7 +163,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( CrsMatrix, NonlocalAfterResume, LO, GO, Scala
//----------------------------------------------------------------------
// put in diagonal, locally
//----------------------------------------------------------------------
Tpetra::CrsMatrix<Scalar,LO,GO,Node> matrix(rmap,cmap,3,DynamicProfile);
Tpetra::CrsMatrix<Scalar,LO,GO,Node> matrix(rmap,cmap,3);
for (GO r=rmap->getMinGlobalIndex(); r <= rmap->getMaxGlobalIndex(); ++r) {
matrix.insertGlobalValues(r,tuple(r),tuple(ST::one()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ namespace {
using Tpetra::createContigMapWithNode;
using Tpetra::createVector;
using Tpetra::createCrsMatrix;
using Tpetra::ProfileType;
using Tpetra::StaticProfile;
using Tpetra::DynamicProfile;
using Tpetra::OptimizeOption;
using Tpetra::DoOptimizeStorage;
using Tpetra::DoNotOptimizeStorage;
using Tpetra::GloballyDistributed;
using Tpetra::INSERT;

TEUCHOS_STATIC_SETUP()
Expand Down
6 changes: 3 additions & 3 deletions packages/tpetra/core/test/CrsMatrix/CrsMatrix_UnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ namespace { // (anonymous)
{
RCPMap map = createContigMapWithNode<LO,GO,Node>(INVALID,numLocal,comm);
MV mv(map,1);
zero = rcp( new MAT(map,0,Tpetra::DynamicProfile) );
zero = rcp( new MAT(map,0) );
TEST_THROW(zero->apply(mv,mv), std::runtime_error);
#ifndef TPETRA_ENABLE_DEPRECATED_CODE
# if defined(HAVE_TPETRA_THROW_EFFICIENCY_WARNINGS)
// throw exception because we required increased allocation
TEST_THROW(zero->insertGlobalValues(map->getMinGlobalIndex(),tuple<GO>(0),tuple<Scalar>(ST::one())), std::runtime_error);
# endif
TEST_ASSERT( zero->getProfileType() == Tpetra::DynamicProfile );
#endif // TPETRA_ENABLE_DEPRECATED_CODE
zero->fillComplete();
}
STD_TESTS((*zero));
Expand Down Expand Up @@ -187,7 +188,6 @@ namespace { // (anonymous)
for (size_t i=0; i<numLocal; ++i) {
eye_crs->insertGlobalValues(base+i,tuple<GO>(base+i),tuple<Scalar>(ST::one()));
}
TEST_ASSERT( eye_crs->getProfileType() == Tpetra::DynamicProfile );
eye_crs->fillComplete();
eye = eye_crs;
}
Expand Down
9 changes: 4 additions & 5 deletions packages/tpetra/core/test/CrsMatrix/CrsMatrix_UnitTests2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ namespace {
using Tpetra::createCrsMatrix;
using Tpetra::ProfileType;
using Tpetra::StaticProfile;
using Tpetra::DynamicProfile;
using Tpetra::OptimizeOption;
using Tpetra::DoOptimizeStorage;
using Tpetra::DoNotOptimizeStorage;
Expand Down Expand Up @@ -261,14 +260,16 @@ inline void tupleToArray(Array<T> &arr, const tuple &tup)
RCP<const map_type> lclmap = createLocalMapWithNode<LO,GO,Node> (P, comm);

// create the matrix
MAT A(rowmap,P,DynamicProfile);
MAT A(rowmap,P);
for (GO i=0; i<static_cast<GO>(M); ++i) {
for (GO j=0; j<static_cast<GO>(P); ++j) {
A.insertGlobalValues( M*myImageID+i, tuple<GO>(j), tuple<Scalar>(M*myImageID+i + j*M*N) );
}
}
// call fillComplete()
TEST_EQUALITY_CONST( A.getProfileType() == DynamicProfile, true );
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
TEST_ASSERT( A.getProfileType() == Tpetra::DynamicProfile );
#endif // TPETRA_ENABLE_DEPRECATED_CODE
A.fillComplete(lclmap,rowmap);
// build the input multivector X
MV X(lclmap,numVecs);
Expand Down Expand Up @@ -631,5 +632,3 @@ inline void tupleToArray(Array<T> &arr, const tuple &tup)
TPETRA_INSTANTIATE_SLGN( UNIT_TEST_GROUP )

}


Loading

0 comments on commit ad792be

Please sign in to comment.