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 #if defined (HAVE_AMESOS2_CUSOLVER) && defined (HAVE_AMESOS2_CUSPARSE)
140 #include "Amesos2_cuSOLVER.hpp"
143 #ifdef HAVE_AMESOS2_MUMPS
144 #include "Amesos2_MUMPS.hpp"
150 template <
class,
class>
class Solver;
155 std::string tolower(
const std::string& s);
172 template <
class Matrix,
174 Solver<Matrix,Vector>*
175 create(
const Matrix* A, Vector* X,
const Vector* B);
192 template <
class Matrix,
194 Teuchos::RCP<Solver<Matrix,Vector> >
195 create(Teuchos::RCP<const Matrix> A,
196 Teuchos::RCP<Vector> X,
197 Teuchos::RCP<const Vector> B);
217 template <
class Matrix,
219 Solver<Matrix,Vector>*
220 create(
const char* solverName,
const Matrix* A, Vector* X,
const Vector* B);
239 template <
class Matrix,
241 Teuchos::RCP<Solver<Matrix,Vector> >
242 create(
const char* solverName,
243 const Teuchos::RCP<const Matrix> A,
244 const Teuchos::RCP<Vector> X,
245 const Teuchos::RCP<const Vector> B);
264 template <
class Matrix,
266 Solver<Matrix,Vector>*
267 create(
const std::string solverName,
const Matrix* A, Vector* X,
const Vector* B);
286 template <
class Matrix,
288 Teuchos::RCP<Solver<Matrix,Vector> >
289 create(
const std::string solverName,
290 const Teuchos::RCP<const Matrix> A,
291 const Teuchos::RCP<Vector> X,
292 const Teuchos::RCP<const Vector> B);
313 template <
class Matrix,
315 Solver<Matrix,Vector>*
316 create(
const std::string solverName,
const Matrix* A);
337 template <
class Matrix,
339 Teuchos::RCP<Solver<Matrix,Vector> >
340 create(
const std::string solverName,
341 const Teuchos::RCP<const Matrix> A);
348 template <
template <
class,
class>
class ConcreteSolver,
351 struct create_solver_with_supported_type {
352 static Teuchos::RCP<Solver<Matrix,Vector> > apply(Teuchos::RCP<const Matrix> A,
353 Teuchos::RCP<Vector> X,
354 Teuchos::RCP<const Vector> B )
358 typename MatrixTraits<Matrix>::scalar_t,
359 typename MultiVecAdapter<Vector>::scalar_t
361 > same_scalar_assertion;
362 (void)same_scalar_assertion;
365 return rcp(
new ConcreteSolver<Matrix,Vector>(A, X, B) );
377 template <
template <
class,
class>
class ConcreteSolver,
380 struct throw_no_scalar_support_exception {
381 static Teuchos::RCP<Solver<Matrix,Vector> > apply(Teuchos::RCP<const Matrix> A,
382 Teuchos::RCP<Vector> X,
383 Teuchos::RCP<const Vector> B )
386 typedef typename MatrixTraits<Matrix>::scalar_t scalar_t;
387 TEUCHOS_TEST_FOR_EXCEPTION(
true,
388 std::invalid_argument,
389 "The requested Amesos2 "
391 " solver interface does not support the " <<
392 Teuchos::ScalarTraits<scalar_t>::name() <<
397 template <
template <
class,
class>
class ConcreteSolver,
400 struct throw_no_matrix_support_exception {
401 static Teuchos::RCP<Solver<Matrix,Vector> > apply(Teuchos::RCP<const Matrix> A,
402 Teuchos::RCP<Vector> X,
403 Teuchos::RCP<const Vector> B )
405 TEUCHOS_TEST_FOR_EXCEPTION(
true,
406 std::invalid_argument,
407 "This solver does not support the kokkos adapter." );
420 template <
template <
class,
class>
class ConcreteSolver,
423 struct handle_solver_scalar_type_support {
424 static Teuchos::RCP<Solver<Matrix,Vector> > apply(Teuchos::RCP<const Matrix> A,
425 Teuchos::RCP<Vector> X,
426 Teuchos::RCP<const Vector> B )
428 return Meta::if_then_else<
429 solver_supports_scalar<ConcreteSolver, typename MatrixTraits<Matrix>::scalar_t>::value,
430 create_solver_with_supported_type<ConcreteSolver,Matrix,Vector>,
431 throw_no_scalar_support_exception<ConcreteSolver,Matrix,Vector> >::type::apply(A, X, B);
444 template <
template <
class,
class>
class ConcreteSolver,
447 struct handle_solver_matrix_and_type_support {
448 static Teuchos::RCP<Solver<Matrix,Vector> > apply(Teuchos::RCP<const Matrix> A,
449 Teuchos::RCP<Vector> X,
450 Teuchos::RCP<const Vector> B )
452 return Meta::if_then_else<
453 solver_supports_matrix<ConcreteSolver, Matrix>::value,
454 handle_solver_scalar_type_support<ConcreteSolver,Matrix,Vector>,
455 throw_no_matrix_support_exception<ConcreteSolver,Matrix,Vector> >::type::apply(A, X, B);
470 bool query(
const char* solverName);
480 bool query(
const std::string solverName);
487 template <
class Matrix,
489 Solver<Matrix,Vector>*
490 create(Matrix* A, Vector* X, Vector* B)
492 std::string solver =
"Klu2";
494 return( create(solver, rcp(A,
false), rcp(X,
false), rcp(B,
false)).getRawPtr() );
498 template <
class Matrix,
500 Teuchos::RCP<Solver<Matrix,Vector> >
501 create(Teuchos::RCP<const Matrix> A,
502 Teuchos::RCP<Vector> X,
503 Teuchos::RCP<const Vector> B)
505 std::string solver =
"Klu2";
506 return( create(solver, A, X, B) );
510 template <
class Matrix,
512 Solver<Matrix,Vector>*
513 create(
const char* solverName,
const Matrix* A, Vector* X,
const Vector* B)
515 std::string solver = solverName;
517 return( create(solver, rcp(A,
false), rcp(X,
false), rcp(B,
false)).getRawPtr() );
521 template <
class Matrix,
523 Teuchos::RCP<Solver<Matrix,Vector> >
524 create(
const char* solverName,
525 const Teuchos::RCP<const Matrix> A,
526 const Teuchos::RCP<Vector> X,
527 const Teuchos::RCP<const Vector> B)
529 std::string solver = solverName;
530 return( create(solver, A, X, B) );
534 template <
class Matrix,
536 Solver<Matrix,Vector>*
537 create(
const std::string solverName,
const Matrix* A){
538 return( create(solverName, rcp(A,
false),
539 Teuchos::RCP<Vector>(),
540 Teuchos::RCP<const Vector>()).getRawPtr() );
544 template <
class Matrix,
546 Teuchos::RCP<Solver<Matrix,Vector> >
547 create(
const std::string solverName,
const Teuchos::RCP<const Matrix> A){
548 return( create(solverName, A, Teuchos::RCP<Vector>(), Teuchos::RCP<const Vector>()) );
552 template <
class Matrix,
554 Teuchos::RCP<Solver<Matrix,Vector> >
555 create(
const std::string solverName,
const Matrix* A, Vector* X,
const Vector* B)
558 return( create(solverName, rcp(A,
false), rcp(X,
false), rcp(B,
false)) );
562 template <
class Matrix,
564 Teuchos::RCP<Solver<Matrix,Vector> >
565 create(
const std::string solver_name,
566 const Teuchos::RCP<const Matrix> A,
567 const Teuchos::RCP<Vector> X,
568 const Teuchos::RCP<const Vector> B)
570 std::string solverName = tolower(solver_name);
575 #ifdef HAVE_AMESOS2_SHYLUBASKER
576 if((solverName ==
"ShyLUBasker") || (solverName ==
"shylubasker") || (solverName ==
"amesos2_shylubasker"))
578 return handle_solver_matrix_and_type_support<ShyLUBasker, Matrix,Vector>::apply(A,X,B);
582 #ifdef HAVE_AMESOS2_BASKER
583 if((solverName ==
"Basker") || (solverName ==
"basker") || (solverName ==
"amesos2_basker"))
585 return handle_solver_matrix_and_type_support<Basker, Matrix,Vector>::apply(A,X,B);
590 #ifdef HAVE_AMESOS2_KLU2
591 if((solverName ==
"amesos2_klu2") || (solverName ==
"klu2") ||
592 (solverName ==
"amesos2_klu") || (solverName ==
"klu")){
593 return handle_solver_matrix_and_type_support<KLU2,Matrix,Vector>::apply(A, X, B);
597 #ifdef HAVE_AMESOS2_SUPERLUDIST
598 if((solverName ==
"amesos2_superludist") ||
599 (solverName ==
"superludist") ||
600 (solverName ==
"amesos2_superlu_dist") ||
601 (solverName ==
"superlu_dist")){
602 return handle_solver_matrix_and_type_support<Superludist,Matrix,Vector>::apply(A, X, B);
606 #ifdef HAVE_AMESOS2_SUPERLUMT
607 if((solverName ==
"amesos2_superlumt") ||
608 (solverName ==
"superlumt") ||
609 (solverName ==
"amesos2_superlu_mt") ||
610 (solverName ==
"superlu_mt")){
611 return handle_solver_matrix_and_type_support<Superlumt,Matrix,Vector>::apply(A, X, B);
615 #ifdef HAVE_AMESOS2_UMFPACK
616 if((solverName ==
"amesos2_umfpack") ||
617 (solverName ==
"umfpack")){
618 return handle_solver_matrix_and_type_support<Umfpack,Matrix,Vector>::apply(A, X, B);
622 #ifdef HAVE_AMESOS2_TACHO
623 if((solverName ==
"amesos2_tacho") ||
624 (solverName ==
"tacho")){
625 return handle_solver_matrix_and_type_support<TachoSolver,Matrix,Vector>::apply(A, X, B);
630 #ifdef HAVE_AMESOS2_SUPERLU
631 if((solverName ==
"amesos2_superlu") ||
632 (solverName ==
"superlu")){
633 return handle_solver_matrix_and_type_support<Superlu,Matrix,Vector>::apply(A, X, B);
637 #ifdef HAVE_AMESOS2_PARDISO_MKL
638 if((solverName ==
"amesos2_pardiso_mkl") ||
639 (solverName ==
"pardiso_mkl") ||
640 (solverName ==
"amesos2_pardisomkl") ||
641 (solverName ==
"pardisomkl")){
642 return handle_solver_matrix_and_type_support<PardisoMKL,Matrix,Vector>::apply(A, X, B);
646 #ifdef HAVE_AMESOS2_LAPACK
647 if((solverName ==
"amesos2_lapack") ||
648 (solverName ==
"lapack")){
649 return handle_solver_matrix_and_type_support<Lapack,Matrix,Vector>::apply(A, X, B);
654 #ifdef HAVE_AMESOS2_MUMPS
655 if((solverName ==
"MUMPS") || (solverName ==
"mumps") ||
656 (solverName ==
"amesos2_MUMPS") || (solverName ==
"amesos2_mumps"))
658 return handle_solver_matrix_and_type_support<MUMPS,Matrix,Vector>::apply(A,X,B);
662 #if defined (HAVE_AMESOS2_CHOLMOD) && defined (HAVE_AMESOS2_EXPERIMENTAL)
663 if(solverName ==
"amesos2_cholmod" || solverName ==
"cholmod")
664 return handle_solver_matrix_and_type_support<Cholmod,Matrix,Vector>::apply(A, X, B);
667 #if defined (HAVE_AMESOS2_CUSOLVER) && defined (HAVE_AMESOS2_CUSPARSE)
668 if(solverName ==
"amesos2_cusolver" || solverName ==
"cusolver")
669 return handle_solver_matrix_and_type_support<cuSOLVER,Matrix,Vector>::apply(A, X, B);
676 std::string err_msg = solver_name +
" is not enabled or is not supported";
677 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument, err_msg);
683 #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.