Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_ShyLUBasker_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Amesos2: Templated Direct Sparse Solver Package
4 //
5 // Copyright 2011 NTESS and the Amesos2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
20 #ifndef AMESOS2_SHYLUBASKER_DEF_HPP
21 #define AMESOS2_SHYLUBASKER_DEF_HPP
22 
23 #include <Teuchos_Tuple.hpp>
24 #include <Teuchos_ParameterList.hpp>
25 #include <Teuchos_StandardParameterEntryValidators.hpp>
26 
29 
30 namespace Amesos2 {
31 
32 
33 template <class Matrix, class Vector>
34 ShyLUBasker<Matrix,Vector>::ShyLUBasker(
35  Teuchos::RCP<const Matrix> A,
36  Teuchos::RCP<Vector> X,
37  Teuchos::RCP<const Vector> B )
38  : SolverCore<Amesos2::ShyLUBasker,Matrix,Vector>(A, X, B)
39  , is_contiguous_(true)
40 {
41 
42  //Nothing
43 
44  // Override some default options
45  // TODO: use data_ here to init
46 #if defined(HAVE_AMESOS2_KOKKOS) && defined(KOKKOS_ENABLE_OPENMP)
47  /*
48  static_assert(std::is_same<kokkos_exe,Kokkos::OpenMP>::value,
49  "Kokkos node type not supported by experimental ShyLUBasker Amesos2");
50  */
51  typedef Kokkos::OpenMP Exe_Space;
52 
53  ShyLUbasker = new ::BaskerNS::BaskerTrilinosInterface<local_ordinal_type, shylubasker_dtype, Exe_Space>();
54  ShyLUbasker->Options.no_pivot = BASKER_FALSE;
55  ShyLUbasker->Options.static_delayed_pivot = 0;
56  ShyLUbasker->Options.symmetric = BASKER_FALSE;
57  ShyLUbasker->Options.realloc = BASKER_TRUE;
58  ShyLUbasker->Options.verbose = BASKER_FALSE;
59  ShyLUbasker->Options.prune = BASKER_TRUE;
60  ShyLUbasker->Options.btf_matching = 2; // use cardinary matching from Trilinos, globally
61  ShyLUbasker->Options.blk_matching = 1; // use max-weight matching from Basker on each diagonal block
62  ShyLUbasker->Options.matrix_scaling = 0; // use matrix scaling on a big A block
63  ShyLUbasker->Options.min_block_size = 0; // no merging small blocks
64  ShyLUbasker->Options.amd_dom = BASKER_TRUE; // use block-wise AMD
65  ShyLUbasker->Options.use_metis = BASKER_TRUE; // use scotch/metis for ND (TODO: should METIS optional?)
66  ShyLUbasker->Options.use_nodeNDP = BASKER_TRUE; // use nodeNDP to compute ND partition
67  ShyLUbasker->Options.run_nd_on_leaves = BASKER_TRUE; // run ND on the final leaf-nodes
68  ShyLUbasker->Options.run_amd_on_leaves = BASKER_FALSE; // run AMD on the final leaf-nodes
69  ShyLUbasker->Options.transpose = BASKER_FALSE;
70  ShyLUbasker->Options.replace_tiny_pivot = BASKER_FALSE;
71  ShyLUbasker->Options.verbose_matrix_out = BASKER_FALSE;
72 
73  ShyLUbasker->Options.user_fill = (double)BASKER_FILL_USER;
74  ShyLUbasker->Options.use_sequential_diag_facto = BASKER_FALSE;
75 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
76  num_threads = Kokkos::OpenMP::max_hardware_threads();
77 #else
78  num_threads = Kokkos::OpenMP::impl_max_hardware_threads();
79 #endif
80 
81 #else
82  TEUCHOS_TEST_FOR_EXCEPTION(1 != 0,
83  std::runtime_error,
84  "Amesos2_ShyLUBasker Exception: Do not have supported Kokkos node type (OpenMP) enabled for ShyLUBasker");
85 #endif
86 }
87 
88 
89 template <class Matrix, class Vector>
90 ShyLUBasker<Matrix,Vector>::~ShyLUBasker( )
91 {
92  /* ShyLUBasker will cleanup its own internal memory*/
93 #if defined(HAVE_AMESOS2_KOKKOS) && defined(KOKKOS_ENABLE_OPENMP)
94  ShyLUbasker->Finalize();
95  delete ShyLUbasker;
96 #endif
97 }
98 
99 template <class Matrix, class Vector>
100 bool
102  return (this->root_ && (this->matrixA_->getComm()->getSize() == 1) && is_contiguous_);
103 }
104 
105 template<class Matrix, class Vector>
106 int
108 {
109  /* TODO: Define what it means for ShyLUBasker
110  */
111 #ifdef HAVE_AMESOS2_TIMERS
112  Teuchos::TimeMonitor preOrderTimer(this->timers_.preOrderTime_);
113 #endif
114 
115  return(0);
116 }
117 
118 
119 template <class Matrix, class Vector>
120 int
122 {
123 
124  int info = 0;
125  if(this->root_)
126  {
127  ShyLUbasker->SetThreads(num_threads);
128 
129 
130  // NDE: Special case
131  // Rather than going through the Amesos2 machinery to convert the matrixA_ CRS pointer data to CCS and store in Teuchos::Arrays,
132  // in this special case we pass the CRS raw pointers directly to ShyLUBasker which copies+transposes+sorts the data for CCS format
133  // loadA_impl is essentially an empty function in this case, as the raw pointers are handled here and similarly in Symbolic
134 
135  if ( single_proc_optimization() ) {
136 
137  host_ordinal_type_array sp_rowptr;
138  host_ordinal_type_array sp_colind;
139  // this needs to be checked during loadA_impl...
140  this->matrixA_->returnRowPtr_kokkos_view(sp_rowptr);
141  TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr.data() == nullptr,
142  std::runtime_error, "Amesos2 Runtime Error: sp_rowptr returned null ");
143  this->matrixA_->returnColInd_kokkos_view(sp_colind);
144  TEUCHOS_TEST_FOR_EXCEPTION(sp_colind.data() == nullptr,
145  std::runtime_error, "Amesos2 Runtime Error: sp_colind returned null ");
146 
147  host_value_type_array hsp_values;
148  this->matrixA_->returnValues_kokkos_view(hsp_values);
149  shylubasker_dtype * sp_values = function_map::convert_scalar(hsp_values.data());
150  //shylubasker_dtype * sp_values = function_map::convert_scalar(nzvals_view_.data());
151  TEUCHOS_TEST_FOR_EXCEPTION(sp_values == nullptr,
152  std::runtime_error, "Amesos2 Runtime Error: sp_values returned null ");
153 
154  // In this case, colptr_, rowind_, nzvals_ are invalid
155  info = ShyLUbasker->Symbolic(this->globalNumRows_,
156  this->globalNumCols_,
157  this->globalNumNonZeros_,
158  sp_rowptr.data(),
159  sp_colind.data(),
160  sp_values,
161  true);
162 
163  TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
164  std::runtime_error, "Error in ShyLUBasker Symbolic");
165  }
166  else
167  { //follow original code path if conditions not met
168  // In this case, loadA_impl updates colptr_, rowind_, nzvals_
169  shylubasker_dtype * sp_values = function_map::convert_scalar(nzvals_view_.data());
170  info = ShyLUbasker->Symbolic(this->globalNumRows_,
171  this->globalNumCols_,
172  this->globalNumNonZeros_,
173  colptr_view_.data(),
174  rowind_view_.data(),
175  sp_values);
176 
177  TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
178  std::runtime_error, "Error in ShyLUBasker Symbolic");
179  }
180  } // end if (this->root_)
181  /*No symbolic factoriztion*/
182 
183  /* All processes should have the same error code */
184  Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
185  return(info);
186 }
187 
188 
189 template <class Matrix, class Vector>
190 int
192 {
193  using Teuchos::as;
194 
195  int info = 0;
196  if ( this->root_ ){
197  { // Do factorization
198 #ifdef HAVE_AMESOS2_TIMERS
199  Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
200 #endif
201 
202 
203  // NDE: Special case
204  // Rather than going through the Amesos2 machinery to convert the matrixA_ CRS pointer data to CCS and store in Teuchos::Arrays,
205  // in this special case we pass the CRS raw pointers directly to ShyLUBasker which copies+transposes+sorts the data for CCS format
206  // loadA_impl is essentially an empty function in this case, as the raw pointers are handled here and similarly in Symbolic
207 
208  if ( single_proc_optimization() ) {
209 
210  host_ordinal_type_array sp_rowptr;
211  host_ordinal_type_array sp_colind;
212  this->matrixA_->returnRowPtr_kokkos_view(sp_rowptr);
213  TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr.data() == nullptr,
214  std::runtime_error, "Amesos2 Runtime Error: sp_rowptr returned null ");
215  this->matrixA_->returnColInd_kokkos_view(sp_colind);
216  TEUCHOS_TEST_FOR_EXCEPTION(sp_colind.data() == nullptr,
217  std::runtime_error, "Amesos2 Runtime Error: sp_colind returned null ");
218 
219  host_value_type_array hsp_values;
220  this->matrixA_->returnValues_kokkos_view(hsp_values);
221  shylubasker_dtype * sp_values = function_map::convert_scalar(hsp_values.data());
222  //shylubasker_dtype * sp_values = function_map::convert_scalar(nzvals_view_.data());
223 
224  TEUCHOS_TEST_FOR_EXCEPTION(sp_values == nullptr,
225  std::runtime_error, "Amesos2 Runtime Error: sp_values returned null ");
226 
227  // In this case, colptr_, rowind_, nzvals_ are invalid
228  info = ShyLUbasker->Factor( this->globalNumRows_,
229  this->globalNumCols_,
230  this->globalNumNonZeros_,
231  sp_rowptr.data(),
232  sp_colind.data(),
233  sp_values);
234 
235  TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
236  std::runtime_error, "Error ShyLUBasker Factor");
237  }
238  else
239  {
240  // In this case, loadA_impl updates colptr_, rowind_, nzvals_
241  shylubasker_dtype * sp_values = function_map::convert_scalar(nzvals_view_.data());
242  info = ShyLUbasker->Factor(this->globalNumRows_,
243  this->globalNumCols_,
244  this->globalNumNonZeros_,
245  colptr_view_.data(),
246  rowind_view_.data(),
247  sp_values);
248 
249  TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
250  std::runtime_error, "Error ShyLUBasker Factor");
251  }
252 
253  //ShyLUbasker->DEBUG_PRINT();
254 
255  local_ordinal_type blnnz = local_ordinal_type(0);
256  local_ordinal_type bunnz = local_ordinal_type(0);
257  ShyLUbasker->GetLnnz(blnnz); // Add exception handling?
258  ShyLUbasker->GetUnnz(bunnz);
259 
260  // This is set after numeric factorization complete as pivoting can be used;
261  // In this case, a discrepancy between symbolic and numeric nnz total can occur.
262  this->setNnzLU( as<size_t>( blnnz + bunnz ) );
263 
264  } // end scope for timer
265  } // end if (this->root_)
266 
267  /* All processes should have the same error code */
268  Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
269 
270  //global_size_type info_st = as<global_size_type>(info);
271  /* TODO : Proper error messages*/
272  TEUCHOS_TEST_FOR_EXCEPTION(info == -1,
273  std::runtime_error,
274  "ShyLUBasker: Could not alloc space for L and U");
275  TEUCHOS_TEST_FOR_EXCEPTION(info == -2,
276  std::runtime_error,
277  "ShyLUBasker: Could not alloc needed work space");
278  TEUCHOS_TEST_FOR_EXCEPTION(info == -3,
279  std::runtime_error,
280  "ShyLUBasker: Could not alloc additional memory needed for L and U");
281  TEUCHOS_TEST_FOR_EXCEPTION(info > 0,
282  std::runtime_error,
283  "ShyLUBasker: Zero pivot found at: " << info );
284 
285  return(info);
286 }
287 
288 
289 template <class Matrix, class Vector>
290 int
292  const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
293  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const
294 {
295 #ifdef HAVE_AMESOS2_TIMERS
296  Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
297 #endif
298 
299  int ierr = 0; // returned error code
300 
301  using Teuchos::as;
302 
303  const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
304  const size_t nrhs = X->getGlobalNumVectors();
305 
306  const bool ShyluBaskerTransposeRequest = this->control_.useTranspose_;
307  const bool initialize_data = true;
308  const bool do_not_initialize_data = false;
309  {
310 #ifdef HAVE_AMESOS2_TIMERS
311  Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
312  Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
313 #endif
314  if ( single_proc_optimization() && nrhs == 1 ) {
315 
316  // no msp creation
317  Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
318  host_solve_array_t>::do_get(initialize_data, B, bValues_, as<size_t>(ld_rhs));
319 
320  Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
321  host_solve_array_t>::do_get(do_not_initialize_data, X, xValues_, as<size_t>(ld_rhs));
322 
323  } // end if ( single_proc_optimization() && nrhs == 1 )
324  else {
325  Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
326  host_solve_array_t>::do_get(initialize_data, B, bValues_,
327  as<size_t>(ld_rhs),
328  (is_contiguous_ == true) ? ROOTED : CONTIGUOUS_AND_ROOTED,
329  this->rowIndexBase_);
330 
331  // See Amesos2_Tacho_def.hpp for notes on why we 'get' x here.
332  Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
333  host_solve_array_t>::do_get(do_not_initialize_data, X, xValues_,
334  as<size_t>(ld_rhs),
335  (is_contiguous_ == true) ? ROOTED : CONTIGUOUS_AND_ROOTED,
336  this->rowIndexBase_);
337  }
338  }
339 
340  if ( this->root_ ) { // do solve
341  shylubasker_dtype * pxValues = function_map::convert_scalar(xValues_.data());
342  shylubasker_dtype * pbValues = function_map::convert_scalar(bValues_.data());
343  if (!ShyluBaskerTransposeRequest)
344  ierr = ShyLUbasker->Solve(nrhs, pbValues, pxValues);
345  else
346  ierr = ShyLUbasker->Solve(nrhs, pbValues, pxValues, true);
347  }
348  /* All processes should have the same error code */
349  Teuchos::broadcast(*(this->getComm()), 0, &ierr);
350 
351  TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
352  std::runtime_error,
353  "Encountered zero diag element at: " << ierr);
354  TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
355  std::runtime_error,
356  "Could not alloc needed working memory for solve" );
357  {
358 #ifdef HAVE_AMESOS2_TIMERS
359  Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
360  Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
361 #endif
362  Util::put_1d_data_helper_kokkos_view<
363  MultiVecAdapter<Vector>,host_solve_array_t>::do_put(X, xValues_,
364  as<size_t>(ld_rhs),
365  (is_contiguous_ == true) ? ROOTED : CONTIGUOUS_AND_ROOTED);
366  }
367  return(ierr);
368 }
369 
370 
371 template <class Matrix, class Vector>
372 bool
374 {
375  // The ShyLUBasker can only handle square for right now
376  return( this->globalNumRows_ == this->globalNumCols_ );
377 }
378 
379 
380 template <class Matrix, class Vector>
381 void
382 ShyLUBasker<Matrix,Vector>::setParameters_impl(const Teuchos::RCP<Teuchos::ParameterList> & parameterList )
383 {
384  using Teuchos::RCP;
385  using Teuchos::getIntegralValue;
386  using Teuchos::ParameterEntryValidator;
387 
388  RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
389 
390  if(parameterList->isParameter("IsContiguous"))
391  {
392  is_contiguous_ = parameterList->get<bool>("IsContiguous");
393  }
394 
395  if(parameterList->isParameter("num_threads"))
396  {
397  num_threads = parameterList->get<int>("num_threads");
398  }
399  if(parameterList->isParameter("pivot"))
400  {
401  ShyLUbasker->Options.no_pivot = (!parameterList->get<bool>("pivot"));
402  }
403  if(parameterList->isParameter("delayed pivot"))
404  {
405  ShyLUbasker->Options.static_delayed_pivot = (parameterList->get<int>("delayed pivot"));
406  }
407  if(parameterList->isParameter("pivot_tol"))
408  {
409  ShyLUbasker->Options.pivot_tol = parameterList->get<double>("pivot_tol");
410  }
411  if(parameterList->isParameter("symmetric"))
412  {
413  ShyLUbasker->Options.symmetric = parameterList->get<bool>("symmetric");
414  }
415  if(parameterList->isParameter("realloc"))
416  {
417  ShyLUbasker->Options.realloc = parameterList->get<bool>("realloc");
418  }
419  if(parameterList->isParameter("verbose"))
420  {
421  ShyLUbasker->Options.verbose = parameterList->get<bool>("verbose");
422  }
423  if(parameterList->isParameter("verbose_matrix"))
424  {
425  ShyLUbasker->Options.verbose_matrix_out = parameterList->get<bool>("verbose_matrix");
426  }
427  if(parameterList->isParameter("btf"))
428  {
429  ShyLUbasker->Options.btf = parameterList->get<bool>("btf");
430  }
431  if(parameterList->isParameter("use_metis"))
432  {
433  ShyLUbasker->Options.use_metis = parameterList->get<bool>("use_metis");
434  }
435  if(parameterList->isParameter("use_nodeNDP"))
436  {
437  ShyLUbasker->Options.use_nodeNDP = parameterList->get<bool>("use_nodeNDP");
438  }
439  if(parameterList->isParameter("run_nd_on_leaves"))
440  {
441  ShyLUbasker->Options.run_nd_on_leaves = parameterList->get<bool>("run_nd_on_leaves");
442  }
443  if(parameterList->isParameter("run_amd_on_leaves"))
444  {
445  ShyLUbasker->Options.run_amd_on_leaves = parameterList->get<bool>("run_amd_on_leaves");
446  }
447  if(parameterList->isParameter("amd_on_blocks"))
448  {
449  ShyLUbasker->Options.amd_dom = parameterList->get<bool>("amd_on_blocks");
450  }
451  if(parameterList->isParameter("transpose"))
452  {
453  // NDE: set transpose vs non-transpose mode as bool; track separate shylubasker objects
454  const auto transpose = parameterList->get<bool>("transpose");
455  if (transpose == true)
456  this->control_.useTranspose_ = true;
457  }
458  if(parameterList->isParameter("use_sequential_diag_facto"))
459  {
460  ShyLUbasker->Options.use_sequential_diag_facto = parameterList->get<bool>("use_sequential_diag_facto");
461  }
462  if(parameterList->isParameter("user_fill"))
463  {
464  ShyLUbasker->Options.user_fill = parameterList->get<double>("user_fill");
465  }
466  if(parameterList->isParameter("prune"))
467  {
468  ShyLUbasker->Options.prune = parameterList->get<bool>("prune");
469  }
470  if(parameterList->isParameter("replace_tiny_pivot"))
471  {
472  ShyLUbasker->Options.replace_tiny_pivot = parameterList->get<bool>("replace_tiny_pivot");
473  }
474  if(parameterList->isParameter("btf_matching"))
475  {
476  ShyLUbasker->Options.btf_matching = parameterList->get<int>("btf_matching");
477  if (ShyLUbasker->Options.btf_matching == 1 || ShyLUbasker->Options.btf_matching == 2) {
478  ShyLUbasker->Options.matching = true;
479  } else {
480  ShyLUbasker->Options.matching = false;
481  }
482  }
483  if(parameterList->isParameter("blk_matching"))
484  {
485  ShyLUbasker->Options.blk_matching = parameterList->get<int>("blk_matching");
486  }
487  if(parameterList->isParameter("matrix_scaling"))
488  {
489  ShyLUbasker->Options.matrix_scaling = parameterList->get<int>("matrix_scaling");
490  }
491  if(parameterList->isParameter("min_block_size"))
492  {
493  ShyLUbasker->Options.min_block_size = parameterList->get<int>("min_block_size");
494  }
495 }
496 
497 template <class Matrix, class Vector>
498 Teuchos::RCP<const Teuchos::ParameterList>
500 {
501  using Teuchos::ParameterList;
502 
503  static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
504 
505  if( is_null(valid_params) )
506  {
507  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
508  pl->set("IsContiguous", true,
509  "Are GIDs contiguous");
510  pl->set("num_threads", 1,
511  "Number of threads");
512  pl->set("pivot", false,
513  "Should not pivot");
514  pl->set("delayed pivot", 0,
515  "Apply static delayed pivot on a big block");
516  pl->set("pivot_tol", .0001,
517  "Tolerance before pivot, currently not used");
518  pl->set("symmetric", false,
519  "Should Symbolic assume symmetric nonzero pattern");
520  pl->set("realloc" , false,
521  "Should realloc space if not enough");
522  pl->set("verbose", false,
523  "Information about factoring");
524  pl->set("verbose_matrix", false,
525  "Give Permuted Matrices");
526  pl->set("btf", true,
527  "Use BTF ordering");
528  pl->set("prune", false,
529  "Use prune on BTF blocks (Not Supported)");
530  pl->set("btf_matching", 2,
531  "Matching option for BTF: 0 = none, 1 = Basker, 2 = Trilinos (default), (3 = MC64 if enabled)");
532  pl->set("blk_matching", 1,
533  "Matching optioon for block: 0 = none, 1 or anything else = Basker (default), (2 = MC64 if enabled)");
534  pl->set("matrix_scaling", 0,
535  "Use matrix scaling to biig A BTF block: 0 = no-scaling, 1 = symmetric diagonal scaling, 2 = row-max, and then col-max scaling");
536  pl->set("min_block_size", 0,
537  "Size of the minimum diagonal blocks");
538  pl->set("replace_tiny_pivot", false,
539  "Replace tiny pivots during the numerical factorization");
540  pl->set("use_metis", true,
541  "Use METIS for ND");
542  pl->set("use_nodeNDP", true,
543  "Use nodeND to compute ND partition");
544  pl->set("run_nd_on_leaves", false,
545  "Run ND on the final leaf-nodes for ND factorization");
546  pl->set("run_amd_on_leaves", false,
547  "Run AMD on the final leaf-nodes for ND factorization");
548  pl->set("amd_on_blocks", true,
549  "Run AMD on each diagonal blocks");
550  pl->set("transpose", false,
551  "Solve the transpose A");
552  pl->set("use_sequential_diag_facto", false,
553  "Use sequential algorithm to factor each diagonal block");
554  pl->set("user_fill", (double)BASKER_FILL_USER,
555  "User-provided padding for the fill ratio");
556  valid_params = pl;
557  }
558  return valid_params;
559 }
560 
561 
562 template <class Matrix, class Vector>
563 bool
565 {
566  using Teuchos::as;
567  if(current_phase == SOLVE || current_phase == PREORDERING ) return( false );
568 
569  #ifdef HAVE_AMESOS2_TIMERS
570  Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
571  #endif
572 
573 
574  // NDE: Can clean up duplicated code with the #ifdef guards
575  if ( single_proc_optimization() ) {
576  // NDE: Nothing is done in this special case - CRS raw pointers are passed to SHYLUBASKER and transpose of copies handled there
577  // In this case, colptr_, rowind_, nzvals_ are invalid
578  }
579  else
580  {
581 
582  // Only the root image needs storage allocated
583  if( this->root_ && current_phase == SYMBFACT )
584  {
585  Kokkos::resize(nzvals_view_, this->globalNumNonZeros_);
586  Kokkos::resize(rowind_view_, this->globalNumNonZeros_);
587  Kokkos::resize(colptr_view_, 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...
588  }
589 
590  local_ordinal_type nnz_ret = -1;
591  bool gather_supported = (this->matrixA_->getComm()->getSize() > 1 && (std::is_same<scalar_type, float>::value || std::is_same<scalar_type, double>::value));
592  {
593  #ifdef HAVE_AMESOS2_TIMERS
594  Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
595  #endif
596  if (gather_supported) {
597  bool column_major = true;
598  if (!is_contiguous_) {
599  auto contig_mat = this->matrixA_->reindex(this->contig_rowmap_, this->contig_colmap_, current_phase);
600  nnz_ret = contig_mat->gather(nzvals_view_, rowind_view_, colptr_view_, this->recvCounts, this->recvDispls, this->transpose_map, this->nzvals_t,
601  column_major, current_phase);
602  } else {
603  nnz_ret = this->matrixA_->gather(nzvals_view_, rowind_view_, colptr_view_, this->recvCounts, this->recvDispls, this->transpose_map, this->nzvals_t,
604  column_major, current_phase);
605  }
606  // gather failed (e.g., not implemened for KokkosCrsMatrix)
607  // in case of the failure, it falls back to the original "do_get"
608  if (nnz_ret < 0) gather_supported = false;
609  }
610  if (!gather_supported) {
612  MatrixAdapter<Matrix>, host_value_type_array, host_ordinal_type_array, host_ordinal_type_array>
613  ::do_get(this->matrixA_.ptr(), nzvals_view_, rowind_view_, colptr_view_, nnz_ret,
614  (is_contiguous_ == true) ? ROOTED : CONTIGUOUS_AND_ROOTED,
615  ARBITRARY,
616  this->rowIndexBase_); // copies from matrixA_ to ShyLUBasker ConcreteSolver cp, ri, nzval members
617  }
618  }
619 
620  // gather return the total nnz_ret on every MPI process
621  if (gather_supported || this->root_) {
622  TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->globalNumNonZeros_),
623  std::runtime_error,
624  "Amesos2_ShyLUBasker loadA_impl: Did not get the expected number of non-zero vals("
625  +std::to_string(nnz_ret)+" vs "+std::to_string(this->globalNumNonZeros_)+")");
626  }
627  } //end alternative path
628  return true;
629 }
630 
631 
632 template<class Matrix, class Vector>
633 const char* ShyLUBasker<Matrix,Vector>::name = "ShyLUBasker";
634 
635 
636 } // end namespace Amesos2
637 
638 #endif // AMESOS2_SHYLUBASKER_DEF_HPP
A generic helper class for getting a CCS representation of a Matrix.
Definition: Amesos2_Util.hpp:614
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
ShyLUBasker specific solve.
Definition: Amesos2_ShyLUBasker_def.hpp:291
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:31
Amesos2 interface to the Baker package.
Definition: Amesos2_ShyLUBasker_decl.hpp:42
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_ShyLUBasker_def.hpp:499
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_ShyLUBasker_def.hpp:107
void transpose(ArrayView< Scalar > vals, ArrayView< GlobalOrdinal > indices, ArrayView< GlobalSizeT > ptr, ArrayView< Scalar > trans_vals, ArrayView< GlobalOrdinal > trans_indices, ArrayView< GlobalSizeT > trans_ptr)
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_ShyLUBasker_def.hpp:373
Amesos2 ShyLUBasker declarations.
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_ShyLUBasker_def.hpp:564
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:42
int numericFactorization_impl()
ShyLUBasker specific numeric factorization.
Definition: Amesos2_ShyLUBasker_def.hpp:191
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:142
bool single_proc_optimization() const
can we optimize size_type and ordinal_type for straight pass through, also check that is_contiguous_ ...
Definition: Amesos2_ShyLUBasker_def.hpp:101