52#ifndef AMESOS2_MUMPS_DEF_HPP
53#define AMESOS2_MUMPS_DEF_HPP
55#include <Teuchos_Tuple.hpp>
56#include <Teuchos_ParameterList.hpp>
57#include <Teuchos_StandardParameterEntryValidators.hpp>
60#include <Teuchos_DefaultMpiComm.hpp>
72 template <
class Matrix,
class Vector>
73 MUMPS<Matrix,Vector>::MUMPS(
74 Teuchos::RCP<const Matrix> A,
75 Teuchos::RCP<Vector> X,
76 Teuchos::RCP<const Vector> B )
78 , is_contiguous_(true)
81 typedef FunctionMap<MUMPS,scalar_type> function_map;
83 MUMPS_MATRIX_LOAD =
false;
85 MUMPS_MATRIX_LOAD_PREORDERING =
false;
89 using Teuchos::MpiComm;
92 using Teuchos::rcp_dynamic_cast;
95 mumps_par.comm_fortran = -987654;
96 RCP<const Comm<int> > matComm = this->matrixA_->
getComm();
98 TEUCHOS_TEST_FOR_EXCEPTION(
99 matComm.is_null(), std::logic_error,
"Amesos2::Comm");
100 RCP<const MpiComm<int> > matMpiComm =
101 rcp_dynamic_cast<const MpiComm<int> >(matComm);
103 TEUCHOS_TEST_FOR_EXCEPTION(
104 matMpiComm->getRawMpiComm().is_null(),
105 std::logic_error,
"Amesos2::MPI");
106 MPI_Comm rawMpiComm = (* (matMpiComm->getRawMpiComm()) )();
107 mumps_par.comm_fortran = (int) MPI_Comm_c2f(rawMpiComm);
114 function_map::mumps_c(&(mumps_par));
117 mumps_par.n = this->globalNumCols_;
120 mumps_par.icntl[0] = -1;
121 mumps_par.icntl[1] = -1;
122 mumps_par.icntl[2] = -1;
123 mumps_par.icntl[3] = 1;
124 mumps_par.icntl[4] = 0;
125 mumps_par.icntl[5] = 7;
126 mumps_par.icntl[6] = 7;
127 mumps_par.icntl[7] = 7;
128 mumps_par.icntl[8] = 1;
129 mumps_par.icntl[9] = 0;
130 mumps_par.icntl[10] = 0;
131 mumps_par.icntl[11] = 0;
132 mumps_par.icntl[12] = 0;
133 mumps_par.icntl[13] = 20;
134 mumps_par.icntl[17] = 0;
135 mumps_par.icntl[18] = 0;
136 mumps_par.icntl[19] = 0;
137 mumps_par.icntl[20] = 0;
138 mumps_par.icntl[21] = 0;
139 mumps_par.icntl[22] = 0;
140 mumps_par.icntl[23] = 0;
141 mumps_par.icntl[24] = 0;
142 mumps_par.icntl[25] = 0;
143 mumps_par.icntl[27] = 1;
144 mumps_par.icntl[28] = 0;
145 mumps_par.icntl[29] = 0;
146 mumps_par.icntl[30] = 0;
147 mumps_par.icntl[31] = 0;
148 mumps_par.icntl[32] = 0;
152 template <
class Matrix,
class Vector>
153 MUMPS<Matrix,Vector>::~MUMPS( )
156 typedef FunctionMap<MUMPS,scalar_type> function_map;
158 if(MUMPS_STRUCT ==
true)
165 if (this->rank_ < this->nprocs_) {
166 function_map::mumps_c(&(mumps_par));
171 template<
class Matrix,
class Vector>
177 #ifdef HAVE_AMESOS2_TIMERS
178 Teuchos::TimeMonitor preOrderTimer(this->
timers_.preOrderTime_);
184 template <
class Matrix,
class Vector>
186 MUMPS<Matrix,Vector>::symbolicFactorization_impl()
193 function_map::mumps_c(&(mumps_par));
200 template <
class Matrix,
class Vector>
210 #ifdef HAVE_AMESOS2_TIMERS
211 Teuchos::TimeMonitor numFactTimer(this->
timers_.numFactTime_);
216 function_map::mumps_c(&(mumps_par));
223 template <
class Matrix,
class Vector>
234 const global_size_type ld_rhs = this->
root_ ? X->getGlobalLength() : 0;
235 const size_t nrhs = X->getGlobalNumVectors();
237 const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
239 xvals_.resize(val_store_size);
240 bvals_.resize(val_store_size);
242 #ifdef HAVE_AMESOS2_TIMERS
243 Teuchos::TimeMonitor mvConvTimer(this->
timers_.vecConvTime_);
244 Teuchos::TimeMonitor redistTimer( this->
timers_.vecRedistTime_ );
247 if ( is_contiguous_ ==
true ) {
258 mumps_par.nrhs = nrhs;
259 mumps_par.lrhs = mumps_par.n;
264 mumps_par.rhs =
bvals_.getRawPtr();
267 #ifdef HAVE_AMESOS2_TIMERS
268 Teuchos::TimeMonitor solveTimer(this->
timers_.solveTime_);
271 function_map::mumps_c(&(mumps_par));
275 #ifdef HAVE_AMESOS2_TIMERS
276 Teuchos::TimeMonitor redistTimer2(this->
timers_.vecRedistTime_);
279 if ( is_contiguous_ ==
true ) {
292 MUMPS_MATRIX_LOAD_PREORDERING =
false;
297 template <
class Matrix,
class Vector>
306 template <
class Matrix,
class Vector>
311 using Teuchos::getIntegralValue;
312 using Teuchos::ParameterEntryValidator;
316 if(parameterList->isParameter(
"ICNTL(1)")){
317 mumps_par.icntl[0] = parameterList->get<
int>(
"ICNTL(1)", -1);
319 if(parameterList->isParameter(
"ICNTL(2)")){
320 mumps_par.icntl[1] = parameterList->get<
int>(
"ICNTL(2)", -1);
322 if(parameterList->isParameter(
"ICNTL(3)")){
323 mumps_par.icntl[2] = parameterList->get<
int>(
"ICNTL(3)", -1);
325 if(parameterList->isParameter(
"ICNTL(4)")){
326 mumps_par.icntl[3] = parameterList->get<
int>(
"ICNTL(4)", 1);
328 if(parameterList->isParameter(
"ICNTL(6)")){
329 mumps_par.icntl[5] = parameterList->get<
int>(
"ICNTL(6)", 0);
331 if(parameterList->isParameter(
"ICNTL(7)")){
332 mumps_par.icntl[6] = parameterList->get<
int>(
"ICNTL(7)", 7);
334 if(parameterList->isParameter(
"ICNTL(9)")){
335 mumps_par.icntl[8] = parameterList->get<
int>(
"ICNTL(9)", 1);
337 if(parameterList->isParameter(
"ICNTL(11)")){
338 mumps_par.icntl[10] = parameterList->get<
int>(
"ICNTL(11)", 0);
340 if(parameterList->isParameter(
"ICNTL(14)")){
341 mumps_par.icntl[13] = parameterList->get<
int>(
"ICNTL(14)", 20);
343 if( parameterList->isParameter(
"IsContiguous") ){
344 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
349 template <
class Matrix,
class Vector>
350 Teuchos::RCP<const Teuchos::ParameterList>
353 using Teuchos::ParameterList;
355 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
357 if( is_null(valid_params) ){
358 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
360 pl->set(
"ICNTL(1)", -1,
"See Manual" );
361 pl->set(
"ICNTL(2)", -1,
"See Manual" );
362 pl->set(
"ICNTL(3)", -1,
"See Manual" );
363 pl->set(
"ICNTL(4)", 1,
"See Manual" );
364 pl->set(
"ICNTL(6)", 0,
"See Manual" );
365 pl->set(
"ICNTL(9)", 1,
"See Manual" );
366 pl->set(
"ICNTL(11)", 0,
"See Manual" );
367 pl->set(
"ICNTL(14)", 20,
"See Manual" );
368 pl->set(
"IsContiguous",
true,
"Whether GIDs contiguous");
377 template <
class Matrix,
class Vector>
383 #ifdef HAVE_AMESOS2_TIMERS
384 Teuchos::TimeMonitor convTimer(this->
timers_.mtxConvTime_);
386 if(MUMPS_MATRIX_LOAD ==
false || (current_phase==NUMFACT && !MUMPS_MATRIX_LOAD_PREORDERING))
389 if( !MUMPS_MATRIX_LOAD && this->
root_ ){
395 local_ordinal_type nnz_ret = 0;
397 #ifdef HAVE_AMESOS2_TIMERS
398 Teuchos::TimeMonitor mtxRedistTimer( this->
timers_.mtxRedistTime_ );
401 if ( is_contiguous_ ==
true ) {
415 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->
globalNumNonZeros_),
417 "Did not get the expected number of non-zero vals");
429 if (current_phase==PREORDERING){
430 MUMPS_MATRIX_LOAD_PREORDERING =
true;
436 MUMPS_MATRIX_LOAD =
true;
440 template <
class Matrix,
class Vector>
442 MUMPS<Matrix,Vector>::ConvertToTriplet()
444 if ( !MUMPS_STRUCT ) {
446 mumps_par.n = this->globalNumCols_;
447 mumps_par.nz = this->globalNumNonZeros_;
448 mumps_par.a = (mumps_type*)malloc(mumps_par.nz *
sizeof(mumps_type));
449 mumps_par.irn = (MUMPS_INT*)malloc(mumps_par.nz *
sizeof(MUMPS_INT));
450 mumps_par.jcn = (MUMPS_INT*)malloc(mumps_par.nz *
sizeof(MUMPS_INT));
452 if((mumps_par.a == NULL) || (mumps_par.irn == NULL)
453 || (mumps_par.jcn == NULL))
459 local_ordinal_type tri_count = 0;
460 local_ordinal_type i,j;
461 local_ordinal_type max_local_ordinal = 0;
463 for(i = 0; i < (local_ordinal_type)this->globalNumCols_; i++)
465 for( j = host_col_ptr_view_(i); j < host_col_ptr_view_(i+1)-1; j++)
467 mumps_par.jcn[tri_count] = (MUMPS_INT)i+1;
468 mumps_par.irn[tri_count] = (MUMPS_INT)host_rows_view_(j)+1;
469 mumps_par.a[tri_count] = host_nzvals_view_(j);
474 j = host_col_ptr_view_(i+1)-1;
475 mumps_par.jcn[tri_count] = (MUMPS_INT)i+1;
476 mumps_par.irn[tri_count] = (MUMPS_INT)host_rows_view_(j)+1;
477 mumps_par.a[tri_count] = host_nzvals_view_(j);
481 if(host_rows_view_(j) > max_local_ordinal)
483 max_local_ordinal = host_rows_view_(j);
486 TEUCHOS_TEST_FOR_EXCEPTION(std::numeric_limits<MUMPS_INT>::max() <= max_local_ordinal,
488 "Matrix index larger than MUMPS_INT");
493 template<
class Matrix,
class Vector>
495 MUMPS<Matrix,Vector>::MUMPS_ERROR()
const
499 bool Wrong = ((mumps_par.info[0] != 0) || (mumps_par.infog[0] != 0)) && (this->rank_ < this->nprocs_);
501 if (this->rank_==0) {
502 std::cerr <<
"Amesos_Mumps : ERROR" << std::endl;
503 std::cerr <<
"Amesos_Mumps : INFOG(1) = " << mumps_par.infog[0] << std::endl;
504 std::cerr <<
"Amesos_Mumps : INFOG(2) = " << mumps_par.infog[1] << std::endl;
506 if (mumps_par.info[0] != 0 && Wrong) {
507 std::cerr <<
"Amesos_Mumps : On process " << this->matrixA_->getComm()->getRank()
508 <<
", INFO(1) = " << mumps_par.info[0] << std::endl;
509 std::cerr <<
"Amesos_Mumps : On process " << this->matrixA_->getComm()->getRank()
510 <<
", INFO(2) = " << mumps_par.info[1] << std::endl;
516 int WrongInt = Wrong;
517 RCP<const Comm<int> > matComm = this->matrixA_->getComm();
518 Teuchos::broadcast<int,int>(*matComm,0,1,&WrongInt);
519 TEUCHOS_TEST_FOR_EXCEPTION(WrongInt>0,
526 template<
class Matrix,
class Vector>
527 const char* MUMPS<Matrix,Vector>::name =
"MUMPS";
Amesos2 MUMPS declarations.
@ ROOTED
Definition Amesos2_TypeDecl.hpp:127
@ CONTIGUOUS_AND_ROOTED
Definition Amesos2_TypeDecl.hpp:128
@ ARBITRARY
Definition Amesos2_TypeDecl.hpp:143
Amesos2 interface to the MUMPS package.
Definition Amesos2_MUMPS_decl.hpp:85
Teuchos::Array< mumps_type > xvals_
Persisting 1D store for X.
Definition Amesos2_MUMPS_decl.hpp:223
host_ordinal_type_view host_rows_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition Amesos2_MUMPS_decl.hpp:218
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition Amesos2_MUMPS_def.hpp:379
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition Amesos2_MUMPS_def.hpp:299
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
MUMPS specific solve.
Definition Amesos2_MUMPS_def.hpp:225
host_value_type_view host_nzvals_view_
Stores the values of the nonzero entries for MUMPS.
Definition Amesos2_MUMPS_decl.hpp:216
host_ordinal_type_view host_col_ptr_view_
Stores the row indices of the nonzero entries.
Definition Amesos2_MUMPS_decl.hpp:220
int numericFactorization_impl()
MUMPS specific numeric factorization.
Definition Amesos2_MUMPS_def.hpp:202
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition Amesos2_MUMPS_def.hpp:173
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition Amesos2_MUMPS_def.hpp:351
Teuchos::Array< mumps_type > bvals_
Persisting 1D store for B.
Definition Amesos2_MUMPS_decl.hpp:225
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > ¶meterList)
Definition Amesos2_MUMPS_def.hpp:308
A Matrix adapter interface for Amesos2.
Definition Amesos2_MatrixAdapter_decl.hpp:76
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers.
Definition Amesos2_SolverCore_decl.hpp:106
Teuchos::RCP< const MatrixAdapter< Matrix > > matrixA_
Definition Amesos2_SolverCore_decl.hpp:455
bool root_
Definition Amesos2_SolverCore_decl.hpp:506
global_size_type rowIndexBase_
Definition Amesos2_SolverCore_decl.hpp:485
global_size_type globalNumCols_
Definition Amesos2_SolverCore_decl.hpp:479
Timers timers_
Definition Amesos2_SolverCore_decl.hpp:497
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
global_size_type globalNumNonZeros_
Definition Amesos2_SolverCore_decl.hpp:482
global_size_type globalNumRows_
Definition Amesos2_SolverCore_decl.hpp:476
EPhase
Used to indicate a phase in the direct solution.
Definition Amesos2_TypeDecl.hpp:65
Passes functions to TPL functions based on type.
Definition Amesos2_FunctionMap.hpp:77
A templated MultiVector class adapter for Amesos2.
Definition Amesos2_MultiVecAdapter_decl.hpp:176
Helper class for getting 1-D copies of multivectors.
Definition Amesos2_MultiVecAdapter_decl.hpp:267
A generic helper class for getting a CCS representation of a Matrix.
Definition Amesos2_Util.hpp:652
Helper class for putting 1-D data arrays into multivectors.
Definition Amesos2_MultiVecAdapter_decl.hpp:373