47 #include "Stokhos_Ensemble_Sizes.hpp"
50 #include "Kokkos_Core.hpp"
59 template <
typename scalar,
typename ordinal>
63 const ordinal iColFEM,
64 const ordinal iStoch )
66 const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
67 const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
68 return X_fem + X_stoch;
72 template <
typename ViewType>
76 typedef ViewType view_type;
77 typedef typename view_type::size_type size_type;
78 typedef typename view_type::HostMirror host_view_type;
79 typedef typename host_view_type::array_type host_array_type;
85 host_array_type h_a = h_v;
87 size_type num_rows, num_cols;
91 bool is_right = std::is_same<
typename ViewType::array_layout,
94 num_rows = h_a.extent(0);
95 num_cols = h_a.extent(1);
98 num_rows = h_a.extent(1);
99 num_cols = h_a.extent(0);
103 for (size_type i=0; i<num_rows; ++i) {
104 for (size_type
j=0;
j<num_cols; ++
j) {
105 scalar_type
val = h_a(i,
j);
106 scalar_type val_expected =
107 generate_vector_coefficient<scalar_type>(
108 num_rows, num_cols, i,
j);
114 for (size_type i=0; i<num_rows; ++i) {
115 for (size_type
j=0;
j<num_cols; ++
j) {
116 scalar_type
val = h_a(
j,i);
117 scalar_type val_expected =
118 generate_vector_coefficient<scalar_type>(
119 num_rows, num_cols, i,
j);
128 template <
typename ViewType>
133 typedef ViewType view_type;
134 typedef typename view_type::size_type size_type;
135 typedef typename view_type::HostMirror host_view_type;
142 const size_type num_rows = h_v.extent(0);
145 for (size_type i=0; i<num_rows; ++i) {
146 for (size_type
j=0;
j<num_cols; ++
j) {
147 scalar_type
val = h_v(i).coeff(
j);
148 scalar_type val_expected = v_expected.coeff(
j);
156 template <
typename DataType,
typename LayoutType,
typename ExecutionSpace>
158 typedef Kokkos::View<DataType,LayoutType,ExecutionSpace>
type;
162 template <
typename DataType,
typename ExecutionSpace>
164 typedef Kokkos::View<DataType,ExecutionSpace>
type;
179 typedef typename ViewType::size_type size_type;
182 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
183 ViewType v(
"view", num_rows, num_cols);
193 typedef typename ViewType::size_type size_type;
194 typedef typename ViewType::HostMirror host_view_type;
195 typedef typename host_view_type::array_type host_array_type;
198 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
199 ViewType v(
"view", num_rows, num_cols);
201 host_array_type h_a = h_v;
203 bool is_right = std::is_same<
typename ViewType::array_layout,
206 for (size_type i=0; i<num_rows; ++i)
207 for (size_type
j=0;
j<num_cols; ++
j)
208 h_a(i,
j) = generate_vector_coefficient<Scalar>(
209 num_rows, num_cols, i,
j);
212 for (size_type i=0; i<num_rows; ++i)
213 for (size_type
j=0;
j<num_cols; ++
j)
214 h_a(
j,i) = generate_vector_coefficient<Scalar>(
215 num_rows, num_cols, i,
j);
228 typedef typename ViewType::size_type size_type;
231 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
232 ViewType v(
"view", num_rows, num_cols);
246 typedef typename ViewType::size_type size_type;
249 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
250 ViewType v(
"view", num_rows, num_cols);
264 typedef typename ViewType::size_type size_type;
267 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
268 ViewType v(
"view", num_rows, num_cols);
269 Vector
val(num_cols, 0.0);
270 for (size_type
j=0;
j<num_cols; ++
j)
271 val.fastAccessCoeff(
j) =
272 generate_vector_coefficient<Scalar>(num_rows, num_cols, size_type(0),
j);
285 typedef typename ViewType::size_type size_type;
286 typedef typename ViewType::HostMirror host_view_type;
290 const size_type num_cols = 5;
291 const size_type num_vec =
293 ViewType v1(
"view1", num_rows1, num_cols, num_vec);
294 ViewType v2(
"view2", num_rows2, num_cols, num_vec);
296 for (size_type
j=0;
j<num_cols; ++
j) {
297 std::pair<size_type,size_type> rows( 0, num_rows1 );
298 ViewType v1s = Kokkos::subview( v1, rows, std::pair<size_t,size_t> (
j,
j+1) );
299 ViewType v2s = Kokkos::subview( v2, rows, std::pair<size_t,size_t> (
j,
j+1) );
308 for (size_type
j=0;
j<num_cols; ++
j) {
309 for (size_type i=0; i<num_rows1; ++i) {
310 for (size_type k=0; k<num_vec; ++k) {
311 Scalar
val = hv2(i,
j).fastAccessCoeff(k);
312 Scalar val_expected =
j+1;
316 for (size_type i=num_rows1; i<num_rows2; ++i) {
317 for (size_type k=0; k<num_vec; ++k) {
318 Scalar
val = hv2(i,
j).fastAccessCoeff(k);
319 Scalar val_expected = 0;
332 typedef typename ViewType::size_type size_type;
333 typedef typename ViewType::HostMirror host_view_type;
334 typedef typename host_view_type::array_type host_array_type;
337 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
338 ViewType v(
"view", num_rows, num_cols);
341 bool is_right = std::is_same<
typename ViewType::array_layout,
344 for (size_type i=0; i<num_rows; ++i)
345 for (size_type
j=0;
j<num_cols; ++
j)
346 h_a(i,
j) = generate_vector_coefficient<Scalar>(
347 num_rows, num_cols, i,
j);
350 for (size_type i=0; i<num_rows; ++i)
351 for (size_type
j=0;
j<num_cols; ++
j)
352 h_a(
j,i) = generate_vector_coefficient<Scalar>(
353 num_rows, num_cols, i,
j);
366 typedef typename ViewType::size_type size_type;
367 typedef typename ViewType::HostMirror host_view_type;
368 typedef typename host_view_type::array_type host_array_type;
369 typedef typename ViewType::array_type array_type;
372 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
373 ViewType v(
"view", num_rows, num_cols);
375 host_array_type h_a = h_v;
378 for (size_type i=0; i<num_rows; ++i)
379 for (size_type
j=0;
j<num_cols; ++
j)
380 h_a(i,
j) = generate_vector_coefficient<Scalar>(
381 num_rows, num_cols, i,
j);
393 typedef typename ViewType::size_type size_type;
394 typedef typename ViewType::HostMirror host_view_type;
395 typedef typename host_view_type::array_type host_array_type;
398 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
399 ViewType v(
"view", num_rows, num_cols);
401 host_array_type h_a = h_v;
403 bool is_right = std::is_same<
typename ViewType::array_layout,
406 for (size_type i=0; i<num_rows; ++i)
407 for (size_type
j=0;
j<num_cols; ++
j)
408 h_a(i,
j) = generate_vector_coefficient<Scalar>(
409 num_rows, num_cols, i,
j);
412 for (size_type i=0; i<num_rows; ++i)
413 for (size_type
j=0;
j<num_cols; ++
j)
414 h_a(
j,i) = generate_vector_coefficient<Scalar>(
415 num_rows, num_cols, i,
j);
420 ViewType v2(v.data(), num_rows, num_cols);
431 typedef typename ViewType::size_type size_type;
432 typedef typename ViewType::HostMirror host_view_type;
435 const size_type num_cols = Storage::static_size;
436 ViewType v(
"view", num_rows, num_cols);
439 const size_type num_cols_part = num_cols/2;
440 auto h_v1 = Kokkos::partition<num_cols_part>(h_v, 0);
441 auto h_v2 = Kokkos::partition<num_cols_part>(h_v, num_cols_part);
443 for (size_type i=0; i<num_rows; ++i) {
444 for (size_type
j=0;
j<num_cols_part; ++
j) {
445 h_v1(i).fastAccessCoeff(
j) = generate_vector_coefficient<Scalar>(
446 num_rows, num_cols, i,
j);
447 h_v2(i).fastAccessCoeff(
j) = generate_vector_coefficient<Scalar>(
448 num_rows, num_cols, i,
j+num_cols_part);
504 typedef typename ViewType::size_type size_type;
506 typedef typename flat_view_type::HostMirror host_flat_view_type;
509 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
510 ViewType v(
"view", num_rows, num_cols);
513 flat_view_type flat_v = v;
515 for (size_type i=0; i<num_rows; ++i)
516 for (size_type
j=0;
j<num_cols; ++
j)
517 h_flat_v(i*num_cols+
j) = generate_vector_coefficient<Scalar>(
518 num_rows, num_cols, i,
j);
526 template<
class ViewType >
538 Kokkos::parallel_for(
m_v.extent(0) , *this );
541 KOKKOS_INLINE_FUNCTION
557 typedef typename ViewType::size_type size_type;
560 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
561 ViewType v(
"view", num_rows, num_cols);
575 typedef typename ViewType::size_type size_type;
578 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
579 ViewType v1(
"view1", num_rows, num_cols);
580 ViewType v2(
"view2", num_rows, num_cols);
586 auto s1 = Kokkos::subview(v1, std::make_pair(0, 1));
587 auto s2 = Kokkos::subview(v2, std::make_pair(0, 1));
589 s1.assign_data(s2.data());
595 #define VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT( STORAGE, LAYOUT ) \
596 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
597 Kokkos_View_MP, Size, STORAGE, LAYOUT ) \
598 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
599 Kokkos_View_MP, DeepCopy, STORAGE, LAYOUT ) \
600 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
601 Kokkos_View_MP, DeepCopy_ConstantScalar, STORAGE, LAYOUT ) \
602 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
603 Kokkos_View_MP, DeepCopy_ConstantVector, STORAGE, LAYOUT ) \
604 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
605 Kokkos_View_MP, DeepCopy_ConstantVector2, STORAGE, LAYOUT ) \
606 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
607 Kokkos_View_MP, Unmanaged, STORAGE, LAYOUT ) \
608 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
609 Kokkos_View_MP, Flatten, STORAGE, LAYOUT ) \
610 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
611 Kokkos_View_MP, AssignData, STORAGE, LAYOUT )
627 #define VIEW_MP_VECTOR_TESTS_STORAGE( STORAGE ) \
628 using Kokkos::LayoutLeft; \
629 using Kokkos::LayoutRight; \
630 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, NoLayout) \
631 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, LayoutLeft) \
632 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, LayoutRight) \
633 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
634 Kokkos_View_MP, DeepCopy_Subview_Range, STORAGE )
636 #define VIEW_MP_VECTOR_TESTS_ORDINAL_SCALAR_DEVICE( ORDINAL, SCALAR, DEVICE ) \
637 typedef Stokhos::StaticFixedStorage<ORDINAL,SCALAR,global_num_cols,DEVICE> SFS; \
638 typedef Stokhos::DynamicStorage<ORDINAL,SCALAR,DEVICE> DS; \
639 VIEW_MP_VECTOR_TESTS_STORAGE( SFS ) \
640 VIEW_MP_VECTOR_TESTS_STORAGE( DS ) \
641 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
642 Kokkos_View_MP, PartitionHost, SFS, NoLayout ) \
643 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
644 Kokkos_View_MP, PartitionHost, SFS, LayoutLeft ) \
645 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
646 Kokkos_View_MP, PartitionHost, SFS, LayoutRight )
648 #define VIEW_MP_VECTOR_TESTS_DEVICE( DEVICE ) \
649 VIEW_MP_VECTOR_TESTS_ORDINAL_SCALAR_DEVICE( int, double, DEVICE )
ViewType::value_type vector_type
bool checkConstantVectorView(const ViewType &v, const typename ViewType::value_type &v_expected, Teuchos::FancyOStream &out)
KOKKOS_INLINE_FUNCTION void operator()(int i) const
Kokkos::DefaultExecutionSpace execution_space
scalar generate_vector_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch)
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P...> >::value, unsigned >::type dimension_scalar(const View< T, P...> &view)
vector_type::storage_type::value_type scalar_type
const int global_num_cols
bool checkVectorView(const ViewType &v, Teuchos::FancyOStream &out)
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Kokkos_SG_SpMv, CrsProductTensorCijk, Scalar, Device)
KOKKOS_INLINE_FUNCTION void atomic_assign(volatile Sacado::UQ::PCE< Storage > *const dest, const Sacado::UQ::PCE< Storage > &src)
Kokkos::View< DataType, ExecutionSpace > type
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
const int global_num_rows
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
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
ViewType::execution_space execution_space
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)
MPVectorAtomicFunctor(const ViewType &v, const scalar_type &s)