53 #ifndef AMESOS2_SOLVERCORE_DEF_HPP 54 #define AMESOS2_SOLVERCORE_DEF_HPP 56 #include "Amesos2_MatrixAdapter_def.hpp" 57 #include "Amesos2_MultiVecAdapter_def.hpp" 65 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
67 Teuchos::RCP<const Matrix> A,
68 Teuchos::RCP<Vector> X,
69 Teuchos::RCP<const Vector> B )
70 : matrixA_(createConstMatrixAdapter<Matrix>(A))
73 , globalNumRows_(matrixA_->getGlobalNumRows())
74 , globalNumCols_(matrixA_->getGlobalNumCols())
75 , globalNumNonZeros_(matrixA_->getGlobalNNZ())
76 , rowIndexBase_(matrixA_->getRowIndexBase())
77 , columnIndexBase_(matrixA_->getColumnIndexBase())
78 , rank_(
Teuchos::rank(*this->getComm()))
80 , nprocs_(
Teuchos::size(*this->getComm()))
82 TEUCHOS_TEST_FOR_EXCEPTION(
84 std::invalid_argument,
85 "Matrix shape inappropriate for this solver");
90 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
97 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
101 #ifdef HAVE_AMESOS2_TIMERS 102 Teuchos::TimeMonitor LocalTimer1(
timers_.totalTime_);
107 static_cast<solver_type*
>(
this)->preOrdering_impl();
115 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
119 #ifdef HAVE_AMESOS2_TIMERS 120 Teuchos::TimeMonitor LocalTimer1(
timers_.totalTime_);
130 static_cast<solver_type*
>(
this)->symbolicFactorization_impl();
138 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
142 #ifdef HAVE_AMESOS2_TIMERS 143 Teuchos::TimeMonitor LocalTimer1(
timers_.totalTime_);
153 static_cast<solver_type*
>(
this)->numericFactorization_impl();
161 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
168 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
171 const Teuchos::Ptr<const Vector> B)
const 173 #ifdef HAVE_AMESOS2_TIMERS 174 Teuchos::TimeMonitor LocalTimer1(
timers_.totalTime_);
180 const Teuchos::RCP<MultiVecAdapter<Vector> > x =
181 createMultiVecAdapter<Vector>(Teuchos::rcpFromPtr(X));
182 const Teuchos::RCP<const MultiVecAdapter<Vector> > b =
183 createConstMultiVecAdapter<Vector>(Teuchos::rcpFromPtr(B));
185 #ifdef HAVE_AMESOS2_DEBUG 187 TEUCHOS_TEST_FOR_EXCEPTION(x->getGlobalLength() !=
matrixA_->getGlobalNumCols(),
188 std::invalid_argument,
189 "MultiVector X must have length equal to the number of " 190 "global columns in A");
192 TEUCHOS_TEST_FOR_EXCEPTION(b->getGlobalLength() !=
matrixA_->getGlobalNumRows(),
193 std::invalid_argument,
194 "MultiVector B must have length equal to the number of " 197 TEUCHOS_TEST_FOR_EXCEPTION(x->getGlobalNumVectors() != b->getGlobalNumVectors(),
198 std::invalid_argument,
199 "X and B MultiVectors must have the same number of vectors");
200 #endif // HAVE_AMESOS2_DEBUG 208 static_cast<const solver_type*
>(
this)->solve_impl(Teuchos::outArg(*x), Teuchos::ptrInArg(*b));
213 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
217 solve(Teuchos::ptr(X), Teuchos::ptr(B));
220 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
224 #ifdef HAVE_AMESOS2_TIMERS 225 Teuchos::TimeMonitor LocalTimer1(
timers_.totalTime_);
228 return( static_cast<solver_type*>(
this)->matrixShapeOK_impl() );
234 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
239 matrixA_ = createConstMatrixAdapter(a);
241 #ifdef HAVE_AMESOS2_DEBUG 242 TEUCHOS_TEST_FOR_EXCEPTION( (keep_phase != CLEAN) &&
245 std::invalid_argument,
246 "Dimensions of new matrix be the same as the old matrix if " 247 "keeping any solver phase" );
273 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
276 const Teuchos::RCP<Teuchos::ParameterList> & parameterList )
278 #ifdef HAVE_AMESOS2_TIMERS 279 Teuchos::TimeMonitor LocalTimer1(
timers_.totalTime_);
282 if( parameterList->name() ==
"Amesos2" ){
285 parameterList->validateParameters(*valid_params);
288 control_.setControlParameters(parameterList);
292 if( parameterList->isSublist(
name()) ){
295 control_.setControlParameters(Teuchos::sublist(parameterList,
name()));
297 static_cast<solver_type*
>(
this)->setParameters_impl(Teuchos::sublist(parameterList,
name()));
305 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
306 Teuchos::RCP<const Teuchos::ParameterList>
309 #ifdef HAVE_AMESOS2_TIMERS 310 Teuchos::TimeMonitor LocalTimer1(
timers_.totalTime_ );
313 using Teuchos::ParameterList;
317 RCP<ParameterList> control_params = rcp(
new ParameterList(
"Amesos2 Control"));
318 control_params->set(
"Transpose",
false,
"Whether to solve with the matrix transpose");
324 RCP<const ParameterList>
325 solver_params =
static_cast<const solver_type*
>(
this)->getValidParameters_impl();
327 Teuchos::rcp_const_cast<ParameterList>(solver_params)->
set(
"Transpose",
false,
328 "Whether to solve with the " 331 RCP<ParameterList> amesos2_params = rcp(
new ParameterList(
"Amesos2"));
332 amesos2_params->setParameters(*control_params);
333 amesos2_params->set(
name(), *solver_params);
335 return amesos2_params;
339 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
343 std::ostringstream oss;
344 oss <<
name() <<
" solver interface";
349 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
352 Teuchos::FancyOStream &out,
353 const Teuchos::EVerbosityLevel verbLevel)
const 358 using Teuchos::VERB_DEFAULT;
359 using Teuchos::VERB_NONE;
360 using Teuchos::VERB_LOW;
361 using Teuchos::VERB_MEDIUM;
362 using Teuchos::VERB_HIGH;
363 using Teuchos::VERB_EXTREME;
364 Teuchos::EVerbosityLevel vl = verbLevel;
365 if (vl == VERB_DEFAULT) vl = VERB_LOW;
366 Teuchos::RCP<const Teuchos::Comm<int> > comm = this->
getComm();
371 width = std::max<size_t>(width,size_t(11)) + 2;
372 Teuchos::OSTab tab(out);
380 if( vl != VERB_NONE ) {
381 std::string p =
name();
383 out << this->
description() << std::endl << std::endl;
385 out << p <<
"Matrix has " << globalNumRows_ <<
"rows" 388 if( vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME ){
389 out << p <<
"Nonzero elements per row = " 392 out << p <<
"Percentage of nonzero elements = " 396 if( vl == VERB_HIGH || vl == VERB_EXTREME ){
397 out << p <<
"Use transpose = " <<
control_.useTranspose_
400 if ( vl == VERB_EXTREME ){
408 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
411 Teuchos::FancyOStream &out,
412 const Teuchos::EVerbosityLevel verbLevel)
const 416 double preTime =
timers_.preOrderTime_.totalElapsedTime();
417 double symTime =
timers_.symFactTime_.totalElapsedTime();
418 double numTime =
timers_.numFactTime_.totalElapsedTime();
419 double solTime =
timers_.solveTime_.totalElapsedTime();
420 double totTime =
timers_.totalTime_.totalElapsedTime();
421 double overhead = totTime - (preTime + symTime + numTime + solTime);
423 std::string p =
name() +
" : ";
426 if(verbLevel != Teuchos::VERB_NONE)
428 out << p <<
"Time to convert matrix to implementation format = " 429 <<
timers_.mtxConvTime_.totalElapsedTime() <<
" (s)" 431 out << p <<
"Time to redistribute matrix = " 432 <<
timers_.mtxRedistTime_.totalElapsedTime() <<
" (s)" 435 out << p <<
"Time to convert vectors to implementation format = " 436 <<
timers_.vecConvTime_.totalElapsedTime() <<
" (s)" 438 out << p <<
"Time to redistribute vectors = " 439 <<
timers_.vecRedistTime_.totalElapsedTime() <<
" (s)" 442 out << p <<
"Number of pre-orderings = " 445 out << p <<
"Time for pre-ordering = " 446 << preTime <<
" (s), avg = " 450 out << p <<
"Number of symbolic factorizations = " 453 out << p <<
"Time for sym fact = " 454 << symTime <<
" (s), avg = " 458 out << p <<
"Number of numeric factorizations = " 461 out << p <<
"Time for num fact = " 462 << numTime <<
" (s), avg = " 466 out << p <<
"Number of solve phases = " 469 out << p <<
"Time for solve = " 470 << solTime <<
" (s), avg = " 474 out << p <<
"Total time spent in Amesos2 = " 477 out << p <<
"Total time spent in the Amesos2 interface = " 478 << overhead <<
" (s)" 480 out << p <<
" (the above time does not include solver time)" 482 out << p <<
"Amesos2 interface time / total time = " 483 << overhead / totTime
490 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
493 Teuchos::ParameterList& timingParameterList)
const 495 Teuchos::ParameterList temp;
496 timingParameterList = temp.setName(
"NULL");
500 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
504 std::string solverName = solver_type::name;
508 template <
template <
class,
class>
class ConcreteSolver,
class Matrix,
class Vector >
512 matrix_loaded_ =
static_cast<solver_type*
>(
this)->loadA_impl(current_phase);
518 #endif // AMESOS2_SOLVERCORE_DEF_HPP int getNumNumericFact() const
Returns the number of numeric factorizations performed by the owning solver.
Definition: Amesos2_Status.hpp:102
~SolverCore()
Destructor.
Definition: Amesos2_SolverCore_def.hpp:91
int getNumSymbolicFact() const
Returns the number of symbolic factorizations performed by the owning solver.
Definition: Amesos2_Status.hpp:98
int getNumPreOrder() const
Returns the number of pre-orderings performed by the owning solver.
Definition: Amesos2_Status.hpp:94
void setA(const Teuchos::RCP< const Matrix > a, EPhase keep_phase=CLEAN)
Sets the matrix A of this solver.
Definition: Amesos2_SolverCore_def.hpp:236
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
EPhase last_phase_
The last phase of computation that was performed by the owning solver object.
Definition: Amesos2_Status.hpp:146
global_size_type globalNumCols_
Number of global columns in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:479
void printTiming(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints timing information about the current solver.
Definition: Amesos2_SolverCore_def.hpp:410
int numNumericFact_
Number of numeric factorization phases.
Definition: Amesos2_Status.hpp:140
global_size_type globalNumRows_
Number of global rows in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:476
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Definition: Amesos2_SolverCore_def.hpp:351
Utility functions for Amesos2.
std::string name() const
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:502
Control control_
Parameters for solving.
Definition: Amesos2_SolverCore_decl.hpp:495
bool matrixShapeOK()
Returns true if the solver can handle this matrix shape.
Definition: Amesos2_SolverCore_def.hpp:222
int numPreOrder_
Number of pre-ordering phases.
Definition: Amesos2_Status.hpp:134
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a const parameter list of all of the valid parameters that this->setParameterList(...) will accept.
Definition: Amesos2_SolverCore_def.hpp:307
super_type & preOrdering()
Pre-orders the matrix A for minimal fill-in.
Definition: Amesos2_SolverCore_def.hpp:99
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_SolverCore_def.hpp:341
SolverCore(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
Initialize a Solver instance.
Definition: Amesos2_SolverCore_def.hpp:66
bool preOrderingDone() const
If true , then pre-ordering has been performed.
Definition: Amesos2_Status.hpp:110
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
bool symbolicFactorizationDone() const
If true , then symbolic factorization has been performed.
Definition: Amesos2_Status.hpp:114
void printLine(Teuchos::FancyOStream &out)
Prints a line of 70 "-"s on std::cout.
Definition: Amesos2_Util.cpp:123
void solve()
Solves (or )
Definition: Amesos2_SolverCore_def.hpp:163
super_type & numericFactorization()
Performs numeric factorization on the matrix A.
Definition: Amesos2_SolverCore_def.hpp:140
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns a pointer to the Teuchos::Comm communicator with this operator.
Definition: Amesos2_SolverCore_decl.hpp:363
bool matrix_loaded_
Definition: Amesos2_SolverCore_decl.hpp:462
int numSymbolicFact_
Number of symbolic factorization phases.
Definition: Amesos2_Status.hpp:137
void loadA(EPhase current_phase)
Refresh this solver's internal data about A.
Definition: Amesos2_SolverCore_def.hpp:510
Interface to Amesos2 solver objects.
Definition: Amesos2_Solver_decl.hpp:78
Definition: Amesos2_Cholmod_TypeMap.hpp:92
bool numericFactorizationDone() const
If true , then numeric factorization has been performed.
Definition: Amesos2_Status.hpp:118
void getTiming(Teuchos::ParameterList &timingParameterList) const
Extracts timing information from the current solver.
Definition: Amesos2_SolverCore_def.hpp:492
global_size_type globalNumNonZeros_
Number of global non-zero values in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:482
super_type & setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶meterList)
Set/update internal variables and solver options.
Definition: Amesos2_SolverCore_def.hpp:275
int numSolve_
Number of solves.
Definition: Amesos2_Status.hpp:143
int rank_
The MPI rank of this image.
Definition: Amesos2_SolverCore_decl.hpp:504
Teuchos::RCP< const Vector > multiVecB_
The RHS vector/multi-vector.
Definition: Amesos2_SolverCore_decl.hpp:473
int getNumSolve() const
Returns the number of solves performed by the owning solver.
Definition: Amesos2_Status.hpp:106
Timers timers_
Various timing statistics.
Definition: Amesos2_SolverCore_decl.hpp:498
super_type & symbolicFactorization()
Performs symbolic factorization on the matrix A.
Definition: Amesos2_SolverCore_def.hpp:117
Teuchos::RCP< Vector > multiVecX_
The LHS vector/multi-vector.
Definition: Amesos2_SolverCore_decl.hpp:466
Teuchos::RCP< const MatrixAdapter< Matrix > > matrixA_
The LHS operator.
Definition: Amesos2_SolverCore_decl.hpp:455
Status status_
Holds status information about a solver.
Definition: Amesos2_SolverCore_decl.hpp:492