26 template <
typename kokkos_cijk_type,
typename ordinal_type>
42 Array< RCP<const one_d_basis> > bases(stoch_dim);
44 bases[i] =
rcp(
new legendre_basis(poly_ord,
true));
45 RCP<const product_basis> basis =
rcp(
new product_basis(bases));
48 RCP<Cijk>
cijk = basis->computeTripleProductTensor();
51 kokkos_cijk_type kokkos_cijk =
52 Stokhos::create_product_tensor<execution_space>(*basis, *
cijk);
57 template <
typename scalar,
typename ordinal>
61 const ordinal iColFEM,
62 const ordinal iStoch )
64 const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
65 const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
66 return X_fem + X_stoch;
70 template <
typename ViewType>
73 typedef ViewType view_type;
74 typedef typename view_type::size_type size_type;
75 typedef typename view_type::HostMirror host_view_type;
76 typedef typename host_view_type::array_type host_array_type;
82 host_array_type h_a = h_v;
84 size_type num_rows, num_cols;
88 bool is_right = std::is_same<
typename ViewType::array_layout,
91 num_rows = h_a.extent(0);
92 num_cols = h_a.extent(1);
95 num_rows = h_a.extent(1);
96 num_cols = h_a.extent(0);
100 for (size_type i=0; i<num_rows; ++i) {
101 for (size_type
j=0;
j<num_cols; ++
j) {
102 scalar_type
val = h_a(i,
j);
103 scalar_type val_expected =
104 generate_pce_coefficient<scalar_type>(
105 num_rows, num_cols, i,
j);
111 for (size_type i=0; i<num_rows; ++i) {
112 for (size_type
j=0;
j<num_cols; ++
j) {
113 scalar_type
val = h_a(
j,i);
114 scalar_type val_expected =
115 generate_pce_coefficient<scalar_type>(
116 num_rows, num_cols, i,
j);
125 template <
typename ViewType>
130 typedef ViewType view_type;
131 typedef typename view_type::size_type size_type;
132 typedef typename view_type::HostMirror host_view_type;
139 const size_type num_rows = h_v.extent(0);
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_v(i).coeff(
j);
146 scalar_type val_expected = v_expected.coeff(
j);
154 template <
typename DataType,
typename LayoutType,
typename ExecutionSpace>
156 typedef Kokkos::View<DataType,LayoutType,ExecutionSpace>
type;
160 template <
typename DataType,
typename ExecutionSpace>
162 typedef Kokkos::View<DataType,ExecutionSpace>
type;
177 typedef typename ViewType::size_type size_type;
179 typedef typename PCE::cijk_type Cijk;
186 const size_type num_rows = 11;
187 const size_type num_cols = cijk.dimension();
188 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
199 typedef typename ViewType::size_type size_type;
200 typedef typename ViewType::HostMirror host_view_type;
201 typedef typename host_view_type::array_type host_array_type;
202 typedef typename PCE::cijk_type Cijk;
209 const size_type num_rows = 11;
210 const size_type num_cols = cijk.dimension();
211 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
213 host_array_type h_a = h_v;
215 bool is_right = std::is_same<
typename ViewType::array_layout,
218 for (size_type i=0; i<num_rows; ++i)
219 for (size_type
j=0;
j<num_cols; ++
j)
220 h_a(i,
j) = generate_pce_coefficient<Scalar>(
221 num_rows, num_cols, i,
j);
224 for (size_type i=0; i<num_rows; ++i)
225 for (size_type
j=0;
j<num_cols; ++
j)
226 h_a(
j,i) = generate_pce_coefficient<Scalar>(
227 num_rows, num_cols, i,
j);
240 typedef Kokkos::HostSpace HostDevice;
241 typedef Kokkos::View<PCE*,typename ViewType::array_layout,HostDevice,Kokkos::MemoryUnmanaged> HostViewType;
242 typedef typename ViewType::size_type size_type;
243 typedef typename PCE::cijk_type Cijk;
250 const size_type num_rows = 11;
251 const size_type num_cols = cijk.dimension();
252 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
255 for (size_type i=0; i<num_rows; ++i) {
257 for (size_type
j=0;
j<num_cols; ++
j)
259 num_rows, num_cols, i,
j);
263 Kokkos::make_view<HostViewType>(a.getRawPtr(),
cijk, num_rows, num_cols);
275 typedef typename ViewType::size_type size_type;
276 typedef typename PCE::cijk_type Cijk;
283 const size_type num_rows = 11;
284 const size_type num_cols = cijk.dimension();
285 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
290 PCE pce_val(cijk); pce_val.fastAccessCoeff(0) =
val;
300 typedef typename ViewType::size_type size_type;
301 typedef typename PCE::cijk_type Cijk;
308 const size_type num_rows = 11;
309 const size_type num_cols = cijk.dimension();
310 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
315 PCE pce_val(cijk); pce_val.fastAccessCoeff(0) =
val;
325 typedef typename ViewType::size_type size_type;
326 typedef typename PCE::cijk_type Cijk;
333 const size_type num_rows = 11;
334 const size_type num_cols = cijk.dimension();
335 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
337 for (size_type
j=0;
j<num_cols; ++
j)
338 val.fastAccessCoeff(
j) =
339 generate_pce_coefficient<Scalar>(num_rows, num_cols, size_type(0),
j);
352 typedef typename ViewType::size_type size_type;
353 typedef typename ViewType::HostMirror host_view_type;
354 typedef typename PCE::cijk_type Cijk;
363 const size_type num_cols = 5;
364 const size_type num_pce = cijk.dimension();
365 ViewType v1 = Kokkos::make_view<ViewType>(
"view1",
cijk, num_rows1, num_cols);
366 ViewType v2 = Kokkos::make_view<ViewType>(
"view2",
cijk, num_rows2, num_cols);
368 for (size_type
j=0;
j<num_cols; ++
j) {
369 std::pair<size_type,size_type> rows( 0, num_rows1 );
370 ViewType v1s = Kokkos::subview( v1, rows, std::pair<size_t,size_t> (
j,
j+1) );
371 ViewType v2s = Kokkos::subview( v2, rows, std::pair<size_t,size_t> (
j,
j+1) );
380 for (size_type
j=0;
j<num_cols; ++
j) {
381 for (size_type i=0; i<num_rows1; ++i) {
382 for (size_type k=0; k<num_pce; ++k) {
383 Scalar
val = hv2(i,
j).fastAccessCoeff(k);
388 for (size_type i=num_rows1; i<num_rows2; ++i) {
389 for (size_type k=0; k<num_pce; ++k) {
390 Scalar
val = hv2(i,
j).fastAccessCoeff(k);
391 Scalar val_expected = 0;
404 typedef typename ViewType::size_type size_type;
405 typedef typename ViewType::HostMirror host_view_type;
406 typedef typename host_view_type::array_type host_array_type;
407 typedef typename PCE::cijk_type Cijk;
414 const size_type num_rows = 11;
415 const size_type num_cols = cijk.dimension();
416 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
419 bool is_right = std::is_same<
typename ViewType::array_layout,
422 for (size_type i=0; i<num_rows; ++i)
423 for (size_type
j=0;
j<num_cols; ++
j)
424 h_a(i,
j) = generate_pce_coefficient<Scalar>(
425 num_rows, num_cols, i,
j);
428 for (size_type i=0; i<num_rows; ++i)
429 for (size_type
j=0;
j<num_cols; ++
j)
430 h_a(
j,i) = generate_pce_coefficient<Scalar>(
431 num_rows, num_cols, i,
j);
444 typedef typename ViewType::size_type size_type;
445 typedef typename ViewType::HostMirror host_view_type;
446 typedef typename host_view_type::array_type host_array_type;
447 typedef typename ViewType::array_type array_type;
448 typedef typename PCE::cijk_type Cijk;
455 const size_type num_rows = 11;
456 const size_type num_cols = cijk.dimension();
457 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
459 host_array_type h_a = h_v;
462 for (size_type i=0; i<num_rows; ++i)
463 for (size_type
j=0;
j<num_cols; ++
j)
464 h_a(i,
j) = generate_pce_coefficient<Scalar>(
465 num_rows, num_cols, i,
j);
477 typedef typename ViewType::size_type size_type;
478 typedef typename ViewType::HostMirror host_view_type;
479 typedef typename host_view_type::array_type host_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;
493 bool is_right = std::is_same<
typename ViewType::array_layout,
496 for (size_type i=0; i<num_rows; ++i)
497 for (size_type
j=0;
j<num_cols; ++
j)
498 h_a(i,
j) = generate_pce_coefficient<Scalar>(
499 num_rows, num_cols, i,
j);
502 for (size_type i=0; i<num_rows; ++i)
503 for (size_type
j=0;
j<num_cols; ++
j)
504 h_a(
j,i) = generate_pce_coefficient<Scalar>(
505 num_rows, num_cols, i,
j);
511 Kokkos::make_view<ViewType>( v.data(),
cijk, num_rows, num_cols );
519 template<
class ViewType >
532 Kokkos::parallel_for(
m_v.extent(0) , *this );
535 KOKKOS_INLINE_FUNCTION
551 typedef typename ViewType::size_type size_type;
552 typedef typename PCE::cijk_type Cijk;
559 const size_type num_rows = 11;
560 const size_type num_cols = cijk.dimension();
561 ViewType v = Kokkos::make_view<ViewType>(
"view",
cijk, num_rows, num_cols);
575 typedef typename ViewType::size_type size_type;
577 typedef typename PCE::cijk_type Cijk;
584 const size_type num_rows = 11;
585 const size_type num_cols = cijk.dimension();
586 ViewType v1 = Kokkos::make_view<ViewType>(
"view1",
cijk, num_rows, num_cols);
587 ViewType v2 = Kokkos::make_view<ViewType>(
"view2",
cijk, num_rows, num_cols);
593 auto s1 = Kokkos::subview(v1, std::make_pair(0, 1));
594 auto s2 = Kokkos::subview(v2, std::make_pair(0, 1));
596 s1.assign_data(s2.data());
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 ) \
619 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
620 Kokkos_View_PCE, AssignData, STORAGE, LAYOUT )
636 #define VIEW_UQ_PCE_TESTS_STORAGE( STORAGE ) \
637 using Kokkos::LayoutLeft; \
638 using Kokkos::LayoutRight; \
639 VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, NoLayout) \
640 VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, LayoutLeft) \
641 VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, LayoutRight) \
642 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
643 Kokkos_View_PCE, DeepCopy_Subview_Range, STORAGE )
645 #define VIEW_UQ_PCE_TESTS_ORDINAL_SCALAR_DEVICE( ORDINAL, SCALAR, DEVICE ) \
646 typedef Stokhos::DynamicStorage<ORDINAL,SCALAR,DEVICE> DS; \
647 VIEW_UQ_PCE_TESTS_STORAGE( DS )
649 #define VIEW_UQ_PCE_TESTS_DEVICE( DEVICE ) \
650 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)