42 #include "Teuchos_TestingHelpers.hpp" 43 #include "Teuchos_UnitTestHelpers.hpp" 49 #include "Kokkos_Core.hpp" 58 template <
typename scalar,
typename ordinal>
62 const ordinal iColFEM,
63 const ordinal iStoch )
65 const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
66 const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
67 return X_fem + X_stoch;
71 template <
typename ViewType>
74 Teuchos::FancyOStream& out) {
75 typedef ViewType view_type;
76 typedef typename view_type::size_type size_type;
77 typedef typename view_type::HostMirror host_view_type;
78 typedef typename host_view_type::array_type host_array_type;
84 host_array_type h_a = h_v;
86 size_type num_rows, num_cols;
90 bool is_right = Kokkos::Impl::is_same<
typename ViewType::array_layout,
93 num_rows = h_a.dimension_0();
94 num_cols = h_a.dimension_1();
97 num_rows = h_a.dimension_1();
98 num_cols = h_a.dimension_0();
102 for (size_type i=0; i<num_rows; ++i) {
103 for (size_type
j=0;
j<num_cols; ++
j) {
106 generate_vector_coefficient<scalar_type>(
107 num_rows, num_cols, i,
j);
108 TEUCHOS_TEST_EQUALITY(
val, val_expected, out, success);
113 for (size_type i=0; i<num_rows; ++i) {
114 for (size_type
j=0;
j<num_cols; ++
j) {
117 generate_vector_coefficient<scalar_type>(
118 num_rows, num_cols, i,
j);
119 TEUCHOS_TEST_EQUALITY(
val, val_expected, out, success);
127 template <
typename ViewType>
131 Teuchos::FancyOStream& out) {
132 typedef ViewType view_type;
133 typedef typename view_type::size_type size_type;
134 typedef typename view_type::HostMirror host_view_type;
141 const size_type num_rows = h_v.dimension_0();
144 for (size_type i=0; i<num_rows; ++i) {
145 for (size_type
j=0;
j<num_cols; ++
j) {
147 scalar_type val_expected = v_expected.fastAccessCoeff(
j);
148 TEUCHOS_TEST_EQUALITY(
val, val_expected, out, success);
155 template <
typename DataType,
typename LayoutType,
typename ExecutionSpace>
157 typedef Kokkos::View<DataType,LayoutType,ExecutionSpace>
type;
161 template <
typename DataType,
typename ExecutionSpace>
163 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);
184 TEUCHOS_TEST_EQUALITY(v.size(), num_rows, out, success);
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 = Kokkos::Impl::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) {
313 TEUCHOS_TEST_EQUALITY(
val, val_expected, out, success);
316 for (size_type i=num_rows1; i<num_rows2; ++i) {
317 for (size_type k=0; k<num_vec; ++k) {
320 TEUCHOS_TEST_EQUALITY(
val, val_expected, out, success);
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 = Kokkos::Impl::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 = Kokkos::Impl::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.ptr_on_device(), 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.dimension_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);
570 #define VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT( STORAGE, LAYOUT ) \ 571 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 572 Kokkos_View_MP, Size, STORAGE, LAYOUT ) \ 573 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 574 Kokkos_View_MP, DeepCopy, STORAGE, LAYOUT ) \ 575 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 576 Kokkos_View_MP, DeepCopy_ConstantScalar, STORAGE, LAYOUT ) \ 577 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 578 Kokkos_View_MP, DeepCopy_ConstantVector, STORAGE, LAYOUT ) \ 579 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 580 Kokkos_View_MP, DeepCopy_ConstantVector2, STORAGE, LAYOUT ) \ 581 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 582 Kokkos_View_MP, Unmanaged, STORAGE, LAYOUT ) \ 583 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 584 Kokkos_View_MP, Flatten, STORAGE, LAYOUT ) 600 #define VIEW_MP_VECTOR_TESTS_STORAGE( STORAGE ) \ 601 using Kokkos::LayoutLeft; \ 602 using Kokkos::LayoutRight; \ 603 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, NoLayout) \ 604 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, LayoutLeft) \ 605 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, LayoutRight) \ 606 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \ 607 Kokkos_View_MP, DeepCopy_Subview_Range, STORAGE ) 609 #define VIEW_MP_VECTOR_TESTS_ORDINAL_SCALAR_DEVICE( ORDINAL, SCALAR, DEVICE ) \ 610 typedef Stokhos::StaticFixedStorage<ORDINAL,SCALAR,global_num_cols,DEVICE> SFS; \ 611 typedef Stokhos::DynamicStorage<ORDINAL,SCALAR,DEVICE> DS; \ 612 VIEW_MP_VECTOR_TESTS_STORAGE( SFS ) \ 613 VIEW_MP_VECTOR_TESTS_STORAGE( DS ) \ 614 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 615 Kokkos_View_MP, PartitionHost, SFS, NoLayout ) \ 616 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 617 Kokkos_View_MP, PartitionHost, SFS, LayoutLeft ) \ 618 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 619 Kokkos_View_MP, PartitionHost, SFS, LayoutRight ) 621 #define VIEW_MP_VECTOR_TESTS_DEVICE( DEVICE ) \ 622 VIEW_MP_VECTOR_TESTS_ORDINAL_SCALAR_DEVICE( int, double, DEVICE )
scalar generate_vector_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch)
ViewType::value_type vector_type
bool checkConstantVectorView(const ViewType &v, const typename ViewType::value_type &v_expected, Teuchos::FancyOStream &out)
const int global_num_rows
Kokkos::DefaultExecutionSpace execution_space
bool checkVectorView(const ViewType &v, Teuchos::FancyOStream &out)
vector_type::storage_type::value_type scalar_type
const int global_num_cols
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Kokkos_View_MP, DeepCopy_Subview_Range, Storage)
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Kokkos_View_MP, Size, Storage, Layout)
KOKKOS_INLINE_FUNCTION void atomic_assign(volatile Sacado::UQ::PCE< Storage > *const dest, const Sacado::UQ::PCE< Storage > &src)
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P... > >::value, unsigned >::type dimension_scalar(const View< T, P... > &view)
Kokkos::View< DataType, ExecutionSpace > type
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
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)
KOKKOS_INLINE_FUNCTION void operator()(int i) const