Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_KLU2_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Amesos2: Templated Direct Sparse Solver Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
52 #ifndef AMESOS2_KLU2_DEF_HPP
53 #define AMESOS2_KLU2_DEF_HPP
54 
55 #include <Teuchos_Tuple.hpp>
56 #include <Teuchos_ParameterList.hpp>
57 #include <Teuchos_StandardParameterEntryValidators.hpp>
58 
60 #include "Amesos2_KLU2_decl.hpp"
61 
62 namespace Amesos2 {
63 
64 
65 template <class Matrix, class Vector>
67  Teuchos::RCP<const Matrix> A,
68  Teuchos::RCP<Vector> X,
69  Teuchos::RCP<const Vector> B )
70  : SolverCore<Amesos2::KLU2,Matrix,Vector>(A, X, B)
71  , nzvals_() // initialize to empty arrays
72  , rowind_()
73  , colptr_()
74  , transFlag_(0)
75  , is_contiguous_(true)
76 {
77  ::KLU2::klu_defaults<slu_type, local_ordinal_type> (&(data_.common_)) ;
78  data_.symbolic_ = NULL;
79  data_.numeric_ = NULL;
80 
81  // Override some default options
82  // TODO: use data_ here to init
83 }
84 
85 
86 template <class Matrix, class Vector>
88 {
89  /* Free KLU2 data_types
90  * - Matrices
91  * - Vectors
92  * - Other data
93  */
94  if (data_.symbolic_ != NULL)
95  ::KLU2::klu_free_symbolic<slu_type, local_ordinal_type>
96  (&(data_.symbolic_), &(data_.common_)) ;
97  if (data_.numeric_ != NULL)
98  ::KLU2::klu_free_numeric<slu_type, local_ordinal_type>
99  (&(data_.numeric_), &(data_.common_)) ;
100 
101  // Storage is initialized in numericFactorization_impl()
102  //if ( data_.A.Store != NULL ){
103  // destoy
104  //}
105 
106  // only root allocated these SuperMatrices.
107  //if ( data_.L.Store != NULL ){ // will only be true for this->root_
108  // destroy ..
109  //}
110 }
111 
112 template <class Matrix, class Vector>
113 bool
115  return (this->root_ && (this->matrixA_->getComm()->getSize() == 1) && is_contiguous_);
116 }
117 
118 template<class Matrix, class Vector>
119 int
121 {
122  /* TODO: Define what it means for KLU2
123  */
124 #ifdef HAVE_AMESOS2_TIMERS
125  Teuchos::TimeMonitor preOrderTimer(this->timers_.preOrderTime_);
126 #endif
127 
128  return(0);
129 }
130 
131 
132 template <class Matrix, class Vector>
133 int
135 {
136  if (data_.symbolic_ != NULL) {
137  ::KLU2::klu_free_symbolic<slu_type, local_ordinal_type>
138  (&(data_.symbolic_), &(data_.common_)) ;
139  }
140 
141  if ( single_proc_optimization() ) {
142 
143  auto sp_rowptr = this->matrixA_->returnRowPtr();
144  TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr == nullptr,
145  std::runtime_error, "Amesos2 Runtime Error: sp_rowptr returned null ");
146  auto sp_colind = this->matrixA_->returnColInd();
147  TEUCHOS_TEST_FOR_EXCEPTION(sp_colind == nullptr,
148  std::runtime_error, "Amesos2 Runtime Error: sp_colind returned null ");
149 #ifndef HAVE_TEUCHOS_COMPLEX
150  auto sp_values = this->matrixA_->returnValues();
151 #else
152  // NDE: 09/25/2017
153  // Cannot convert Kokkos::complex<T>* to std::complex<T>*; in this case, use reinterpret_cast
154  using complex_type = typename Util::getStdCplxType< magnitude_type, typename matrix_adapter_type::spmtx_vals_t >::type;
155  complex_type * sp_values = nullptr;
156  sp_values = reinterpret_cast< complex_type * > ( this->matrixA_->returnValues() );
157 #endif
158  TEUCHOS_TEST_FOR_EXCEPTION(sp_values == nullptr,
159  std::runtime_error, "Amesos2 Runtime Error: sp_values returned null ");
160 
161  // sp_rowptr can cause compile-time matching issues
162  // e.g const long unsigned int* , not convertible/compatible with int*
163  // Need sp_rowptr and sp_colind to have same ordinal type for KLU2 interface
164  Teuchos::Array< local_ordinal_type > sp_rowptr_with_common_type( this->globalNumRows_ + 1 );
165  for ( global_size_type i = 0; i < this->globalNumRows_+1; ++i ) {
166  //sp_rowptr_with_common_type[i] = static_cast<local_ordinal_type>(sp_rowptr[i]);
167  sp_rowptr_with_common_type[i] = sp_rowptr[i];
168  }
169 
170  data_.symbolic_ = ::KLU2::klu_analyze<slu_type, local_ordinal_type>
171  ((local_ordinal_type)this->globalNumCols_, sp_rowptr_with_common_type.getRawPtr(),
172  sp_colind, &(data_.common_)) ;
173  }
174  else
175  {
176  data_.symbolic_ = ::KLU2::klu_analyze<slu_type, local_ordinal_type>
177  ((local_ordinal_type)this->globalNumCols_, colptr_.getRawPtr(),
178  rowind_.getRawPtr(), &(data_.common_)) ;
179 
180  } //end single_process_optim_check = false
181 
182  return(0);
183 }
184 
185 
186 template <class Matrix, class Vector>
187 int
189 {
190  using Teuchos::as;
191 
192  // Cleanup old L and U matrices if we are not reusing a symbolic
193  // factorization. Stores and other data will be allocated in gstrf.
194  // Only rank 0 has valid pointers, TODO: for KLU2
195 
196  int info = 0;
197  if ( this->root_ ) {
198 
199  { // Do factorization
200 #ifdef HAVE_AMESOS2_TIMERS
201  Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
202 #endif
203 
204 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
205  std::cout << "KLU2:: Before numeric factorization" << std::endl;
206  std::cout << "nzvals_ : " << nzvals_.toString() << std::endl;
207  std::cout << "rowind_ : " << rowind_.toString() << std::endl;
208  std::cout << "colptr_ : " << colptr_.toString() << std::endl;
209 #endif
210 
211  if (data_.numeric_ != NULL) {
212  ::KLU2::klu_free_numeric<slu_type, local_ordinal_type>
213  (&(data_.numeric_), &(data_.common_)) ;
214  }
215 
216  if ( single_proc_optimization() ) {
217 
218  auto sp_rowptr = this->matrixA_->returnRowPtr();
219  TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr == nullptr,
220  std::runtime_error, "Amesos2 Runtime Error: sp_rowptr returned null ");
221  auto sp_colind = this->matrixA_->returnColInd();
222  TEUCHOS_TEST_FOR_EXCEPTION(sp_colind == nullptr,
223  std::runtime_error, "Amesos2 Runtime Error: sp_colind returned null ");
224 #ifndef HAVE_TEUCHOS_COMPLEX
225  auto sp_values = this->matrixA_->returnValues();
226 #else
227  // NDE: 09/25/2017
228  // Cannot convert Kokkos::complex<T>* to std::complex<T>*; in this case, use reinterpret_cast
229  using complex_type = typename Util::getStdCplxType< magnitude_type, typename matrix_adapter_type::spmtx_vals_t >::type;
230  complex_type * sp_values = nullptr;
231  sp_values = reinterpret_cast< complex_type * > ( this->matrixA_->returnValues() );
232 #endif
233  TEUCHOS_TEST_FOR_EXCEPTION(sp_values == nullptr,
234  std::runtime_error, "Amesos2 Runtime Error: sp_values returned null ");
235 
236  // sp_rowptr can cause compile-time matching issues
237  // e.g const long unsigned int* , not convertible/compatible with int*
238  // Need sp_rowptr and sp_colind to have same ordinal type for KLU2 interface
239  Teuchos::Array< local_ordinal_type > sp_rowptr_with_common_type( this->globalNumRows_ + 1 );
240  for ( global_size_type i = 0; i < this->globalNumRows_+1; ++i ) {
241  //sp_rowptr_with_common_type[i] = static_cast<local_ordinal_type>(sp_rowptr[i]);
242  sp_rowptr_with_common_type[i] = sp_rowptr[i];
243  }
244 
245  data_.numeric_ = ::KLU2::klu_factor<slu_type, local_ordinal_type>
246  (sp_rowptr_with_common_type.getRawPtr(), sp_colind, sp_values,
247  data_.symbolic_, &(data_.common_)) ;
248  }
249  else {
250  data_.numeric_ = ::KLU2::klu_factor<slu_type, local_ordinal_type>
251  (colptr_.getRawPtr(), rowind_.getRawPtr(), nzvals_.getRawPtr(),
252  data_.symbolic_, &(data_.common_)) ;
253  } //end single_process_optim_check = false
254 
255  // To have a test which confirms a throw, we need MPI to throw on all the
256  // ranks. So we delay and broadcast first. Others throws in Amesos2 which
257  // happen on just the root rank would also have the same problem if we
258  // tested them but we decided to fix just this one for the present. This
259  // is the only error/throw we currently have a unit test for.
260  if(data_.numeric_ == nullptr) {
261  info = 1;
262  }
263 
264  // This is set after numeric factorization complete as pivoting can be used;
265  // In this case, a discrepancy between symbolic and numeric nnz total can occur.
266  if(info == 0) { // skip if error code so we don't segfault - will throw
267  this->setNnzLU( as<size_t>((data_.numeric_)->lnz) + as<size_t>((data_.numeric_)->unz) );
268  }
269  } // end scope
270 
271  } // end this->root_
272 
273  /* All processes should have the same error code */
274  Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
275 
276  TEUCHOS_TEST_FOR_EXCEPTION(info > 0, std::runtime_error,
277  "KLU2 numeric factorization failed");
278 
279  //global_size_type info_st = as<global_size_type>(info); // unused
280  /* TODO : Proper error messages
281  TEUCHOS_TEST_FOR_EXCEPTION( (info_st > 0) && (info_st <= this->globalNumCols_),
282  std::runtime_error,
283  "Factorization complete, but matrix is singular. Division by zero eminent");
284  TEUCHOS_TEST_FOR_EXCEPTION( (info_st > 0) && (info_st > this->globalNumCols_),
285  std::runtime_error,
286  "Memory allocation failure in KLU2 factorization");*/
287 
288  //data_.options.Fact = SLU::FACTORED;
289  //same_symbolic_ = true;
290 
291  return(info);
292 }
293 
294 
295 template <class Matrix, class Vector>
296 int
298  const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
299  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const
300 {
301  using Teuchos::as;
302  int ierr = 0; // returned error code
303 
304  const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
305  const size_t nrhs = X->getGlobalNumVectors();
306 
307  if ( single_proc_optimization() && nrhs == 1 ) {
308 #ifdef HAVE_AMESOS2_TIMERS
309  Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
310 #endif
311 
312 #ifndef HAVE_TEUCHOS_COMPLEX
313  auto b_vector = Util::vector_pointer_helper< MultiVecAdapter<Vector>, Vector >::get_pointer_to_vector( B );
314  auto x_vector = Util::vector_pointer_helper< MultiVecAdapter<Vector>, Vector >::get_pointer_to_vector( X );
315 #else
316  // NDE: 09/25/2017
317  // Cannot convert Kokkos::complex<T>* to std::complex<T>*; in this case, use reinterpret_cast
318  using complex_type = typename Util::getStdCplxType< magnitude_type, typename matrix_adapter_type::spmtx_vals_t >::type;
319  complex_type * b_vector = reinterpret_cast< complex_type * >( Util::vector_pointer_helper< MultiVecAdapter<Vector>, Vector >::get_pointer_to_vector( B ) );
320  complex_type * x_vector = reinterpret_cast< complex_type * >( Util::vector_pointer_helper< MultiVecAdapter<Vector>, Vector >::get_pointer_to_vector( X ) );
321 #endif
322  TEUCHOS_TEST_FOR_EXCEPTION(b_vector == nullptr,
323  std::runtime_error, "Amesos2 Runtime Error: b_vector returned null ");
324 
325  TEUCHOS_TEST_FOR_EXCEPTION(x_vector == nullptr,
326  std::runtime_error, "Amesos2 Runtime Error: x_vector returned null ");
327 
328  // For this case, Crs matrix raw pointers wereused, so the non-transpose default solve
329  // is actually the transpose solve as klu_solve expects Ccs matrix pointers
330  // Thus, if the transFlag_ is true, the non-transpose solve should be used
331  if (transFlag_ == 0)
332  {
333  ::KLU2::klu_tsolve2<slu_type, local_ordinal_type>
334  (data_.symbolic_, data_.numeric_,
335  (local_ordinal_type)this->globalNumCols_,
336  (local_ordinal_type)nrhs,
337  b_vector, x_vector, &(data_.common_)) ;
338  }
339  else {
340  ::KLU2::klu_solve2<slu_type, local_ordinal_type>
341  (data_.symbolic_, data_.numeric_,
342  (local_ordinal_type)this->globalNumCols_,
343  (local_ordinal_type)nrhs,
344  b_vector, x_vector, &(data_.common_)) ;
345  }
346 
347  /* All processes should have the same error code */
348  // Teuchos::broadcast(*(this->getComm()), 0, &ierr);
349 
350  } // end single_process_optim_check && nrhs == 1
351  else // single proc optimizations but nrhs > 1,
352  // or distributed over processes case
353  {
354  const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
355  Teuchos::Array<slu_type> bValues(val_store_size);
356 
357  { // Get values from RHS B
358 #ifdef HAVE_AMESOS2_TIMERS
359  Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
360  Teuchos::TimeMonitor redistTimer( this->timers_.vecRedistTime_ );
361 #endif
362  if ( is_contiguous_ == true ) {
364  slu_type>::do_get(B, bValues(),
365  as<size_t>(ld_rhs),
366  ROOTED, this->rowIndexBase_);
367  }
368  else {
370  slu_type>::do_get(B, bValues(),
371  as<size_t>(ld_rhs),
372  CONTIGUOUS_AND_ROOTED, this->rowIndexBase_);
373  }
374  } // end Timer scope
375 
376  if ( this->root_ ) {
377  //local_ordinal_type i_ld_rhs = as<local_ordinal_type>(ld_rhs);
378  { // Do solve!
379 #ifdef HAVE_AMESOS2_TIMERS
380  Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
381 #endif
382  if (transFlag_ == 0)
383  {
384  // For this case, Crs matrix raw pointers wereused, so the non-transpose default solve
385  // is actually the transpose solve as klu_solve expects Ccs matrix pointers
386  // Thus, if the transFlag_ is true, the non-transpose solve should be used
387  if ( single_proc_optimization() ) {
388  ::KLU2::klu_tsolve<slu_type, local_ordinal_type>
389  (data_.symbolic_, data_.numeric_,
390  (local_ordinal_type)this->globalNumCols_,
391  (local_ordinal_type)nrhs,
392  bValues.getRawPtr(), &(data_.common_)) ;
393  }
394  else {
395  ::KLU2::klu_solve<slu_type, local_ordinal_type>
396  (data_.symbolic_, data_.numeric_,
397  (local_ordinal_type)this->globalNumCols_,
398  (local_ordinal_type)nrhs,
399  bValues.getRawPtr(), &(data_.common_)) ;
400  }
401  }
402  else
403  {
404  // For this case, Crs matrix raw pointers wereused, so the non-transpose default solve
405  // is actually the transpose solve as klu_solve expects Ccs matrix pointers
406  // Thus, if the transFlag_ is true, the non-transpose solve should be used
407  if ( single_proc_optimization() ) {
408  ::KLU2::klu_solve<slu_type, local_ordinal_type>
409  (data_.symbolic_, data_.numeric_,
410  (local_ordinal_type)this->globalNumCols_,
411  (local_ordinal_type)nrhs,
412  bValues.getRawPtr(), &(data_.common_)) ;
413  }
414  else {
415  ::KLU2::klu_tsolve<slu_type, local_ordinal_type>
416  (data_.symbolic_, data_.numeric_,
417  (local_ordinal_type)this->globalNumCols_,
418  (local_ordinal_type)nrhs,
419  bValues.getRawPtr(), &(data_.common_)) ;
420  }
421  }
422  } //end Timer scope
423  } // end root_
424 
425  /* All processes should have the same error code */
426  // Teuchos::broadcast(*(this->getComm()), 0, &ierr);
427 
428  // global_size_type ierr_st = as<global_size_type>(ierr); // unused
429  // TODO
430  //TEUCHOS_TEST_FOR_EXCEPTION( ierr < 0,
431  //std::invalid_argument,
432  //"Argument " << -ierr << " to KLU2 xgssvx had illegal value" );
433  //TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0 && ierr_st <= this->globalNumCols_,
434  //std::runtime_error,
435  //"Factorization complete, but U is exactly singular" );
436  //TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0 && ierr_st > this->globalNumCols_ + 1,
437  //std::runtime_error,
438  //"KLU2 allocated " << ierr - this->globalNumCols_ << " bytes of "
439  //"memory before allocation failure occured." );
440 
441  /* Update X's global values */
442  {
443 #ifdef HAVE_AMESOS2_TIMERS
444  Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
445 #endif
446 
447  if ( is_contiguous_ == true ) {
449  MultiVecAdapter<Vector>,slu_type>::do_put(X, bValues(),
450  as<size_t>(ld_rhs),
451  ROOTED, this->rowIndexBase_);
452  }
453  else {
455  MultiVecAdapter<Vector>,slu_type>::do_put(X, bValues(),
456  as<size_t>(ld_rhs),
457  CONTIGUOUS_AND_ROOTED, this->rowIndexBase_);
458  }
459  } // end Timer scope
460  } //end else
461 
462  return(ierr);
463 }
464 
465 
466 template <class Matrix, class Vector>
467 bool
469 {
470  // The KLU2 factorization routines can handle square as well as
471  // rectangular matrices, but KLU2 can only apply the solve routines to
472  // square matrices, so we check the matrix for squareness.
473  return( this->matrixA_->getGlobalNumRows() == this->matrixA_->getGlobalNumCols() );
474 }
475 
476 
477 template <class Matrix, class Vector>
478 void
479 KLU2<Matrix,Vector>::setParameters_impl(const Teuchos::RCP<Teuchos::ParameterList> & parameterList )
480 {
481  using Teuchos::RCP;
482  using Teuchos::getIntegralValue;
483  using Teuchos::ParameterEntryValidator;
484 
485  RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
486 
487  transFlag_ = this->control_.useTranspose_ ? 1: 0;
488  // The KLU2 transpose option can override the Amesos2 option
489  if( parameterList->isParameter("Trans") ){
490  RCP<const ParameterEntryValidator> trans_validator = valid_params->getEntry("Trans").validator();
491  parameterList->getEntry("Trans").setValidator(trans_validator);
492 
493  transFlag_ = getIntegralValue<int>(*parameterList, "Trans");
494  }
495 
496  if( parameterList->isParameter("IsContiguous") ){
497  is_contiguous_ = parameterList->get<bool>("IsContiguous");
498  }
499 }
500 
501 
502 template <class Matrix, class Vector>
503 Teuchos::RCP<const Teuchos::ParameterList>
505 {
506  using std::string;
507  using Teuchos::tuple;
508  using Teuchos::ParameterList;
509  using Teuchos::setStringToIntegralParameter;
510 
511  static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
512 
513  if( is_null(valid_params) )
514  {
515  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
516 
517  pl->set("Equil", true, "Whether to equilibrate the system before solve, does nothing now");
518  pl->set("IsContiguous", true, "Whether GIDs contiguous");
519 
520  setStringToIntegralParameter<int>("Trans", "NOTRANS",
521  "Solve for the transpose system or not",
522  tuple<string>("NOTRANS","TRANS","CONJ"),
523  tuple<string>("Solve with transpose",
524  "Do not solve with transpose",
525  "Solve with the conjugate transpose"),
526  tuple<int>(0, 1, 2),
527  pl.getRawPtr());
528  valid_params = pl;
529  }
530 
531  return valid_params;
532 }
533 
534 
535 template <class Matrix, class Vector>
536 bool
538 {
539  using Teuchos::as;
540 
541  if(current_phase == SOLVE)return(false);
542 
543  if ( single_proc_optimization() ) {
544  // Do nothing in this case - Crs raw pointers will be used
545  }
546  else
547  {
548 
549 #ifdef HAVE_AMESOS2_TIMERS
550  Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
551 #endif
552 
553  // Only the root image needs storage allocated
554  if( this->root_ ){
555  nzvals_.resize(this->globalNumNonZeros_);
556  rowind_.resize(this->globalNumNonZeros_);
557  colptr_.resize(this->globalNumCols_ + 1);
558  }
559 
560  local_ordinal_type nnz_ret = 0;
561  {
562 #ifdef HAVE_AMESOS2_TIMERS
563  Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
564 #endif
565 
566  if ( is_contiguous_ == true ) {
568  MatrixAdapter<Matrix>,slu_type,local_ordinal_type,local_ordinal_type>
569  ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
570  nnz_ret, ROOTED, ARBITRARY, this->rowIndexBase_);
571  }
572  else {
574  MatrixAdapter<Matrix>,slu_type,local_ordinal_type,local_ordinal_type>
575  ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
576  nnz_ret, CONTIGUOUS_AND_ROOTED, ARBITRARY, this->rowIndexBase_);
577  }
578  }
579 
580 
581  if( this->root_ ){
582  TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->globalNumNonZeros_),
583  std::runtime_error,
584  "Did not get the expected number of non-zero vals");
585  }
586 
587  } //end else single_process_optim_check = false
588 
589  return true;
590 }
591 
592 
593 template<class Matrix, class Vector>
594 const char* KLU2<Matrix,Vector>::name = "KLU2";
595 
596 
597 } // end namespace Amesos2
598 
599 #endif // AMESOS2_KLU2_DEF_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
KLU2(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
Initialize from Teuchos::RCP.
Definition: Amesos2_KLU2_def.hpp:66
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
KLU2 specific solve.
Definition: Amesos2_KLU2_def.hpp:297
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
Amesos2 KLU2 declarations.
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_KLU2_def.hpp:537
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:266
~KLU2()
Destructor.
Definition: Amesos2_KLU2_def.hpp:87
Helper struct for getting pointers to the MV data - only used when number of vectors = 1 and single M...
Definition: Amesos2_MultiVecAdapter_decl.hpp:218
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_KLU2_def.hpp:479
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using KLU2.
Definition: Amesos2_KLU2_def.hpp:134
A generic helper class for getting a CCS representation of a Matrix.
Definition: Amesos2_Util.hpp:654
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_KLU2_def.hpp:120
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_KLU2_def.hpp:468
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
int numericFactorization_impl()
KLU2 specific numeric factorization.
Definition: Amesos2_KLU2_def.hpp:188
Amesos2 interface to the KLU2 package.
Definition: Amesos2_KLU2_decl.hpp:72
bool single_proc_optimization() const
can we optimize size_type and ordinal_type for straight pass through, also check that is_contiguous_ ...
Definition: Amesos2_KLU2_def.hpp:114
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_KLU2_def.hpp:504
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:322
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:176