58 template <
typename kokkos_cijk_type,
typename ordinal_type>
74 Array< RCP<const one_d_basis> > bases(stoch_dim);
76 bases[i] =
rcp(
new legendre_basis(poly_ord,
true));
77 RCP<const product_basis> basis =
rcp(
new product_basis(bases));
80 RCP<Cijk>
cijk = basis->computeTripleProductTensor();
83 kokkos_cijk_type kokkos_cijk =
84 Stokhos::create_product_tensor<execution_space>(*basis, *
cijk);
89 template <
typename scalar,
typename ordinal>
93 const ordinal iColFEM,
94 const ordinal iStoch )
96 const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
97 const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
98 return X_fem + X_stoch;
102 template <
typename ViewType>
105 typedef ViewType view_type;
106 typedef typename view_type::size_type size_type;
107 typedef typename view_type::HostMirror host_view_type;
108 typedef typename host_view_type::array_type host_array_type;
114 host_array_type h_a = h_v;
116 size_type num_rows, num_cols;
120 bool is_right = Kokkos::Impl::is_same<
typename ViewType::array_layout,
123 num_rows = h_a.extent(0);
124 num_cols = h_a.extent(1);
127 num_rows = h_a.extent(1);
128 num_cols = h_a.extent(0);
132 for (size_type i=0; i<num_rows; ++i) {
133 for (size_type
j=0;
j<num_cols; ++
j) {
134 scalar_type
val = h_a(i,
j);
135 scalar_type val_expected =
136 generate_pce_coefficient<scalar_type>(
137 num_rows, num_cols, i,
j);
143 for (size_type i=0; i<num_rows; ++i) {
144 for (size_type
j=0;
j<num_cols; ++
j) {
145 scalar_type
val = h_a(
j,i);
146 scalar_type val_expected =
147 generate_pce_coefficient<scalar_type>(
148 num_rows, num_cols, i,
j);
157 template <
typename ViewType>
162 typedef ViewType view_type;
163 typedef typename view_type::size_type size_type;
164 typedef typename view_type::HostMirror host_view_type;
171 const size_type num_rows = h_v.extent(0);
175 for (size_type i=0; i<num_rows; ++i) {
176 for (size_type
j=0;
j<num_cols; ++
j) {
177 scalar_type
val = h_v(i).fastAccessCoeff(
j);
178 scalar_type val_expected = v_expected.fastAccessCoeff(
j);
186 template <
typename DataType,
typename LayoutType,
typename ExecutionSpace>
188 typedef Kokkos::View<DataType,LayoutType,ExecutionSpace>
type;
192 template <
typename DataType,
typename ExecutionSpace>
194 typedef Kokkos::View<DataType,ExecutionSpace>
type;
209 typedef typename ViewType::size_type size_type;
211 typedef typename PCE::cijk_type Cijk;
218 const size_type num_rows = 11;
219 const size_type num_cols = cijk.dimension();
220 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
231 typedef typename ViewType::size_type size_type;
232 typedef typename ViewType::HostMirror host_view_type;
233 typedef typename host_view_type::array_type host_array_type;
234 typedef typename PCE::cijk_type Cijk;
241 const size_type num_rows = 11;
242 const size_type num_cols = cijk.dimension();
243 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
245 host_array_type h_a = h_v;
247 bool is_right = Kokkos::Impl::is_same<
typename ViewType::array_layout,
250 for (size_type i=0; i<num_rows; ++i)
251 for (size_type
j=0;
j<num_cols; ++
j)
252 h_a(i,
j) = generate_pce_coefficient<Scalar>(
253 num_rows, num_cols, i,
j);
256 for (size_type i=0; i<num_rows; ++i)
257 for (size_type
j=0;
j<num_cols; ++
j)
258 h_a(
j,i) = generate_pce_coefficient<Scalar>(
259 num_rows, num_cols, i,
j);
272 typedef Kokkos::HostSpace HostDevice;
273 typedef Kokkos::View<PCE*,typename ViewType::array_layout,HostDevice,Kokkos::MemoryUnmanaged> HostViewType;
274 typedef typename ViewType::size_type size_type;
275 typedef typename PCE::cijk_type Cijk;
282 const size_type num_rows = 11;
283 const size_type num_cols = cijk.dimension();
284 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
287 for (size_type i=0; i<num_rows; ++i) {
289 for (size_type
j=0;
j<num_cols; ++
j)
291 num_rows, num_cols, i,
j);
295 Kokkos::make_view<HostViewType>(a.getRawPtr(),
cijk, num_rows, num_cols);
307 typedef typename ViewType::size_type size_type;
308 typedef typename PCE::cijk_type Cijk;
315 const size_type num_rows = 11;
316 const size_type num_cols = cijk.dimension();
317 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
322 PCE pce_val(cijk); pce_val.fastAccessCoeff(0) =
val;
332 typedef typename ViewType::size_type size_type;
333 typedef typename PCE::cijk_type Cijk;
340 const size_type num_rows = 11;
341 const size_type num_cols = cijk.dimension();
342 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
347 PCE pce_val(cijk); pce_val.fastAccessCoeff(0) =
val;
357 typedef typename ViewType::size_type size_type;
358 typedef typename PCE::cijk_type Cijk;
365 const size_type num_rows = 11;
366 const size_type num_cols = cijk.dimension();
367 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
369 for (size_type
j=0;
j<num_cols; ++
j)
370 val.fastAccessCoeff(
j) =
371 generate_pce_coefficient<Scalar>(num_rows, num_cols, size_type(0),
j);
384 typedef typename ViewType::size_type size_type;
385 typedef typename ViewType::HostMirror host_view_type;
386 typedef typename PCE::cijk_type Cijk;
395 const size_type num_cols = 5;
396 const size_type num_pce = cijk.dimension();
397 ViewType v1 = Kokkos::make_view<ViewType>(
"view1",
cijk, num_rows1, num_cols);
398 ViewType v2 = Kokkos::make_view<ViewType>(
"view2",
cijk, num_rows2, num_cols);
400 for (size_type
j=0;
j<num_cols; ++
j) {
401 std::pair<size_type,size_type> rows( 0, num_rows1 );
402 ViewType v1s = Kokkos::subview( v1, rows, std::pair<size_t,size_t> (
j,
j+1) );
403 ViewType v2s = Kokkos::subview( v2, rows, std::pair<size_t,size_t> (
j,
j+1) );
412 for (size_type
j=0;
j<num_cols; ++
j) {
413 for (size_type i=0; i<num_rows1; ++i) {
414 for (size_type k=0; k<num_pce; ++k) {
415 Scalar
val = hv2(i,
j).fastAccessCoeff(k);
420 for (size_type i=num_rows1; i<num_rows2; ++i) {
421 for (size_type k=0; k<num_pce; ++k) {
422 Scalar
val = hv2(i,
j).fastAccessCoeff(k);
423 Scalar val_expected = 0;
436 typedef typename ViewType::size_type size_type;
437 typedef typename ViewType::HostMirror host_view_type;
438 typedef typename host_view_type::array_type host_array_type;
439 typedef typename PCE::cijk_type Cijk;
446 const size_type num_rows = 11;
447 const size_type num_cols = cijk.dimension();
448 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
451 bool is_right = Kokkos::Impl::is_same<
typename ViewType::array_layout,
454 for (size_type i=0; i<num_rows; ++i)
455 for (size_type
j=0;
j<num_cols; ++
j)
456 h_a(i,
j) = generate_pce_coefficient<Scalar>(
457 num_rows, num_cols, i,
j);
460 for (size_type i=0; i<num_rows; ++i)
461 for (size_type
j=0;
j<num_cols; ++
j)
462 h_a(
j,i) = generate_pce_coefficient<Scalar>(
463 num_rows, num_cols, i,
j);
476 typedef typename ViewType::size_type size_type;
477 typedef typename ViewType::HostMirror host_view_type;
478 typedef typename host_view_type::array_type host_array_type;
479 typedef typename ViewType::array_type array_type;
480 typedef typename PCE::cijk_type Cijk;
487 const size_type num_rows = 11;
488 const size_type num_cols = cijk.dimension();
489 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
491 host_array_type h_a = h_v;
494 for (size_type i=0; i<num_rows; ++i)
495 for (size_type
j=0;
j<num_cols; ++
j)
496 h_a(i,
j) = generate_pce_coefficient<Scalar>(
497 num_rows, num_cols, i,
j);
509 typedef typename ViewType::size_type size_type;
510 typedef typename ViewType::HostMirror host_view_type;
511 typedef typename host_view_type::array_type host_array_type;
512 typedef typename PCE::cijk_type Cijk;
519 const size_type num_rows = 11;
520 const size_type num_cols = cijk.dimension();
521 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
523 host_array_type h_a = h_v;
525 bool is_right = Kokkos::Impl::is_same<
typename ViewType::array_layout,
528 for (size_type i=0; i<num_rows; ++i)
529 for (size_type
j=0;
j<num_cols; ++
j)
530 h_a(i,
j) = generate_pce_coefficient<Scalar>(
531 num_rows, num_cols, i,
j);
534 for (size_type i=0; i<num_rows; ++i)
535 for (size_type
j=0;
j<num_cols; ++
j)
536 h_a(
j,i) = generate_pce_coefficient<Scalar>(
537 num_rows, num_cols, i,
j);
543 Kokkos::make_view<ViewType>( v.data(),
cijk, num_rows, num_cols );
551 template<
class ViewType >
564 Kokkos::parallel_for(
m_v.extent(0) , *this );
567 KOKKOS_INLINE_FUNCTION
583 typedef typename ViewType::size_type size_type;
584 typedef typename PCE::cijk_type Cijk;
591 const size_type num_rows = 11;
592 const size_type num_cols = cijk.dimension();
593 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
604 #define VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT( STORAGE, LAYOUT ) \
605 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
606 Kokkos_View_PCE, Size, STORAGE, LAYOUT ) \
607 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
608 Kokkos_View_PCE, DeepCopy, STORAGE, LAYOUT ) \
609 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
610 Kokkos_View_PCE, DeepCopy_NonContiguous, STORAGE, LAYOUT ) \
611 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
612 Kokkos_View_PCE, DeepCopy_ConstantScalar, STORAGE, LAYOUT ) \
613 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
614 Kokkos_View_PCE, DeepCopy_ConstantPCE, STORAGE, LAYOUT ) \
615 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
616 Kokkos_View_PCE, DeepCopy_ConstantPCE2, STORAGE, LAYOUT ) \
617 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
618 Kokkos_View_PCE, Unmanaged, STORAGE, LAYOUT )
634 #define VIEW_UQ_PCE_TESTS_STORAGE( STORAGE ) \
635 using Kokkos::LayoutLeft; \
636 using Kokkos::LayoutRight; \
637 VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, NoLayout) \
638 VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, LayoutLeft) \
639 VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, LayoutRight) \
640 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
641 Kokkos_View_PCE, DeepCopy_Subview_Range, STORAGE )
643 #define VIEW_UQ_PCE_TESTS_ORDINAL_SCALAR_DEVICE( ORDINAL, SCALAR, DEVICE ) \
644 typedef Stokhos::DynamicStorage<ORDINAL,SCALAR,DEVICE> DS; \
645 VIEW_UQ_PCE_TESTS_STORAGE( DS )
647 #define VIEW_UQ_PCE_TESTS_DEVICE( DEVICE ) \
648 VIEW_UQ_PCE_TESTS_ORDINAL_SCALAR_DEVICE( int, double, DEVICE )
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
Kokkos::DefaultExecutionSpace execution_space
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P...> >::value, unsigned >::type dimension_scalar(const View< T, P...> &view)
const int global_num_cols
bool checkConstantPCEView(const ViewType &v, const typename ViewType::value_type &v_expected, Teuchos::FancyOStream &out)
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Kokkos_SG_SpMv, CrsProductTensorCijk, Scalar, Device)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
pce_type::storage_type::value_type scalar_type
KOKKOS_INLINE_FUNCTION void atomic_assign(volatile Sacado::UQ::PCE< Storage > *const dest, const Sacado::UQ::PCE< Storage > &src)
ViewType::value_type pce_type
Kokkos::View< DataType, ExecutionSpace > type
scalar generate_pce_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch)
KOKKOS_INLINE_FUNCTION void operator()(int i) const
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
view_type::array_type::non_const_value_type type
kokkos_cijk_type build_cijk(ordinal_type stoch_dim, ordinal_type poly_ord)
ViewType::execution_space execution_space
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
Legendre polynomial basis.
const int global_num_rows
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
Abstract base class for 1-D orthogonal polynomials.
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Kokkos_CrsMatrix_MP, ReplaceValues, MatrixScalar)
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
Kokkos::View< DataType, LayoutType, ExecutionSpace > type
bool checkPCEView(const ViewType &v, Teuchos::FancyOStream &out)
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)
PCEAtomicFunctor(const ViewType &v, const scalar_type &s)