42 #include "Teuchos_TestingHelpers.hpp" 43 #include "Teuchos_UnitTestHelpers.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>
75 Teuchos::FancyOStream& out) {
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 = Kokkos::Impl::is_same<
typename ViewType::array_layout,
93 if (is_right || !view_type::is_contiguous) {
94 num_rows = h_a.dimension_0();
95 num_cols = h_a.dimension_1();
98 num_rows = h_a.dimension_1();
99 num_cols = h_a.dimension_0();
102 if (is_right || !view_type::is_contiguous) {
103 for (size_type i=0; i<num_rows; ++i) {
104 for (size_type
j=0;
j<num_cols; ++
j) {
107 generate_vector_coefficient<scalar_type>(
108 num_rows, num_cols, i,
j);
109 TEUCHOS_TEST_EQUALITY(
val, val_expected, out, success);
114 for (size_type i=0; i<num_rows; ++i) {
115 for (size_type
j=0;
j<num_cols; ++
j) {
118 generate_vector_coefficient<scalar_type>(
119 num_rows, num_cols, i,
j);
120 TEUCHOS_TEST_EQUALITY(
val, val_expected, out, success);
128 template <
typename ViewType>
132 Teuchos::FancyOStream& out) {
133 typedef ViewType view_type;
137 typedef typename view_type::size_type size_type;
138 typedef typename view_type::HostMirror host_view_type;
144 const size_type num_rows = h_view.dimension_0();
146 const size_type num_ensemble = storage_type::static_size;
148 for (size_type i=0; i<num_rows; ++i) {
149 for (size_type k=0; k<num_ensemble; ++k) {
150 TEUCHOS_TEST_EQUALITY(h_view(i).
val().coeff(k), v.val().coeff(k), out, success);
151 for (size_type
j=0;
j<num_fad; ++
j) {
152 TEUCHOS_TEST_EQUALITY(h_view(i).
dx(
j).coeff(k), v.dx(
j).coeff(k), out, success);
160 template <
typename ViewType>
164 Teuchos::FancyOStream& out) {
165 typedef ViewType view_type;
169 typedef typename view_type::size_type size_type;
170 typedef typename view_type::HostMirror host_view_type;
178 const size_type num_ensemble = storage_type::static_size;
179 for (size_type i0=0; i0<h_view.dimension_0(); ++i0) {
180 for (size_type i1=0; i1<h_view.dimension_1(); ++i1) {
181 for (size_type i2=0; i2<h_view.dimension_2(); ++i2) {
182 for (size_type i3=0; i3<h_view.dimension_3(); ++i3) {
183 for (size_type i4=0; i4<h_view.dimension_4(); ++i4) {
184 for (size_type i5=0; i5<h_view.dimension_5(); ++i5) {
185 for (size_type i6=0; i6<h_view.dimension_6(); ++i6) {
186 for (size_type k=0; k<num_ensemble; ++k)
187 TEUCHOS_TEST_EQUALITY(h_view(i0,i1,i2,i3,i4,i5,i6,0).val().coeff(k),
188 v.val().coeff(k), out, success);
189 for (size_type
j=0;
j<num_fad; ++
j) {
190 for (size_type k=0; k<num_ensemble; ++k)
191 TEUCHOS_TEST_EQUALITY(h_view(i0,i1,i2,i3,i4,i5,i6,0).dx(
j).coeff(k),
192 v.dx(
j).coeff(k), out, success);
199 template <
typename DataType,
typename LayoutType,
typename ExecutionSpace>
201 typedef Kokkos::View<DataType,LayoutType,ExecutionSpace>
type;
205 template <
typename DataType,
typename ExecutionSpace>
207 typedef Kokkos::View<DataType,ExecutionSpace>
type;
223 typedef typename ViewType::size_type size_type;
227 ViewType v(
"view", num_rows, num_cols);
228 TEUCHOS_TEST_EQUALITY(v.size(), num_rows, out, success);
237 typedef typename ViewType::size_type size_type;
241 ViewType v(
"view", num_rows, num_cols);
242 BaseScalar
val = 1.2345;
258 BaseScalar
val = 1.2345;
265 #define VIEW_FAD_MP_VECTOR_TESTS_SCALAR_LAYOUT( SCALAR, LAYOUT ) \ 266 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 267 Kokkos_View_Fad_MP, Size, SCALAR, LAYOUT ) \ 268 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 269 Kokkos_View_Fad_MP, DeepCopy_ConstantScalar, SCALAR, LAYOUT ) \ 270 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ 271 Kokkos_View_Fad_MP, Rank6, SCALAR, LAYOUT ) 273 #define VIEW_FAD_MP_VECTOR_TESTS_SCALAR( SCALAR ) \ 274 using Kokkos::LayoutLeft; \ 275 using Kokkos::LayoutRight; \ 276 VIEW_FAD_MP_VECTOR_TESTS_SCALAR_LAYOUT(SCALAR, NoLayout) \ 277 VIEW_FAD_MP_VECTOR_TESTS_SCALAR_LAYOUT(SCALAR, LayoutLeft) \ 278 VIEW_FAD_MP_VECTOR_TESTS_SCALAR_LAYOUT(SCALAR, LayoutRight) 280 #define VIEW_FAD_MP_VECTOR_TESTS_DEVICE( DEVICE ) \ 281 typedef Stokhos::StaticFixedStorage<int,double,global_ensemble_size,DEVICE> SFS; \ 282 typedef Sacado::MP::Vector< SFS > MP_SFS; \ 283 typedef Sacado::Fad::DFad< MP_SFS > Fad_MP_SFS; \ 284 VIEW_FAD_MP_VECTOR_TESTS_SCALAR( Fad_MP_SFS )
const int global_ensemble_size
Stokhos::StandardStorage< int, double > storage_type
Kokkos::DefaultExecutionSpace execution_space
bool checkConstantFadVectorView2(const ViewType &view, const typename ViewType::value_type &v, Teuchos::FancyOStream &out)
bool checkVectorView(const ViewType &v, Teuchos::FancyOStream &out)
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Kokkos_View_Fad_MP, Size, Scalar, Layout)
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_fad_size
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
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
bool checkConstantFadVectorView(const ViewType &view, const typename ViewType::value_type &v, Teuchos::FancyOStream &out)
Kokkos::View< DataType, LayoutType, ExecutionSpace > type
scalar generate_vector_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch)
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)