Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Basker_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 
53 #ifndef AMESOS2_BASKER_DEF_HPP
54 #define AMESOS2_BASKER_DEF_HPP
55 
56 #include <Teuchos_Tuple.hpp>
57 #include <Teuchos_ParameterList.hpp>
58 #include <Teuchos_StandardParameterEntryValidators.hpp>
59 
61 #include "Amesos2_Basker_decl.hpp"
62 
63 namespace Amesos2 {
64 
65 
66 template <class Matrix, class Vector>
67 Basker<Matrix,Vector>::Basker(
68  Teuchos::RCP<const Matrix> A,
69  Teuchos::RCP<Vector> X,
70  Teuchos::RCP<const Vector> B )
71  : SolverCore<Amesos2::Basker,Matrix,Vector>(A, X, B)
72  , nzvals_() // initialize to empty arrays
73  , rowind_()
74  , colptr_()
75  , is_contiguous_(true)
76 {
77 
78  //Nothing
79 
80  // Override some default options
81  // TODO: use data_ here to init
82 
83 
84 #ifdef SHYLUBASKER
85 #ifdef HAVE_AMESOS2_KOKKOS
86 #ifdef KOKKOS_HAVE_OPENMP
87  /*
88  static_assert(std::is_same<kokkos_exe,Kokkos::OpenMP>::value,
89  "Kokkos node type not supported by experimental Basker Amesos2");
90  */
91  typedef Kokkos::OpenMP Exe_Space;
92 #elif defined(KOKKOS_HAVE_SERIAL)
93  typedef Kokkos::Serial Exe_Space;
94 #else
95  TEUCHOS_TEST_FOR_EXCEPTION(1 != 0,
96  std::runtime_error,
97  "Amesos2_Basker Exception: Do not have supported Kokkos node type for Basker");
98 #endif
99  basker = new ::BaskerNS::BaskerTrilinosInterface<local_ordinal_type, slu_type, Exe_Space>();
100  basker->Options.no_pivot = BASKER_TRUE;
101  basker->Options.symmetric = BASKER_FALSE;
102  basker->Options.realloc = BASKER_FALSE;
103  basker->Options.verbose = BASKER_FALSE;
104  basker->Options.matching = BASKER_TRUE;
105  basker->Options.matching_type = 0;
106  basker->Options.btf = BASKER_TRUE;
107  basker->Options.amd_btf = BASKER_TRUE;
108  basker->Options.amd_dom = BASKER_TRUE;
109  basker->Options.transpose = BASKER_FALSE;
110  basker->Options.verbose_matrix_out = BASKER_FALSE;
111  num_threads = Kokkos::OpenMP::max_hardware_threads();
112 #endif
113 #endif
114 
115 }
116 
117 
118 template <class Matrix, class Vector>
119 Basker<Matrix,Vector>::~Basker( )
120 {
121 #ifdef SHYLUBASKER
122 #ifdef HAVE_AMESOS2_KOKKOS
123  delete basker;
124 #endif
125 #endif
126 
127  /* Basker will cleanup its own internal memory*/
128 }
129 
130 template<class Matrix, class Vector>
131 int
133 {
134  /* TODO: Define what it means for Basker
135  */
136 #ifdef HAVE_AMESOS2_TIMERS
137  Teuchos::TimeMonitor preOrderTimer(this->timers_.preOrderTime_);
138 #endif
139 
140  return(0);
141 }
142 
143 
144 template <class Matrix, class Vector>
145 int
147 {
148 #ifdef SHYLUBASKER
149 
150  if(this->root_)
151  {
152  int info = 0;
153 
154  //std::cout << "setting number of threads "
155  // << num_threads << std::endl;
156  basker->SetThreads(num_threads);
157  //std::cout << "Set Threads Done" << std::endl;
158 
159  #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
160  std::cout << "Basker:: Before symbolic factorization" << std::endl;
161  std::cout << "nzvals_ : " << nzvals_.toString() << std::endl;
162  std::cout << "rowind_ : " << rowind_.toString() << std::endl;
163  std::cout << "colptr_ : " << colptr_.toString() << std::endl;
164  #endif
165 
166  // NDE: Special case
167  // Rather than going through the Amesos2 machinery to convert the matrixA_ CRS pointer data to CCS and store in Teuchos::Arrays,
168  // in this special case we pass the CRS raw pointers directly to ShyLUBasker which copies+transposes+sorts the data for CCS format
169  // loadA_impl is essentially an empty function in this case, as the raw pointers are handled here and similarly in Symbolic
170 
171 #ifndef HAVE_TEUCHOS_COMPLEX
172  bool case_check = ( (this->matrixA_->getComm()->getRank() == 0) && (this->matrixA_->getComm()->getSize() == 1) && is_contiguous_ ) ;
173  if ( case_check ) {
174 
175  // this needs to be checked during loadA_impl...
176  auto sp_rowptr = this->matrixA_->returnRowPtr();
177  TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr == nullptr,
178  std::runtime_error, "Amesos2 Runtime Error: sp_rowptr returned null ");
179  auto sp_colind = this->matrixA_->returnColInd();
180  TEUCHOS_TEST_FOR_EXCEPTION(sp_colind == nullptr,
181  std::runtime_error, "Amesos2 Runtime Error: sp_colind returned null ");
182  auto sp_values = this->matrixA_->returnValues();
183  TEUCHOS_TEST_FOR_EXCEPTION(sp_values == nullptr,
184  std::runtime_error, "Amesos2 Runtime Error: sp_values returned null ");
185 
186  // In this case, colptr_, rowind_, nzvals_ are invalid
187  info = basker->Symbolic(this->globalNumRows_,
188  this->globalNumCols_,
189  this->globalNumNonZeros_,
190  sp_rowptr,
191  sp_colind,
192  sp_values,
193  true);
194  }
195  else
196 #endif
197  { //follow original code path if conditions not met
198  // In this case, loadA_impl updates colptr_, rowind_, nzvals_
199  info = basker->Symbolic(this->globalNumRows_,
200  this->globalNumCols_,
201  this->globalNumNonZeros_,
202  colptr_.getRawPtr(),
203  rowind_.getRawPtr(),
204  nzvals_.getRawPtr());
205  }
206  TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
207  std::runtime_error, "Error in Basker Symbolic");
208 
209  }
210 #endif
211 
212  /*No symbolic factoriztion*/
213  return(0);
214 }
215 
216 
217 template <class Matrix, class Vector>
218 int
220 {
221  using Teuchos::as;
222 
223  int info = 0;
224  if ( this->root_ ){
225  { // Do factorization
226  #ifdef HAVE_AMESOS2_TIMERS
227  Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
228  #endif
229 
230  #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
231  std::cout << "Basker:: Before numeric factorization" << std::endl;
232  std::cout << "nzvals_ : " << nzvals_.toString() << std::endl;
233  std::cout << "rowind_ : " << rowind_.toString() << std::endl;
234  std::cout << "colptr_ : " << colptr_.toString() << std::endl;
235  #endif
236 
237 
238 #ifdef SHYLUBASKER
239  // NDE: Special case
240  // Rather than going through the Amesos2 machinery to convert the matrixA_ CRS pointer data to CCS and store in Teuchos::Arrays,
241  // in this special case we pass the CRS raw pointers directly to ShyLUBasker which copies+transposes+sorts the data for CCS format
242  // loadA_impl is essentially an empty function in this case, as the raw pointers are handled here and similarly in Symbolic
243 
244 #ifndef HAVE_TEUCHOS_COMPLEX
245  bool case_check = ( (this->matrixA_->getComm()->getRank() == 0) && (this->matrixA_->getComm()->getSize() == 1) && is_contiguous_ ) ;
246  if ( case_check ) {
247 
248  auto sp_rowptr = this->matrixA_->returnRowPtr();
249  TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr == nullptr,
250  std::runtime_error, "Amesos2 Runtime Error: sp_rowptr returned null ");
251  auto sp_colind = this->matrixA_->returnColInd();
252  TEUCHOS_TEST_FOR_EXCEPTION(sp_colind == nullptr,
253  std::runtime_error, "Amesos2 Runtime Error: sp_colind returned null ");
254  auto sp_values = this->matrixA_->returnValues();
255  TEUCHOS_TEST_FOR_EXCEPTION(sp_values == nullptr,
256  std::runtime_error, "Amesos2 Runtime Error: sp_values returned null ");
257 
258  // In this case, colptr_, rowind_, nzvals_ are invalid
259  info = basker->Factor( this->globalNumRows_,
260  this->globalNumCols_,
261  this->globalNumNonZeros_,
262  sp_rowptr,
263  sp_colind,
264  sp_values);
265  }
266  else
267 #endif
268  {
269  // In this case, loadA_impl updates colptr_, rowind_, nzvals_
270  info = basker->Factor(this->globalNumRows_,
271  this->globalNumCols_,
272  this->globalNumNonZeros_,
273  colptr_.getRawPtr(),
274  rowind_.getRawPtr(),
275  nzvals_.getRawPtr());
276  //We need to handle the realloc options
277  }
278 
279  //basker->DEBUG_PRINT();
280 
281  TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
282  std::runtime_error, "Error Basker Factor");
283 
284  local_ordinal_type blnnz = local_ordinal_type(0);
285  local_ordinal_type bunnz = local_ordinal_type(0);
286  basker->GetLnnz(blnnz); // Add exception handling?
287  basker->GetUnnz(bunnz);
288 
289  // This is set after numeric factorization complete as pivoting can be used;
290  // In this case, a discrepancy between symbolic and numeric nnz total can occur.
291  this->setNnzLU( as<size_t>( blnnz + bunnz ) );
292 
293 #else
294  info = basker.factor(this->globalNumRows_, this->globalNumCols_, this->globalNumNonZeros_, colptr_.getRawPtr(), rowind_.getRawPtr(), nzvals_.getRawPtr());
295 
296  // This is set after numeric factorization complete as pivoting can be used;
297  // In this case, a discrepancy between symbolic and numeric nnz total can occur.
298  this->setNnzLU( as<size_t>(basker.get_NnzLU() ) ) ;
299 #endif
300 
301  }
302 
303  }
304 
305  /* All processes should have the same error code */
306  Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
307 
308  //global_size_type info_st = as<global_size_type>(info);
309  /* TODO : Proper error messages*/
310  TEUCHOS_TEST_FOR_EXCEPTION( (info == -1) ,
311  std::runtime_error,
312  "Basker: Could not alloc space for L and U");
313  TEUCHOS_TEST_FOR_EXCEPTION( (info == -2),
314  std::runtime_error,
315  "Basker: Could not alloc needed work space");
316  TEUCHOS_TEST_FOR_EXCEPTION( (info == -3) ,
317  std::runtime_error,
318  "Basker: Could not alloc additional memory needed for L and U");
319  TEUCHOS_TEST_FOR_EXCEPTION( (info > 0) ,
320  std::runtime_error,
321  "Basker: Zero pivot found at: " << info );
322 
323  return(info);
324 }
325 
326 
327 template <class Matrix, class Vector>
328 int
330  const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
331  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const
332 {
333  int ierr = 0; // returned error code
334 
335  using Teuchos::as;
336 
337  const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
338  const size_t nrhs = X->getGlobalNumVectors();
339 
340 #ifndef HAVE_TEUCHOS_COMPLEX
341  bool case_check = ( (this->matrixA_->getComm()->getRank() == 0) && (this->matrixA_->getComm()->getSize() == 1) && (nrhs == 1 ) && is_contiguous_ ) ;
342  if ( case_check ) {
343 
344 #ifdef HAVE_AMESOS2_TIMERS
345  Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
346 #endif
347 
348  auto sp_rowptr = this->matrixA_->returnRowPtr();
349  TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr == nullptr,
350  std::runtime_error, "Amesos2 Runtime Error: sp_rowptr returned null ");
351  auto sp_colind = this->matrixA_->returnColInd();
352  TEUCHOS_TEST_FOR_EXCEPTION(sp_colind == nullptr,
353  std::runtime_error, "Amesos2 Runtime Error: sp_colind returned null ");
354  auto sp_values = this->matrixA_->returnValues();
355  TEUCHOS_TEST_FOR_EXCEPTION(sp_values == nullptr,
356  std::runtime_error, "Amesos2 Runtime Error: sp_values returned null ");
357 
358  auto b_vector = Util::vector_pointer_helper< MultiVecAdapter<Vector>, Vector >::get_pointer_to_vector( B );
359  TEUCHOS_TEST_FOR_EXCEPTION(b_vector == nullptr,
360  std::runtime_error, "Amesos2 Runtime Error: b_vector returned null ");
361  auto x_vector = Util::vector_pointer_helper< MultiVecAdapter<Vector>, Vector >::get_pointer_to_vector( X );
362  TEUCHOS_TEST_FOR_EXCEPTION(x_vector == nullptr,
363  std::runtime_error, "Amesos2 Runtime Error: x_vector returned null ");
364 
365  if ( this->root_ ) {
366  { // Do solve!
367 #ifdef HAVE_AMESOS2_TIMERS
368  Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
369 #endif
370 
371 #ifdef SHYLUBASKER
372  ierr = basker->Solve(nrhs, b_vector, x_vector);
373 #else
374  ierr = basker.solveMultiple(nrhs, b_vector, x_vector);
375 #endif
376  }
377 
378  /* All processes should have the same error code */
379  Teuchos::broadcast(*(this->getComm()), 0, &ierr);
380 
381  TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
382  std::runtime_error,
383  "Encountered zero diag element at: " << ierr);
384  TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
385  std::runtime_error,
386  "Could not alloc needed working memory for solve" );
387  }
388  }
389  else
390 #endif
391  {
392  const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
393 
394  xvals_.resize(val_store_size);
395  bvals_.resize(val_store_size);
396 
397  { // Get values from RHS B
398 #ifdef HAVE_AMESOS2_TIMERS
399  Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
400  Teuchos::TimeMonitor redistTimer( this->timers_.vecRedistTime_ );
401 #endif
402 
403  if ( is_contiguous_ == true ) {
405  slu_type>::do_get(B, bvals_(), as<size_t>(ld_rhs), ROOTED, this->rowIndexBase_);
406  }
407  else {
409  slu_type>::do_get(B, bvals_(), as<size_t>(ld_rhs), CONTIGUOUS_AND_ROOTED, this->rowIndexBase_);
410  }
411  }
412 
413  if ( this->root_ ) {
414  { // Do solve!
415 #ifdef HAVE_AMESOS2_TIMERS
416  Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
417 #endif
418 
419 #ifdef SHYLUBASKER
420  ierr = basker->Solve(nrhs, bvals_.getRawPtr(),
421  xvals_.getRawPtr());
422 #else
423  ierr = basker.solveMultiple(nrhs, bvals_.getRawPtr(),xvals_.getRawPtr());
424 #endif
425  }
426 
427  }
428 
429  /* All processes should have the same error code */
430  Teuchos::broadcast(*(this->getComm()), 0, &ierr);
431 
432  TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
433  std::runtime_error,
434  "Encountered zero diag element at: " << ierr);
435  TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
436  std::runtime_error,
437  "Could not alloc needed working memory for solve" );
438 
439  {
440 #ifdef HAVE_AMESOS2_TIMERS
441  Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
442 #endif
443 
444  if ( is_contiguous_ == true ) {
446  MultiVecAdapter<Vector>,slu_type>::do_put(X, xvals_(),
447  as<size_t>(ld_rhs),
448  ROOTED);
449  }
450  else {
452  MultiVecAdapter<Vector>,slu_type>::do_put(X, xvals_(),
453  as<size_t>(ld_rhs),
455  }
456  }
457  }
458 
459  return(ierr);
460 }
461 
462 
463 template <class Matrix, class Vector>
464 bool
466 {
467  // The Basker can only handle square for right now
468  return( this->globalNumRows_ == this->globalNumCols_ );
469 }
470 
471 
472 template <class Matrix, class Vector>
473 void
474 Basker<Matrix,Vector>::setParameters_impl(const Teuchos::RCP<Teuchos::ParameterList> & parameterList )
475 {
476  using Teuchos::RCP;
477  using Teuchos::getIntegralValue;
478  using Teuchos::ParameterEntryValidator;
479 
480  RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
481 
482  if(parameterList->isParameter("IsContiguous"))
483  {
484  is_contiguous_ = parameterList->get<bool>("IsContiguous");
485  }
486 
487 #ifdef SHYLUBASKER
488  if(parameterList->isParameter("num_threads"))
489  {
490  num_threads = parameterList->get<int>("num_threads");
491  }
492  if(parameterList->isParameter("pivot"))
493  {
494  basker->Options.no_pivot = (!parameterList->get<bool>("pivot"));
495  }
496  if(parameterList->isParameter("pivot_tol"))
497  {
498  basker->Options.pivot_tol = parameterList->get<double>("pivot_tol");
499  }
500  if(parameterList->isParameter("symmetric"))
501  {
502  basker->Options.symmetric = parameterList->get<bool>("symmetric");
503  }
504  if(parameterList->isParameter("realloc"))
505  {
506  basker->Options.realloc = parameterList->get<bool>("realloc");
507  }
508  if(parameterList->isParameter("verbose"))
509  {
510  basker->Options.verbose = parameterList->get<bool>("verbose");
511  }
512  if(parameterList->isParameter("verbose_matrix"))
513  {
514  basker->Options.verbose_matrix_out = parameterList->get<bool>("verbose_matrix");
515  }
516  if(parameterList->isParameter("matching"))
517  {
518  basker->Options.matching = parameterList->get<bool>("matching");
519  }
520  if(parameterList->isParameter("matching_type"))
521  {
522  basker->Options.matching_type =
523  (local_ordinal_type) parameterList->get<int>("matching_type");
524  }
525  if(parameterList->isParameter("btf"))
526  {
527  basker->Options.btf = parameterList->get<bool>("btf");
528  }
529  if(parameterList->isParameter("amd_btf"))
530  {
531  basker->Options.amd_btf = parameterList->get<bool>("amd_btf");
532  }
533  if(parameterList->isParameter("amd_dom"))
534  {
535  basker->Options.amd_dom = parameterList->get<bool>("amd_dom");
536  }
537  if(parameterList->isParameter("transpose"))
538  {
539  basker->Options.transpose = parameterList->get<bool>("transpose");
540  }
541 #endif
542 
543 }
544 
545 template <class Matrix, class Vector>
546 Teuchos::RCP<const Teuchos::ParameterList>
548 {
549  using Teuchos::ParameterList;
550 
551  static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
552 
553 
554 #ifdef SHYLUBASKER
555  if( is_null(valid_params) )
556  {
557  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
558  pl->set("IsContiguous", true,
559  "Are GIDs contiguous");
560  pl->set("num_threads", 1,
561  "Number of threads");
562  pl->set("pivot", false,
563  "Should not pivot");
564  pl->set("pivot_tol", .0001,
565  "Tolerance before pivot, currently not used");
566  pl->set("symmetric", false,
567  "Should Symbolic assume symmetric nonzero pattern");
568  pl->set("realloc" , false,
569  "Should realloc space if not enough");
570  pl->set("verbose", false,
571  "Information about factoring");
572  pl->set("verbose_matrix", false,
573  "Give Permuted Matrices");
574  pl->set("matching", true,
575  "Use WC matching (Not Supported)");
576  pl->set("matching_type", 0,
577  "Type of WC matching (Not Supported)");
578  pl->set("btf", true,
579  "Use BTF ordering");
580  pl->set("amd_btf", true,
581  "Use AMD on BTF blocks (Not Supported)");
582  pl->set("amd_dom", true,
583  "Use CAMD on ND blocks (Not Supported)");
584  pl->set("transpose", false,
585  "Solve the transpose A");
586  valid_params = pl;
587  }
588  return valid_params;
589 #else
590  if( is_null(valid_params) ){
591  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
592 
593  pl->set("IsContiguous", true, "Are GIDs contiguous");
594  pl->set("alnnz", 2, "Approx number of nonzeros in L, default is 2*nnz(A)");
595  pl->set("aunnx", 2, "Approx number of nonzeros in I, default is 2*nnz(U)");
596  valid_params = pl;
597  }
598 #endif
599  return valid_params;
600 }
601 
602 
603 template <class Matrix, class Vector>
604 bool
606 {
607  using Teuchos::as;
608  if(current_phase == SOLVE) return (false);
609 
610  #ifdef HAVE_AMESOS2_TIMERS
611  Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
612  #endif
613 
614 
615 #ifdef SHYLUBASKER
616  // NDE: Can clean up duplicated code with the #ifdef guards
617 
618 #ifndef HAVE_TEUCHOS_COMPLEX
619  bool case_check = ( (this->root_) && (this->matrixA_->getComm()->getRank() == 0) && (this->matrixA_->getComm()->getSize() == 1) && is_contiguous_ ) ;
620 
621  if ( case_check ) {
622  // NDE: Nothing is done in this special case - CRS raw pointers are passed to SHYLUBASKER and transpose of copies handled there
623  // In this case, colptr_, rowind_, nzvals_ are invalid
624  }
625  else
626 #endif
627  {
628 
629  // Only the root image needs storage allocated
630  if( this->root_ ){
631  nzvals_.resize(this->globalNumNonZeros_);
632  rowind_.resize(this->globalNumNonZeros_);
633  colptr_.resize(this->globalNumCols_ + 1); //this will be wrong for case of gapped col ids, e.g. 0,2,4,9; num_cols = 10 ([0,10)) but num GIDs = 4...
634  }
635 
636  local_ordinal_type nnz_ret = 0;
637  {
638  #ifdef HAVE_AMESOS2_TIMERS
639  Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
640  #endif
641 
642  if ( is_contiguous_ == true ) {
644  MatrixAdapter<Matrix>,slu_type,local_ordinal_type,local_ordinal_type>
645  ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
646  nnz_ret, ROOTED, ARBITRARY, this->rowIndexBase_); // copies from matrixA_ to Basker ConcreteSolver cp, ri, nzval members
647  }
648  else {
650  MatrixAdapter<Matrix>,slu_type,local_ordinal_type,local_ordinal_type>
651  ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
652  nnz_ret, CONTIGUOUS_AND_ROOTED, ARBITRARY, this->rowIndexBase_); // copies from matrixA_ to Basker ConcreteSolver cp, ri, nzval members
653  }
654  }
655 
656  if( this->root_ ){
657  TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->globalNumNonZeros_),
658  std::runtime_error,
659  "Amesos2_Basker loadA_impl: Did not get the expected number of non-zero vals");
660  }
661 
662  } //end alternative path
663 #else // Not ShyLUBasker
664 
665  // Only the root image needs storage allocated
666  if( this->root_ ){
667  nzvals_.resize(this->globalNumNonZeros_);
668  rowind_.resize(this->globalNumNonZeros_);
669  colptr_.resize(this->globalNumCols_ + 1);
670  }
671 
672  local_ordinal_type nnz_ret = 0;
673  {
674  #ifdef HAVE_AMESOS2_TIMERS
675  Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
676  #endif
677 
678  if ( is_contiguous_ == true ) {
680  MatrixAdapter<Matrix>,slu_type,local_ordinal_type,local_ordinal_type>
681  ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
682  nnz_ret, ROOTED, ARBITRARY, this->rowIndexBase_);
683  }
684  else {
686  MatrixAdapter<Matrix>,slu_type,local_ordinal_type,local_ordinal_type>
687  ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
689  }
690  }
691 
692  if( this->root_ ){
693  TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->globalNumNonZeros_),
694  std::runtime_error,
695  "Amesos2_Basker loadA_impl: Did not get the expected number of non-zero vals");
696  }
697 #endif //SHYLUBASKER
698  return true;
699 }
700 
701 
702 template<class Matrix, class Vector>
703 const char* Basker<Matrix,Vector>::name = "Basker";
704 
705 
706 } // end namespace Amesos2
707 
708 #endif // AMESOS2_Basker_DEF_HPP
Definition: basker.cpp:35
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
global_size_type globalNumCols_
Number of global columns in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:478
bool root_
If true, then this is the root processor.
Definition: Amesos2_SolverCore_decl.hpp:506
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Basker_def.hpp:547
global_size_type globalNumRows_
Number of global rows in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:475
Teuchos::Array< slu_type > bvals_
Persisting 1D store for B.
Definition: Amesos2_Basker_decl.hpp:194
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Basker_def.hpp:605
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:266
Definition: Amesos2_TypeDecl.hpp:143
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns a pointer to the Teuchos::Comm communicator with this operator.
Definition: Amesos2_SolverCore_decl.hpp:362
Teuchos::Array< local_ordinal_type > colptr_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Basker_decl.hpp:186
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
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
A generic helper class for getting a CCS representation of a Matrix.
Definition: Amesos2_Util.hpp:626
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Basker specific solve.
Definition: Amesos2_Basker_def.hpp:329
Amesos2 interface to the Baker package.
Definition: Amesos2_Basker_decl.hpp:73
Amesos2 Basker declarations.
Teuchos::Array< local_ordinal_type > rowind_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_Basker_decl.hpp:184
Teuchos::Array< slu_type > xvals_
Persisting 1D store for X.
Definition: Amesos2_Basker_decl.hpp:192
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
Teuchos::Array< slu_type > nzvals_
Stores the values of the nonzero entries for Basker.
Definition: Amesos2_Basker_decl.hpp:182
global_size_type globalNumNonZeros_
Number of global non-zero values in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:481
void setNnzLU(size_t nnz)
Set the number of non-zero values in the and factors.
Definition: Amesos2_SolverCore_decl.hpp:451
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Basker_def.hpp:132
Definition: Amesos2_TypeDecl.hpp:127
Timers timers_
Various timing statistics.
Definition: Amesos2_SolverCore_decl.hpp:497
int numericFactorization_impl()
Basker specific numeric factorization.
Definition: Amesos2_Basker_def.hpp:219
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
Teuchos::RCP< const MatrixAdapter< Matrix > > matrixA_
The LHS operator.
Definition: Amesos2_SolverCore_decl.hpp:454
global_size_type rowIndexBase_
Index base of rowmap of matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:484
Definition: Amesos2_TypeDecl.hpp:128
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Basker_def.hpp:465