15 #include "Stokhos_Ensemble_Sizes.hpp"
18 #include "Kokkos_Core.hpp"
27 template <
typename scalar,
typename ordinal>
31 const ordinal iColFEM,
32 const ordinal iStoch )
34 const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
35 const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
36 return X_fem + X_stoch;
40 template <
typename ViewType>
44 typedef ViewType view_type;
45 typedef typename view_type::size_type size_type;
46 typedef typename view_type::HostMirror host_view_type;
47 typedef typename host_view_type::array_type host_array_type;
53 host_array_type h_a = h_v;
55 size_type num_rows, num_cols;
59 bool is_right = std::is_same<
typename ViewType::array_layout,
62 num_rows = h_a.extent(0);
63 num_cols = h_a.extent(1);
66 num_rows = h_a.extent(1);
67 num_cols = h_a.extent(0);
71 for (size_type i=0; i<num_rows; ++i) {
72 for (size_type
j=0;
j<num_cols; ++
j) {
73 scalar_type
val = h_a(i,
j);
74 scalar_type val_expected =
75 generate_vector_coefficient<scalar_type>(
76 num_rows, num_cols, i,
j);
82 for (size_type i=0; i<num_rows; ++i) {
83 for (size_type
j=0;
j<num_cols; ++
j) {
84 scalar_type
val = h_a(
j,i);
85 scalar_type val_expected =
86 generate_vector_coefficient<scalar_type>(
87 num_rows, num_cols, i,
j);
96 template <
typename ViewType>
101 typedef ViewType view_type;
102 typedef typename view_type::size_type size_type;
103 typedef typename view_type::HostMirror host_view_type;
110 const size_type num_rows = h_v.extent(0);
113 for (size_type i=0; i<num_rows; ++i) {
114 for (size_type
j=0;
j<num_cols; ++
j) {
115 scalar_type
val = h_v(i).coeff(
j);
116 scalar_type val_expected = v_expected.coeff(
j);
124 template <
typename DataType,
typename LayoutType,
typename ExecutionSpace>
126 typedef Kokkos::View<DataType,LayoutType,ExecutionSpace>
type;
130 template <
typename DataType,
typename ExecutionSpace>
132 typedef Kokkos::View<DataType,ExecutionSpace>
type;
147 typedef typename ViewType::size_type size_type;
150 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
151 ViewType v(
"view", num_rows, num_cols);
161 typedef typename ViewType::size_type size_type;
162 typedef typename ViewType::HostMirror host_view_type;
163 typedef typename host_view_type::array_type host_array_type;
166 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
167 ViewType v(
"view", num_rows, num_cols);
169 host_array_type h_a = h_v;
171 bool is_right = std::is_same<
typename ViewType::array_layout,
174 for (size_type i=0; i<num_rows; ++i)
175 for (size_type
j=0;
j<num_cols; ++
j)
176 h_a(i,
j) = generate_vector_coefficient<Scalar>(
177 num_rows, num_cols, i,
j);
180 for (size_type i=0; i<num_rows; ++i)
181 for (size_type
j=0;
j<num_cols; ++
j)
182 h_a(
j,i) = generate_vector_coefficient<Scalar>(
183 num_rows, num_cols, i,
j);
196 typedef typename ViewType::size_type size_type;
199 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
200 ViewType v(
"view", num_rows, num_cols);
214 typedef typename ViewType::size_type size_type;
217 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
218 ViewType v(
"view", num_rows, num_cols);
232 typedef typename ViewType::size_type size_type;
235 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
236 ViewType v(
"view", num_rows, num_cols);
237 Vector
val(num_cols, 0.0);
238 for (size_type
j=0;
j<num_cols; ++
j)
239 val.fastAccessCoeff(
j) =
240 generate_vector_coefficient<Scalar>(num_rows, num_cols, size_type(0),
j);
253 typedef typename ViewType::size_type size_type;
254 typedef typename ViewType::HostMirror host_view_type;
258 const size_type num_cols = 5;
259 const size_type num_vec =
261 ViewType v1(
"view1", num_rows1, num_cols, num_vec);
262 ViewType v2(
"view2", num_rows2, num_cols, num_vec);
264 for (size_type
j=0;
j<num_cols; ++
j) {
265 std::pair<size_type,size_type> rows( 0, num_rows1 );
266 ViewType v1s = Kokkos::subview( v1, rows, std::pair<size_t,size_t> (
j,
j+1) );
267 ViewType v2s = Kokkos::subview( v2, rows, std::pair<size_t,size_t> (
j,
j+1) );
276 for (size_type
j=0;
j<num_cols; ++
j) {
277 for (size_type i=0; i<num_rows1; ++i) {
278 for (size_type k=0; k<num_vec; ++k) {
279 Scalar
val = hv2(i,
j).fastAccessCoeff(k);
280 Scalar val_expected =
j+1;
284 for (size_type i=num_rows1; i<num_rows2; ++i) {
285 for (size_type k=0; k<num_vec; ++k) {
286 Scalar
val = hv2(i,
j).fastAccessCoeff(k);
287 Scalar val_expected = 0;
300 typedef typename ViewType::size_type size_type;
301 typedef typename ViewType::HostMirror host_view_type;
302 typedef typename host_view_type::array_type host_array_type;
305 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
306 ViewType v(
"view", num_rows, num_cols);
309 bool is_right = std::is_same<
typename ViewType::array_layout,
312 for (size_type i=0; i<num_rows; ++i)
313 for (size_type
j=0;
j<num_cols; ++
j)
314 h_a(i,
j) = generate_vector_coefficient<Scalar>(
315 num_rows, num_cols, i,
j);
318 for (size_type i=0; i<num_rows; ++i)
319 for (size_type
j=0;
j<num_cols; ++
j)
320 h_a(
j,i) = generate_vector_coefficient<Scalar>(
321 num_rows, num_cols, i,
j);
334 typedef typename ViewType::size_type size_type;
335 typedef typename ViewType::HostMirror host_view_type;
336 typedef typename host_view_type::array_type host_array_type;
337 typedef typename ViewType::array_type array_type;
340 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
341 ViewType v(
"view", num_rows, num_cols);
343 host_array_type h_a = h_v;
346 for (size_type i=0; i<num_rows; ++i)
347 for (size_type
j=0;
j<num_cols; ++
j)
348 h_a(i,
j) = generate_vector_coefficient<Scalar>(
349 num_rows, num_cols, i,
j);
361 typedef typename ViewType::size_type size_type;
362 typedef typename ViewType::HostMirror host_view_type;
363 typedef typename host_view_type::array_type host_array_type;
366 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
367 ViewType v(
"view", num_rows, num_cols);
369 host_array_type h_a = h_v;
371 bool is_right = std::is_same<
typename ViewType::array_layout,
374 for (size_type i=0; i<num_rows; ++i)
375 for (size_type
j=0;
j<num_cols; ++
j)
376 h_a(i,
j) = generate_vector_coefficient<Scalar>(
377 num_rows, num_cols, i,
j);
380 for (size_type i=0; i<num_rows; ++i)
381 for (size_type
j=0;
j<num_cols; ++
j)
382 h_a(
j,i) = generate_vector_coefficient<Scalar>(
383 num_rows, num_cols, i,
j);
388 ViewType v2(v.data(), num_rows, num_cols);
399 typedef typename ViewType::size_type size_type;
400 typedef typename ViewType::HostMirror host_view_type;
403 const size_type num_cols = Storage::static_size;
404 ViewType v(
"view", num_rows, num_cols);
407 const size_type num_cols_part = num_cols/2;
408 auto h_v1 = Kokkos::partition<num_cols_part>(h_v, 0);
409 auto h_v2 = Kokkos::partition<num_cols_part>(h_v, num_cols_part);
411 for (size_type i=0; i<num_rows; ++i) {
412 for (size_type
j=0;
j<num_cols_part; ++
j) {
413 h_v1(i).fastAccessCoeff(
j) = generate_vector_coefficient<Scalar>(
414 num_rows, num_cols, i,
j);
415 h_v2(i).fastAccessCoeff(
j) = generate_vector_coefficient<Scalar>(
416 num_rows, num_cols, i,
j+num_cols_part);
472 typedef typename ViewType::size_type size_type;
474 typedef typename flat_view_type::HostMirror host_flat_view_type;
477 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
478 ViewType v(
"view", num_rows, num_cols);
481 flat_view_type flat_v = v;
483 for (size_type i=0; i<num_rows; ++i)
484 for (size_type
j=0;
j<num_cols; ++
j)
485 h_flat_v(i*num_cols+
j) = generate_vector_coefficient<Scalar>(
486 num_rows, num_cols, i,
j);
494 template<
class ViewType >
506 Kokkos::parallel_for(
m_v.extent(0) , *this );
509 KOKKOS_INLINE_FUNCTION
525 typedef typename ViewType::size_type size_type;
528 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
529 ViewType v(
"view", num_rows, num_cols);
543 typedef typename ViewType::size_type size_type;
546 const size_type num_cols = Storage::is_static ? Storage::static_size :
global_num_cols;
547 ViewType v1(
"view1", num_rows, num_cols);
548 ViewType v2(
"view2", num_rows, num_cols);
554 auto s1 = Kokkos::subview(v1, std::make_pair(0, 1));
555 auto s2 = Kokkos::subview(v2, std::make_pair(0, 1));
557 s1.assign_data(s2.data());
563 #define VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT( STORAGE, LAYOUT ) \
564 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
565 Kokkos_View_MP, Size, STORAGE, LAYOUT ) \
566 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
567 Kokkos_View_MP, DeepCopy, STORAGE, LAYOUT ) \
568 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
569 Kokkos_View_MP, DeepCopy_ConstantScalar, STORAGE, LAYOUT ) \
570 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
571 Kokkos_View_MP, DeepCopy_ConstantVector, STORAGE, LAYOUT ) \
572 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
573 Kokkos_View_MP, DeepCopy_ConstantVector2, STORAGE, LAYOUT ) \
574 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
575 Kokkos_View_MP, Unmanaged, STORAGE, LAYOUT ) \
576 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
577 Kokkos_View_MP, Flatten, STORAGE, LAYOUT ) \
578 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
579 Kokkos_View_MP, AssignData, STORAGE, LAYOUT )
595 #define VIEW_MP_VECTOR_TESTS_STORAGE( STORAGE ) \
596 using Kokkos::LayoutLeft; \
597 using Kokkos::LayoutRight; \
598 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, NoLayout) \
599 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, LayoutLeft) \
600 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, LayoutRight) \
601 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
602 Kokkos_View_MP, DeepCopy_Subview_Range, STORAGE )
606 #define VIEW_MP_VECTOR_TESTS_ORDINAL_SCALAR_DEVICE( ORDINAL, SCALAR, DEVICE ) \
607 typedef Stokhos::StaticFixedStorage<ORDINAL,SCALAR,global_num_cols,DEVICE> SFS; \
608 VIEW_MP_VECTOR_TESTS_STORAGE( SFS ) \
609 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
610 Kokkos_View_MP, PartitionHost, SFS, NoLayout ) \
611 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
612 Kokkos_View_MP, PartitionHost, SFS, LayoutLeft ) \
613 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
614 Kokkos_View_MP, PartitionHost, SFS, LayoutRight )
616 #define VIEW_MP_VECTOR_TESTS_DEVICE( DEVICE ) \
617 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)