82 #ifndef AMESOS2_FACTORY_HPP
83 #define AMESOS2_FACTORY_HPP
85 #include "Amesos2_config.h"
87 #include "Amesos2_Solver.hpp"
90 #include "Teuchos_ScalarTraits.hpp"
92 #include "Amesos2_MatrixTraits.hpp"
95 #ifdef HAVE_AMESOS2_BASKER
96 #include "Amesos2_Basker.hpp"
99 #ifdef HAVE_AMESOS2_SHYLUBASKER
100 #include "Amesos2_ShyLUBasker.hpp"
103 #if defined(HAVE_AMESOS2_KLU2)
104 #include "Amesos2_KLU2.hpp"
107 #ifdef HAVE_AMESOS2_SUPERLUDIST // Distributed-memory SuperLU
108 #include "Amesos2_Superludist.hpp"
111 #ifdef HAVE_AMESOS2_SUPERLUMT // Multi-threaded SuperLU
112 #include "Amesos2_Superlumt.hpp"
115 #ifdef HAVE_AMESOS2_UMFPACK // Umfpack
116 #include "Amesos2_Umfpack.hpp"
119 #ifdef HAVE_AMESOS2_TACHO // Tacho
120 #include "Amesos2_Tacho.hpp"
123 #ifdef HAVE_AMESOS2_SUPERLU // Sequential SuperLU
124 #include "Amesos2_Superlu.hpp"
127 #ifdef HAVE_AMESOS2_PARDISO_MKL // MKL version of Pardiso
128 #include "Amesos2_PardisoMKL.hpp"
131 #ifdef HAVE_AMESOS2_LAPACK
132 #include "Amesos2_Lapack.hpp"
135 #if defined (HAVE_AMESOS2_CHOLMOD) && defined (HAVE_AMESOS2_EXPERIMENTAL)
136 #include "Amesos2_Cholmod.hpp"
139 #ifdef HAVE_AMESOS2_MUMPS
140 #include "Amesos2_MUMPS.hpp"
146 template <
class,
class>
class Solver;
151 std::string tolower(
const std::string& s);
168 template <
class Matrix,
170 Solver<Matrix,Vector>*
171 create(
const Matrix* A, Vector* X,
const Vector* B);
188 template <
class Matrix,
190 Teuchos::RCP<Solver<Matrix,Vector> >
191 create(Teuchos::RCP<const Matrix> A,
192 Teuchos::RCP<Vector> X,
193 Teuchos::RCP<const Vector> B);
213 template <
class Matrix,
215 Solver<Matrix,Vector>*
216 create(
const char* solverName,
const Matrix* A, Vector* X,
const Vector* B);
235 template <
class Matrix,
237 Teuchos::RCP<Solver<Matrix,Vector> >
238 create(
const char* solverName,
239 const Teuchos::RCP<const Matrix> A,
240 const Teuchos::RCP<Vector> X,
241 const Teuchos::RCP<const Vector> B);
260 template <
class Matrix,
262 Solver<Matrix,Vector>*
263 create(
const std::string solverName,
const Matrix* A, Vector* X,
const Vector* B);
282 template <
class Matrix,
284 Teuchos::RCP<Solver<Matrix,Vector> >
285 create(
const std::string solverName,
286 const Teuchos::RCP<const Matrix> A,
287 const Teuchos::RCP<Vector> X,
288 const Teuchos::RCP<const Vector> B);
309 template <
class Matrix,
311 Solver<Matrix,Vector>*
312 create(
const std::string solverName,
const Matrix* A);
333 template <
class Matrix,
335 Teuchos::RCP<Solver<Matrix,Vector> >
336 create(
const std::string solverName,
337 const Teuchos::RCP<const Matrix> A);
344 template <
template <
class,
class>
class ConcreteSolver,
347 struct create_solver_with_supported_type {
348 static Teuchos::RCP<Solver<Matrix,Vector> > apply(Teuchos::RCP<const Matrix> A,
349 Teuchos::RCP<Vector> X,
350 Teuchos::RCP<const Vector> B )
354 typename MatrixTraits<Matrix>::scalar_t,
355 typename MultiVecAdapter<Vector>::scalar_t
357 > same_scalar_assertion;
358 (void)same_scalar_assertion;
361 return rcp(
new ConcreteSolver<Matrix,Vector>(A, X, B) );
373 template <
template <
class,
class>
class ConcreteSolver,
376 struct throw_no_scalar_support_exception {
377 static Teuchos::RCP<Solver<Matrix,Vector> > apply(Teuchos::RCP<const Matrix> A,
378 Teuchos::RCP<Vector> X,
379 Teuchos::RCP<const Vector> B )
382 typedef typename MatrixTraits<Matrix>::scalar_t scalar_t;
383 TEUCHOS_TEST_FOR_EXCEPTION(
true,
384 std::invalid_argument,
385 "The requested Amesos2 "
387 " solver interface does not support the " <<
388 Teuchos::ScalarTraits<scalar_t>::name() <<
402 template <
template <
class,
class>
class ConcreteSolver,
405 struct handle_solver_type_support {
406 static Teuchos::RCP<Solver<Matrix,Vector> > apply(Teuchos::RCP<const Matrix> A,
407 Teuchos::RCP<Vector> X,
408 Teuchos::RCP<const Vector> B )
410 return Meta::if_then_else<
411 solver_supports_scalar<ConcreteSolver, typename MatrixTraits<Matrix>::scalar_t>::value,
412 create_solver_with_supported_type<ConcreteSolver,Matrix,Vector>,
413 throw_no_scalar_support_exception<ConcreteSolver,Matrix,Vector> >::type::apply(A, X, B);
429 bool query(
const char* solverName);
439 bool query(
const std::string solverName);
446 template <
class Matrix,
448 Solver<Matrix,Vector>*
449 create(Matrix* A, Vector* X, Vector* B)
451 std::string solver =
"Klu2";
453 return( create(solver, rcp(A,
false), rcp(X,
false), rcp(B,
false)).getRawPtr() );
457 template <
class Matrix,
459 Teuchos::RCP<Solver<Matrix,Vector> >
460 create(Teuchos::RCP<const Matrix> A,
461 Teuchos::RCP<Vector> X,
462 Teuchos::RCP<const Vector> B)
464 std::string solver =
"Klu2";
465 return( create(solver, A, X, B) );
469 template <
class Matrix,
471 Solver<Matrix,Vector>*
472 create(
const char* solverName,
const Matrix* A, Vector* X,
const Vector* B)
474 std::string solver = solverName;
476 return( create(solver, rcp(A,
false), rcp(X,
false), rcp(B,
false)).getRawPtr() );
480 template <
class Matrix,
482 Teuchos::RCP<Solver<Matrix,Vector> >
483 create(
const char* solverName,
484 const Teuchos::RCP<const Matrix> A,
485 const Teuchos::RCP<Vector> X,
486 const Teuchos::RCP<const Vector> B)
488 std::string solver = solverName;
489 return( create(solver, A, X, B) );
493 template <
class Matrix,
495 Solver<Matrix,Vector>*
496 create(
const std::string solverName,
const Matrix* A){
497 return( create(solverName, rcp(A,
false),
498 Teuchos::RCP<Vector>(),
499 Teuchos::RCP<const Vector>()).getRawPtr() );
503 template <
class Matrix,
505 Teuchos::RCP<Solver<Matrix,Vector> >
506 create(
const std::string solverName,
const Teuchos::RCP<const Matrix> A){
507 return( create(solverName, A, Teuchos::RCP<Vector>(), Teuchos::RCP<const Vector>()) );
511 template <
class Matrix,
513 Teuchos::RCP<Solver<Matrix,Vector> >
514 create(
const std::string solverName,
const Matrix* A, Vector* X,
const Vector* B)
517 return( create(solverName, rcp(A,
false), rcp(X,
false), rcp(B,
false)) );
521 template <
class Matrix,
523 Teuchos::RCP<Solver<Matrix,Vector> >
524 create(
const std::string solver_name,
525 const Teuchos::RCP<const Matrix> A,
526 const Teuchos::RCP<Vector> X,
527 const Teuchos::RCP<const Vector> B)
529 std::string solverName = tolower(solver_name);
534 #ifdef HAVE_AMESOS2_SHYLUBASKER
535 if((solverName ==
"ShyLUBasker") || (solverName ==
"shylubasker") || (solverName ==
"amesos2_shylubasker"))
537 return handle_solver_type_support<ShyLUBasker, Matrix,Vector>::apply(A,X,B);
541 #ifdef HAVE_AMESOS2_BASKER
542 if((solverName ==
"Basker") || (solverName ==
"basker") || (solverName ==
"amesos2_basker"))
544 return handle_solver_type_support<Basker, Matrix,Vector>::apply(A,X,B);
549 #ifdef HAVE_AMESOS2_KLU2
550 if((solverName ==
"amesos2_klu2") || (solverName ==
"klu2") ||
551 (solverName ==
"amesos2_klu") || (solverName ==
"klu")){
552 return handle_solver_type_support<KLU2,Matrix,Vector>::apply(A, X, B);
556 #ifdef HAVE_AMESOS2_SUPERLUDIST
557 if((solverName ==
"amesos2_superludist") ||
558 (solverName ==
"superludist") ||
559 (solverName ==
"amesos2_superlu_dist") ||
560 (solverName ==
"superlu_dist")){
561 return handle_solver_type_support<Superludist,Matrix,Vector>::apply(A, X, B);
565 #ifdef HAVE_AMESOS2_SUPERLUMT
566 if((solverName ==
"amesos2_superlumt") ||
567 (solverName ==
"superlumt") ||
568 (solverName ==
"amesos2_superlu_mt") ||
569 (solverName ==
"superlu_mt")){
570 return handle_solver_type_support<Superlumt,Matrix,Vector>::apply(A, X, B);
574 #ifdef HAVE_AMESOS2_UMFPACK
575 if((solverName ==
"amesos2_umfpack") ||
576 (solverName ==
"umfpack")){
577 return handle_solver_type_support<Umfpack,Matrix,Vector>::apply(A, X, B);
581 #ifdef HAVE_AMESOS2_TACHO
582 if((solverName ==
"amesos2_tacho") ||
583 (solverName ==
"tacho")){
584 return handle_solver_type_support<TachoSolver,Matrix,Vector>::apply(A, X, B);
588 #ifdef HAVE_AMESOS2_SUPERLU
589 if((solverName ==
"amesos2_superlu") ||
590 (solverName ==
"superlu")){
591 return handle_solver_type_support<Superlu,Matrix,Vector>::apply(A, X, B);
595 #ifdef HAVE_AMESOS2_PARDISO_MKL
596 if((solverName ==
"amesos2_pardiso_mkl") ||
597 (solverName ==
"pardiso_mkl") ||
598 (solverName ==
"amesos2_pardisomkl") ||
599 (solverName ==
"pardisomkl")){
600 return handle_solver_type_support<PardisoMKL,Matrix,Vector>::apply(A, X, B);
604 #ifdef HAVE_AMESOS2_LAPACK
605 if((solverName ==
"amesos2_lapack") ||
606 (solverName ==
"lapack")){
607 return handle_solver_type_support<Lapack,Matrix,Vector>::apply(A, X, B);
612 #ifdef HAVE_AMESOS2_MUMPS
613 if((solverName ==
"MUMPS") || (solverName ==
"mumps") ||
614 (solverName ==
"amesos2_MUMPS") || (solverName ==
"amesos2_mumps"))
616 return handle_solver_type_support<MUMPS,Matrix,Vector>::apply(A,X,B);
620 #if defined (HAVE_AMESOS2_CHOLMOD) && defined (HAVE_AMESOS2_EXPERIMENTAL)
621 if(solverName ==
"amesos2_cholmod")
622 return handle_solver_type_support<Cholmod,Matrix,Vector>::apply(A, X, B);
629 std::string err_msg = solver_name +
" is not enabled or is not supported";
630 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument, err_msg);
636 #endif // AMESOS2_FACTORY_HPP
A templated adapter/wrapper class for Trilinos Multivector type classes. Provides the functions neces...
Simple compile-time assertion class.
Provides access to interesting solver traits.