45 #ifndef AMESOS2_MATRIXADAPTER_DEF_HPP 46 #define AMESOS2_MATRIXADAPTER_DEF_HPP 47 #include <Tpetra_Util.hpp> 48 #include "Amesos2_MatrixAdapter_decl.hpp" 49 #include "Amesos2_ConcreteMatrixAdapter_def.hpp" 52 #define TESTING_AMESOS2_WITH_TPETRA_REMOVE_UVM 53 #if defined(TESTING_AMESOS2_WITH_TPETRA_REMOVE_UVM) 54 #include "KokkosKernels_SparseUtils.hpp" 60 template <
class Matrix >
61 MatrixAdapter<Matrix>::MatrixAdapter(
const Teuchos::RCP<Matrix> m)
64 comm_ =
static_cast<const adapter_t*
>(
this)->getComm_impl();
65 col_map_ =
static_cast<const adapter_t*
>(
this)->getColMap_impl();
66 row_map_ =
static_cast<const adapter_t*
>(
this)->getRowMap_impl();
69 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 70 template <
class Matrix >
72 MatrixAdapter<Matrix>::getCrs(
const Teuchos::ArrayView<scalar_t> nzval,
73 const Teuchos::ArrayView<global_ordinal_t> colind,
74 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> rowptr,
75 typename MatrixAdapter<Matrix>::global_size_t& nnz,
76 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t, global_ordinal_t, node_t> > rowmap,
80 help_getCrs(nzval, colind, rowptr,
81 nnz, rowmap, distribution, ordering,
82 typename adapter_t::get_crs_spec());
86 template <
class Matrix >
87 template<
typename KV_S,
typename KV_GO,
typename KV_GS>
89 MatrixAdapter<Matrix>::getCrs_kokkos_view(KV_S & nzval,
92 typename MatrixAdapter<Matrix>::global_size_t& nnz,
93 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t, global_ordinal_t, node_t> > rowmap,
97 help_getCrs_kokkos_view(nzval, colind, rowptr,
98 nnz, rowmap, distribution, ordering,
99 typename adapter_t::get_crs_spec());
102 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 103 template <
class Matrix >
105 MatrixAdapter<Matrix>::getCrs(
const Teuchos::ArrayView<scalar_t> nzval,
106 const Teuchos::ArrayView<global_ordinal_t> colind,
107 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> rowptr,
108 typename MatrixAdapter<Matrix>::global_size_t& nnz,
112 const Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap
113 = Util::getDistributionMap<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(distribution,
114 this->getGlobalNumRows(),
116 this->getCrs(nzval, colind, rowptr, nnz, Teuchos::ptrInArg(*rowmap), ordering, distribution);
120 template <
class Matrix >
121 template<
typename KV_S,
typename KV_GO,
typename KV_GS>
123 MatrixAdapter<Matrix>::getCrs_kokkos_view(KV_S & nzval,
126 typename MatrixAdapter<Matrix>::global_size_t& nnz,
130 const Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap
131 = Util::getDistributionMap<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(distribution,
132 this->getGlobalNumRows(),
134 this->getCrs_kokkos_view(nzval, colind, rowptr, nnz, Teuchos::ptrInArg(*rowmap), ordering, distribution);
137 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 138 template <
class Matrix >
140 MatrixAdapter<Matrix>::getCcs(
const Teuchos::ArrayView<scalar_t> nzval,
141 const Teuchos::ArrayView<global_ordinal_t> rowind,
142 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> colptr,
143 typename MatrixAdapter<Matrix>::global_size_t& nnz,
144 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t, global_ordinal_t, node_t> > colmap,
148 help_getCcs(nzval, rowind, colptr,
149 nnz, colmap, distribution, ordering,
150 typename adapter_t::get_ccs_spec());
154 template <
class Matrix >
155 template<
typename KV_S,
typename KV_GO,
typename KV_GS>
157 MatrixAdapter<Matrix>::getCcs_kokkos_view(KV_S & nzval,
160 typename MatrixAdapter<Matrix>::global_size_t& nnz,
161 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t, global_ordinal_t, node_t> > colmap,
165 help_getCcs_kokkos_view(nzval, rowind, colptr,
166 nnz, colmap, distribution, ordering,
167 typename adapter_t::get_ccs_spec());
170 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 171 template <
class Matrix >
173 MatrixAdapter<Matrix>::getCcs(
const Teuchos::ArrayView<scalar_t> nzval,
174 const Teuchos::ArrayView<global_ordinal_t> rowind,
175 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> colptr,
176 typename MatrixAdapter<Matrix>::global_size_t& nnz,
180 const Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap
181 = Util::getDistributionMap<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(distribution,
182 this->getGlobalNumCols(),
184 this->getCcs(nzval, rowind, colptr, nnz, Teuchos::ptrInArg(*colmap), ordering, distribution);
188 template <
class Matrix >
189 template<
typename KV_S,
typename KV_GO,
typename KV_GS>
191 MatrixAdapter<Matrix>::getCcs_kokkos_view(KV_S & nzval,
194 typename MatrixAdapter<Matrix>::global_size_t& nnz,
198 const Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap
199 = Util::getDistributionMap<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(distribution,
200 this->getGlobalNumCols(),
202 this->getCcs_kokkos_view(nzval, rowind, colptr, nnz, Teuchos::ptrInArg(*colmap), ordering, distribution);
206 template <
class Matrix >
207 typename MatrixAdapter<Matrix>::global_size_t
210 return static_cast<const adapter_t*
>(
this)->getGlobalNumRows_impl();
213 template <
class Matrix >
214 typename MatrixAdapter<Matrix>::global_size_t
217 return static_cast<const adapter_t*
>(
this)->getGlobalNumCols_impl();
220 template <
class Matrix >
221 typename MatrixAdapter<Matrix>::global_size_t
226 return (row_map_ != Teuchos::null) ? row_map_->getIndexBase() : 0;
229 template <
class Matrix >
230 typename MatrixAdapter<Matrix>::global_size_t
235 return (col_map_ != Teuchos::null) ? col_map_->getIndexBase() : 0;
238 template <
class Matrix >
239 typename MatrixAdapter<Matrix>::global_size_t
242 return static_cast<const adapter_t*
>(
this)->getGlobalNNZ_impl();
245 template <
class Matrix >
249 return row_map_->getNodeNumElements();
252 template <
class Matrix >
256 return col_map_->getNodeNumElements();
259 template <
class Matrix >
263 return static_cast<const adapter_t*
>(
this)->getLocalNNZ_impl();
267 template <
class Matrix >
271 std::ostringstream oss;
272 oss <<
"Amesos2::MatrixAdapter wrapping: ";
277 template <
class Matrix >
280 const Teuchos::EVerbosityLevel verbLevel)
const 283 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 284 template <
class Matrix >
288 return static_cast<const adapter_t*
>(
this)->getSparseRowPtr();
291 template <
class Matrix >
292 typename MatrixAdapter<Matrix>::spmtx_idx_t
293 MatrixAdapter<Matrix>::returnColInd()
const 295 return static_cast<const adapter_t*
>(
this)->getSparseColInd();
298 template <
class Matrix >
299 typename MatrixAdapter<Matrix>::spmtx_vals_t
300 MatrixAdapter<Matrix>::returnValues()
const 302 return static_cast<const adapter_t*
>(
this)->getSparseValues();
306 template <
class Matrix >
307 template <
class KV >
310 return static_cast<const adapter_t*
>(
this)->getSparseRowPtr_kokkos_view(view);
313 template <
class Matrix >
314 template <
class KV >
317 return static_cast<const adapter_t*
>(
this)->getSparseColInd_kokkos_view(view);
320 template <
class Matrix >
321 template <
class KV >
324 return static_cast<const adapter_t*
>(
this)->getSparseValues_kokkos_view(view);
331 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 332 template <
class Matrix >
335 const Teuchos::ArrayView<global_ordinal_t> colind,
336 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> rowptr,
337 typename MatrixAdapter<Matrix>::global_size_t& nnz,
338 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
343 static_cast<const adapter_t*
>(
this)->getCrs_spec(nzval, colind, rowptr,
344 nnz, rowmap, ordering);
347 template <
class Matrix >
349 MatrixAdapter<Matrix>::help_getCrs(
const Teuchos::ArrayView<scalar_t> nzval,
350 const Teuchos::ArrayView<global_ordinal_t> colind,
351 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> rowptr,
352 typename MatrixAdapter<Matrix>::global_size_t& nnz,
353 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
356 no_special_impl nsi)
const 361 do_getCrs(nzval, colind, rowptr,
362 nnz, rowmap, distribution, ordering,
363 typename adapter_t::major_access());
367 template <
class Matrix >
368 template<
typename KV_S,
typename KV_GO,
typename KV_GS>
370 MatrixAdapter<Matrix>::help_getCrs_kokkos_view(KV_S & nzval,
373 typename MatrixAdapter<Matrix>::global_size_t& nnz,
374 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
377 no_special_impl nsi)
const 382 do_getCrs_kokkos_view(nzval, colind, rowptr,
383 nnz, rowmap, distribution, ordering,
384 typename adapter_t::major_access());
387 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 388 template <
class Matrix >
390 MatrixAdapter<Matrix>::do_getCrs(
const Teuchos::ArrayView<scalar_t> nzval,
391 const Teuchos::ArrayView<global_ordinal_t> colind,
392 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> rowptr,
393 typename MatrixAdapter<Matrix>::global_size_t& nnz,
394 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
401 using Teuchos::ArrayView;
402 using Teuchos::OrdinalTraits;
407 RCP<const type> get_mat;
408 if( *rowmap == *this->row_map_ && distribution != CONTIGUOUS_AND_ROOTED ){
410 get_mat = rcp(
this,
false);
412 get_mat =
get(rowmap, distribution);
423 RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rmap = get_mat->getRowMap();
424 ArrayView<const global_ordinal_t> node_elements = rmap->getNodeElementList();
425 if( node_elements.size() == 0 )
return;
427 typename ArrayView<const global_ordinal_t>::iterator row_it, row_end;
428 row_end = node_elements.end();
430 size_t rowptr_ind = OrdinalTraits<size_t>::zero();
431 global_ordinal_t rowInd = OrdinalTraits<global_ordinal_t>::zero();
432 for( row_it = node_elements.begin(); row_it != row_end; ++row_it ){
433 rowptr[rowptr_ind++] = rowInd;
434 size_t rowNNZ = get_mat->getGlobalRowNNZ(*row_it);
435 size_t nnzRet = OrdinalTraits<size_t>::zero();
436 ArrayView<global_ordinal_t> colind_view = colind.view(rowInd,rowNNZ);
437 ArrayView<scalar_t> nzval_view = nzval.view(rowInd,rowNNZ);
439 get_mat->getGlobalRowCopy(*row_it, colind_view, nzval_view, nnzRet);
440 for (
size_t rr = 0; rr < nnzRet ; rr++)
442 colind_view[rr] = colind_view[rr] - rmap->getIndexBase();
448 if( ordering == SORTED_INDICES ){
449 Tpetra::sort2(colind_view.begin(), colind_view.end(), nzval_view.begin());
452 TEUCHOS_TEST_FOR_EXCEPTION( rowNNZ != nnzRet,
454 "Number of values returned different from " 455 "number of values reported");
458 rowptr[rowptr_ind] = nnz = rowInd;
462 template <
class Matrix >
463 template<
typename KV_S,
typename KV_GO,
typename KV_GS>
465 MatrixAdapter<Matrix>::do_getCrs_kokkos_view(KV_S & nzval,
468 typename MatrixAdapter<Matrix>::global_size_t& nnz,
469 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
479 if(this->row_map_ == Teuchos::null) {
480 this->returnValues_kokkos_view(nzval);
481 this->returnRowPtr_kokkos_view(rowptr);
482 this->returnColInd_kokkos_view(colind);
489 using Teuchos::ArrayView;
490 using Teuchos::OrdinalTraits;
494 RCP<const type> get_mat;
495 if( *rowmap == *this->row_map_ && distribution != CONTIGUOUS_AND_ROOTED ){
497 get_mat = rcp(
this,
false);
499 get_mat =
get(rowmap, distribution);
510 RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rmap = get_mat->getRowMap();
511 ArrayView<const global_ordinal_t> node_elements = rmap->getNodeElementList();
513 typename ArrayView<const global_ordinal_t>::iterator row_it, row_end;
514 row_end = node_elements.end();
516 size_t rowptr_ind = OrdinalTraits<size_t>::zero();
517 global_ordinal_t rowInd = OrdinalTraits<global_ordinal_t>::zero();
520 typename KV_GS::HostMirror host_rowptr = Kokkos::create_mirror_view(rowptr);
522 #if !defined(TESTING_AMESOS2_WITH_TPETRA_REMOVE_UVM) 526 Kokkos::View<scalar_t*, Kokkos::HostSpace>
527 mat_nzval(Kokkos::ViewAllocateWithoutInitializing(
"mat_nzval"), nzval.size());
529 Kokkos::View<global_ordinal_t*, Kokkos::HostSpace>
530 mat_colind(Kokkos::ViewAllocateWithoutInitializing(
"mat_colind"), colind.size());
532 ArrayView<scalar_t> nzval_arrayview(mat_nzval.data(), nzval.size());
533 ArrayView<global_ordinal_t> colind_arrayview(mat_colind.data(), colind.size());
535 for( row_it = node_elements.begin(); row_it != row_end; ++row_it ){
536 host_rowptr(rowptr_ind++) = rowInd;
537 size_t rowNNZ = get_mat->getGlobalRowNNZ(*row_it);
538 size_t nnzRet = OrdinalTraits<size_t>::zero();
539 ArrayView<global_ordinal_t> colind_view = colind_arrayview.view(rowInd,rowNNZ);
540 ArrayView<scalar_t> nzval_view = nzval_arrayview.view(rowInd,rowNNZ);
542 get_mat->getGlobalRowCopy(*row_it, colind_view, nzval_view, nnzRet);
544 for (
size_t rr = 0; rr < nnzRet ; rr++) {
545 colind_view[rr] -= rmap->getIndexBase();
551 if( ordering == SORTED_INDICES ) {
552 Tpetra::sort2(colind_view.begin(), colind_view.end(), nzval_view.begin());
555 TEUCHOS_TEST_FOR_EXCEPTION( rowNNZ != nnzRet,
557 "Number of values returned different from " 558 "number of values reported");
561 host_rowptr(rowptr_ind) = nnz = rowInd;
563 deep_copy_or_assign_view(nzval, mat_nzval);
564 deep_copy_or_assign_view(colind, mat_colind);
565 deep_copy_or_assign_view(rowptr, host_rowptr);
568 global_host_idx_t mat_colind(Kokkos::ViewAllocateWithoutInitializing(
"mat_colind"), nzval.size());
569 global_host_val_t mat_nzvals(Kokkos::ViewAllocateWithoutInitializing(
"mat_nzvals"), colind.size());
571 auto host_colind = Kokkos::create_mirror_view(colind);
572 auto host_nzval = Kokkos::create_mirror_view(nzval);
575 for( row_it = node_elements.begin(); row_it != row_end; ++row_it ){
576 size_t rowNNZ = get_mat->getGlobalRowNNZ(*row_it);
577 size_t nnzRet = OrdinalTraits<size_t>::zero();
581 global_host_idx_t colind_view (&(mat_colind(rowInd)), rowNNZ);
582 global_host_val_t nzvals_view (&(mat_nzvals(rowInd)), rowNNZ);
584 global_ordinal_t row_id = *row_it;
585 get_mat->getGlobalRowCopy_kokkos_view(row_id, colind_view, nzvals_view, nnzRet);
587 TEUCHOS_TEST_FOR_EXCEPTION( rowNNZ != nnzRet,
589 "Number of values returned different from " 590 "number of values reported");
591 host_rowptr(rowptr_ind++) = rowInd;
594 host_rowptr(rowptr_ind) = nnz = rowInd;
597 if (rmap->getIndexBase() != 0) {
598 for (
size_t k = 0; k < mat_colind.extent(0); k++) {
599 mat_colind(k) -= rmap->getIndexBase();
604 deep_copy_or_assign_view(nzval, mat_nzvals);
605 deep_copy_or_assign_view(colind, mat_colind);
606 deep_copy_or_assign_view(rowptr, host_rowptr);
609 if( ordering == SORTED_INDICES ) {
610 using execution_space =
typename KV_GS::execution_space;
611 KokkosKernels::Impl::sort_crs_matrix <execution_space, KV_GS, KV_GO, KV_S>
612 (rowptr, colind, nzval);
617 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 619 template <
class Matrix >
621 MatrixAdapter<Matrix>::do_getCrs(
const Teuchos::ArrayView<scalar_t> nzval,
622 const Teuchos::ArrayView<global_ordinal_t> colind,
623 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> rowptr,
624 typename MatrixAdapter<Matrix>::global_size_t& nnz,
625 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
630 using Teuchos::Array;
633 Array<scalar_t> nzval_tmp(nzval.size(), 0);
634 Array<global_ordinal_t> rowind(colind.size(), 0);
635 Array<global_size_t> colptr(this->getGlobalNumCols() + 1);
636 this->getCcs(nzval_tmp(), rowind(), colptr(), nnz, rowmap, ordering, distribution);
638 if( !nzval.is_null() && !colind.is_null() && !rowptr.is_null() )
639 Util::transpose(nzval_tmp(), rowind(), colptr(), nzval, colind, rowptr);
642 template <
class Matrix >
644 MatrixAdapter<Matrix>::help_getCcs(
const Teuchos::ArrayView<scalar_t> nzval,
645 const Teuchos::ArrayView<global_ordinal_t> rowind,
646 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> colptr,
647 typename MatrixAdapter<Matrix>::global_size_t& nnz,
648 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
651 has_special_impl)
const 653 static_cast<const adapter_t*
>(
this)->getCcs_spec(nzval, rowind, colptr,
654 nnz, colmap, ordering);
658 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 659 template <
class Matrix >
661 MatrixAdapter<Matrix>::help_getCcs(
const Teuchos::ArrayView<scalar_t> nzval,
662 const Teuchos::ArrayView<global_ordinal_t> rowind,
663 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> colptr,
664 typename MatrixAdapter<Matrix>::global_size_t& nnz,
665 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
668 no_special_impl nsi)
const 672 do_getCcs(nzval, rowind, colptr,
673 nnz, colmap, distribution, ordering,
674 typename adapter_t::major_access());
678 template <
class Matrix >
679 template<
typename KV_S,
typename KV_GO,
typename KV_GS>
681 MatrixAdapter<Matrix>::help_getCcs_kokkos_view(KV_S & nzval,
684 typename MatrixAdapter<Matrix>::global_size_t& nnz,
685 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
688 no_special_impl nsi)
const 693 do_getCcs_kokkos_view(nzval, rowind, colptr,
694 nnz, colmap, distribution, ordering,
695 typename adapter_t::major_access());
698 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 699 template <
class Matrix >
701 MatrixAdapter<Matrix>::do_getCcs(
const Teuchos::ArrayView<scalar_t> nzval,
702 const Teuchos::ArrayView<global_ordinal_t> rowind,
703 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> colptr,
704 typename MatrixAdapter<Matrix>::global_size_t& nnz,
705 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
710 using Teuchos::Array;
715 Array<scalar_t> nzval_tmp(nzval.size(), 0);
716 Array<global_ordinal_t> colind(rowind.size(), 0);
717 Array<global_size_t> rowptr(this->getGlobalNumRows() + 1);
718 this->getCrs(nzval_tmp(), colind(), rowptr(), nnz, colmap, ordering, distribution);
720 if( !nzval.is_null() && !rowind.is_null() && !colptr.is_null() )
721 Util::transpose(nzval_tmp(), colind(), rowptr(), nzval, rowind, colptr);
725 template <
class Matrix >
726 template<
typename KV_S,
typename KV_GO,
typename KV_GS>
728 MatrixAdapter<Matrix>::do_getCcs_kokkos_view(KV_S & nzval,
731 typename MatrixAdapter<Matrix>::global_size_t& nnz,
732 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
737 using Teuchos::ArrayView;
742 KV_S nzval_tmp(Kokkos::ViewAllocateWithoutInitializing(
"nzval_tmp"), nzval.size());
743 KV_GO colind(Kokkos::ViewAllocateWithoutInitializing(
"colind"), rowind.size());
744 KV_GS rowptr(Kokkos::ViewAllocateWithoutInitializing(
"rowptr"), this->getGlobalNumRows() + 1);
746 this->getCrs_kokkos_view(nzval_tmp, colind, rowptr, nnz, colmap, ordering, distribution);
752 ArrayView<typename KV_S::value_type> av_nzval_tmp(nzval_tmp.data(), nzval_tmp.size());
753 ArrayView<typename KV_GO::value_type> av_colind(colind.data(), colind.size());
754 ArrayView<typename KV_GS::value_type> av_rowptr(rowptr.data(), rowptr.size());
755 ArrayView<typename KV_S::value_type> av_nzval(nzval.data(), nzval.size());
756 ArrayView<typename KV_GO::value_type> av_rowind(rowind.data(), rowind.size());
757 ArrayView<typename KV_GS::value_type> av_colptr(colptr.data(), colptr.size());
758 Util::transpose(av_nzval_tmp, av_colind, av_rowptr, av_nzval, av_rowind, av_colptr);
762 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 763 template <
class Matrix >
765 MatrixAdapter<Matrix>::do_getCcs(
const Teuchos::ArrayView<scalar_t> nzval,
766 const Teuchos::ArrayView<global_ordinal_t> rowind,
767 const Teuchos::ArrayView<
typename MatrixAdapter<Matrix>::global_size_t> colptr,
768 typename MatrixAdapter<Matrix>::global_size_t& nnz,
769 const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
775 using Teuchos::ArrayView;
776 using Teuchos::OrdinalTraits;
778 RCP<const type> get_mat;
779 if( *colmap == *this->col_map_ && distribution != CONTIGUOUS_AND_ROOTED ){
781 get_mat = rcp(
this,
false);
783 get_mat =
get(colmap, distribution);
787 RCP<const Tpetra::Map<scalar_t,local_ordinal_t,global_ordinal_t> > cmap = get_mat->getColMap();
788 TEUCHOS_ASSERT( *colmap == *cmap );
790 ArrayView<global_ordinal_t> node_elements = cmap->getNodeElementList();
791 if( node_elements.size() == 0 )
return;
793 typename ArrayView<global_ordinal_t>::iterator col_it, col_end;
794 col_end = node_elements.end();
796 size_t colptr_ind = OrdinalTraits<size_t>::zero();
797 global_ordinal_t colInd = OrdinalTraits<global_ordinal_t>::zero();
798 for( col_it = node_elements.begin(); col_it != col_end; ++col_it ){
799 colptr[colptr_ind++] = colInd;
800 size_t colNNZ = getGlobalColNNZ(*col_it);
802 ArrayView<global_ordinal_t> rowind_view = rowind.view(colInd,colNNZ);
803 ArrayView<scalar_t> nzval_view = nzval.view(colInd,colNNZ);
804 getGlobalColCopy(*col_it, rowind_view, nzval_view, nnzRet);
809 if( ordering == SORTED_INDICES ){
810 Tpetra::sort2(rowind_view.begin(), rowind_view.end(), nzval_view.begin());
813 TEUCHOS_TEST_FOR_EXCEPTION( colNNZ != nnzRet,
815 "Number of values returned different from " 816 "number of values reported");
819 colptr[colptr_ind] = nnz = colInd;
825 template <
class Matrix >
826 template<
typename KV_GO,
typename KV_S>
833 static_cast<const adapter_t*
>(
this)->getGlobalRowCopy_kokkos_view_impl(row, indices, vals, nnz);
836 #ifdef TPETRA_ENABLE_DEPRECATED_CODE 837 template <
class Matrix >
840 const Teuchos::ArrayView<global_ordinal_t>& indices,
841 const Teuchos::ArrayView<scalar_t>& vals,
844 static_cast<const adapter_t*
>(
this)->getGlobalRowCopy_impl(row, indices, vals, nnz);
847 template <
class Matrix >
849 MatrixAdapter<Matrix>::getGlobalColCopy(global_ordinal_t col,
850 const Teuchos::ArrayView<global_ordinal_t>& indices,
851 const Teuchos::ArrayView<scalar_t>& vals,
854 static_cast<const adapter_t*
>(
this)->getGlobalColCopy_impl(col, indices, vals, nnz);
858 template <
class Matrix >
862 return static_cast<const adapter_t*
>(
this)->getMaxRowNNZ_impl();
865 template <
class Matrix >
869 return static_cast<const adapter_t*
>(
this)->getMaxColNNZ_impl();
872 template <
class Matrix >
874 MatrixAdapter<Matrix>::getGlobalRowNNZ(global_ordinal_t row)
const 876 return static_cast<const adapter_t*
>(
this)->getGlobalRowNNZ_impl(row);
879 template <
class Matrix >
881 MatrixAdapter<Matrix>::getLocalRowNNZ(local_ordinal_t row)
const 883 return static_cast<const adapter_t*
>(
this)->getLocalRowNNZ_impl(row);
886 template <
class Matrix >
888 MatrixAdapter<Matrix>::getGlobalColNNZ(global_ordinal_t col)
const 890 return static_cast<const adapter_t*
>(
this)->getGlobalColNNZ_impl(col);
893 template <
class Matrix >
895 MatrixAdapter<Matrix>::getLocalColNNZ(local_ordinal_t col)
const 897 return static_cast<const adapter_t*
>(
this)->getLocalColNNZ_impl(col);
900 template <
class Matrix >
902 MatrixAdapter<Matrix>::isLocallyIndexed()
const 904 return static_cast<const adapter_t*
>(
this)->isLocallyIndexed_impl();
907 template <
class Matrix >
909 MatrixAdapter<Matrix>::isGloballyIndexed()
const 911 return static_cast<const adapter_t*
>(
this)->isGloballyIndexed_impl();
915 template <
class Matrix >
916 Teuchos::RCP<const MatrixAdapter<Matrix> >
917 MatrixAdapter<Matrix>::get(
const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map,
EDistribution distribution)
const 919 return static_cast<const adapter_t*
>(
this)->get_impl(map, distribution);
923 template <
class Matrix>
924 Teuchos::RCP<MatrixAdapter<Matrix> >
925 createMatrixAdapter(Teuchos::RCP<Matrix> m){
927 using Teuchos::rcp_const_cast;
929 if(m.is_null())
return Teuchos::null;
930 return( rcp(
new ConcreteMatrixAdapter<Matrix>(m)) );
933 template <
class Matrix>
934 Teuchos::RCP<const MatrixAdapter<Matrix> >
935 createConstMatrixAdapter(Teuchos::RCP<const Matrix> m){
937 using Teuchos::rcp_const_cast;
939 if(m.is_null())
return Teuchos::null;
940 return( rcp(
new ConcreteMatrixAdapter<Matrix>(rcp_const_cast<Matrix,const Matrix>(m))).getConst() );
945 #endif // AMESOS2_MATRIXADAPTER_DEF_HPP EStorage_Ordering
Definition: Amesos2_TypeDecl.hpp:141
Indicates that the concrete class has a special implementation that should be called.
Definition: Amesos2_TypeDecl.hpp:82
void transpose(ArrayView< Scalar > vals, ArrayView< GlobalOrdinal > indices, ArrayView< GlobalSizeT > ptr, ArrayView< Scalar > trans_vals, ArrayView< GlobalOrdinal > trans_indices, ArrayView< GlobalSizeT > trans_ptr)
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_MatrixAdapter_def.hpp:269
EDistribution
Definition: Amesos2_TypeDecl.hpp:123