Skip to content

Commit

Permalink
Merge pull request #7811 from cgcgcg/sphynxInitialGuess
Browse files Browse the repository at this point in the history
Zoltan2 Sphynx: Add options for initial guess and full/partial ortho
  • Loading branch information
seheracer authored Aug 9, 2020
2 parents 6779e05 + f77cb0b commit 52b9c81
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
43 changes: 36 additions & 7 deletions packages/zoltan2/sphynx/src/Zoltan2_Sphynx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ namespace Zoltan2 {
bool isHermitian = true;
bool relLockTol = false;
bool lock = false;
bool useFullOrtho = true;

// Information to output in a verbose run
int numfailed = 0;
Expand All @@ -534,6 +535,10 @@ namespace Zoltan2 {
if (pe)
maxIterations = pe->getValue<int>(&maxIterations);

pe = params_->getEntryPtr("sphynx_use_full_ortho");
if (pe)
useFullOrtho = pe->getValue<bool>(&useFullOrtho);


// Set Anasazi verbosity level
int anasaziVerbosity = Anasazi::Errors + Anasazi::Warnings;
Expand All @@ -558,14 +563,38 @@ namespace Zoltan2 {
anasaziParams.set("Orthogonalization", ortho);
anasaziParams.set("Use Locking", lock);
anasaziParams.set("Relative Locking Tolerance", relLockTol);

anasaziParams.set("Full Ortho", useFullOrtho);

// Create and set initial vectors
RCP<mvector_t> ivec( new mvector_t(laplacian_->getRangeMap(), numEigenVectors));
Anasazi::MultiVecTraits<scalar_t, mvector_t>::MvRandom(*ivec);
for (size_t i = 0; i < ivec->getLocalLength(); i++)
ivec->replaceLocalValue(i,0,1.);

std::string initialGuess = params_->get("sphynx_initial_guess", "random");
if (initialGuess == "random") {
// 0-th vector constant 1, rest random
Anasazi::MultiVecTraits<scalar_t, mvector_t>::MvRandom(*ivec);
ivec->getVectorNonConst(0)->putScalar(1.);
}
else if (initialGuess == "constants") {
// 0-th vector constant 1, other vectors constant per block
// Create numEigenVectors blocks, but only use numEigenVectors-1 of them.
// This assures orthogonality.
ivec->getVectorNonConst(0)->putScalar(1.);
for (int j = 1; j < numEigenVectors; j++)
ivec->getVectorNonConst(j)->putScalar(0.);

auto map = laplacian_->getRangeMap();
gno_t blockSize = map->getGlobalNumElements() / numEigenVectors;
TEUCHOS_TEST_FOR_EXCEPTION(blockSize <= 0, std::runtime_error, "Blocksize too small for \"constants\" initial guess. Try \"random\".");

for (size_t lid = 0; lid < ivec->getLocalLength(); lid++) {
gno_t gid = map->getGlobalElement(lid);
for (int j = 1; j < numEigenVectors; j++){
if (((j-1)*blockSize <= gid) && (j*blockSize > gid))
ivec->replaceLocalValue(lid,j,1.);
}
}
}
else
TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unknown value for \"sphynx_initial_guess\": " << initialGuess);

// Create the eigenproblem to be solved
using problem_t = Anasazi::BasicEigenproblem<scalar_t, mvector_t, op_t>;
Expand Down Expand Up @@ -665,7 +694,7 @@ namespace Zoltan2 {
Teuchos::ParameterList smootherParamList;
smootherParamList.set("chebyshev: degree", 3);
smootherParamList.set("chebyshev: ratio eigenvalue", 7.0);
smootherParamList.set("chebyshev: eigenvalue max iterations", 100);
smootherParamList.set("chebyshev: eigenvalue max iterations", 10);
paramList.set("smoother: params", smootherParamList);
paramList.set("use kokkos refactor", false);

Expand All @@ -678,7 +707,7 @@ namespace Zoltan2 {
Teuchos::ParameterList coarseParamList;
coarseParamList.set("chebyshev: degree", 3);
coarseParamList.set("chebyshev: ratio eigenvalue", 7.0);
coarseParamList.set("chebyshev: eigenvalue max iterations", 100);
coarseParamList.set("chebyshev: eigenvalue max iterations", 10);
paramList.set("coarse: params", coarseParamList);

paramList.set("max levels", 5);
Expand Down
24 changes: 24 additions & 0 deletions packages/zoltan2/test/sphynx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ TRIBITS_ADD_TEST(
)


TRIBITS_ADD_TEST(
Sphynx
NAME Sphynx_ConstantsInitialGuess
NUM_MPI_PROCS 4
COMM serial mpi
ARGS
"--inputFile=simple --initialGuess=constants"
PASS_REGULAR_EXPRESSION "PASS"
FAIL_REGULAR_EXPRESSION "FAIL"
)


TRIBITS_ADD_TEST(
Sphynx
NAME Sphynx_PartialOrtho
NUM_MPI_PROCS 4
COMM serial mpi
ARGS
"--inputFile=simple --partialOrtho"
PASS_REGULAR_EXPRESSION "PASS"
FAIL_REGULAR_EXPRESSION "FAIL"
)


IF(Trilinos_ENABLE_Galeri)
TRIBITS_ADD_TEST(
Sphynx
Expand Down
8 changes: 8 additions & 0 deletions packages/zoltan2/test/sphynx/Test_Sphynx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ int main(int narg, char** arg)
bool isNormalized = false;
bool isGeneralized = false;
bool usePoly = false;
std::string initialGuess = "random";
bool useFullOrtho = true;

////// Establish session.
Tpetra::ScopeGuard tscope(&narg, &arg);
Expand Down Expand Up @@ -145,6 +147,10 @@ int main(int narg, char** arg)
"indicate whether or not to use a generalized Laplacian.");
cmdp.setOption("polynomial", "muelu", &usePoly,
"indicate whether or not to use polynomial as preconditioner.");
cmdp.setOption("initialGuess", &initialGuess,
"Initial guess for LOBPCG");
cmdp.setOption("useFullOrtho", "partialOrtho", &useFullOrtho,
"Use full orthogonalization.");

//////////////////////////////////
// Even with cmdp option "true", I get errors for having these
Expand Down Expand Up @@ -216,6 +222,8 @@ int main(int narg, char** arg)
params->set("sphynx_skip_preprocessing", true); // Preprocessing has not been implemented yet.
params->set("sphynx_preconditioner_poly", usePoly);
params->set("sphynx_verbosity", verbose ? 1 : 0);
params->set("sphynx_initial_guess", initialGuess);
params->set("sphynx_use_full_ortho", useFullOrtho);
std::string problemType = "combinatorial";
if(isNormalized)
problemType = "normalized";
Expand Down

0 comments on commit 52b9c81

Please sign in to comment.