| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Belos: Block Linear Solvers Package |
| 4 |
// |
| 5 |
// Copyright 2004-2016 NTESS and the Belos contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
// |
| 10 |
// This test uses the MVOPTester.hpp functions to test the Belos adapters |
| 11 |
// to Kokkos. |
| 12 |
// |
| 13 |
|
| 14 |
|
| 15 |
#include "BelosConfigDefs.hpp" |
| 16 |
#include "BelosKokkosMVOPTester.hpp" |
| 17 |
#include "BelosOutputManager.hpp" |
| 18 |
#include "BelosKokkosAdapter.hpp" |
| 19 |
#include "KokkosSparse_IOUtils.hpp" |
| 20 |
|
| 21 |
#include "Teuchos_StandardCatchMacros.hpp" |
| 22 |
#ifdef HAVE_MPI |
| 23 |
#include <mpi.h> |
| 24 |
#endif |
| 25 |
|
| 26 |
using std::cout; |
| 27 |
using std::endl; |
| 28 |
using Teuchos::RCP; |
| 29 |
using Belos::Warnings; |
| 30 |
using Belos::OutputManager; |
| 31 |
|
| 32 |
template <class ScalarType> |
| 33 |
bool TestKokkosMultiVecOneScalar(const Teuchos::RCP<OutputManager<ScalarType> >& ); |
| 34 |
|
| 35 |
template <class ScalarType1, class ScalarType2> |
| 36 |
bool TestKokkosMultiVecTwoScalar(const Teuchos::RCP<OutputManager<ScalarType1> > & outputMgr); |
| 37 |
|
| 38 |
int main(int argc, char *argv[]) |
| 39 |
{ |
| 40 |
#ifdef HAVE_MPI |
| 41 |
MPI_Init(&argc,&argv); |
| 42 |
#endif |
| 43 |
bool isPassed; |
| 44 |
bool success = true; |
| 45 |
Kokkos::initialize(); |
| 46 |
{ |
| 47 |
bool verbose = false; |
| 48 |
if (argc>1) { |
| 49 |
if (argv[1][0]=='-' && argv[1][1]=='v') { |
| 50 |
verbose = true; |
| 51 |
} |
| 52 |
} |
| 53 |
typedef double ScalarType; |
| 54 |
typedef float ScalarType2; |
| 55 |
typedef Belos::MultiVec<ScalarType> KMV; |
| 56 |
typedef Belos::Operator<ScalarType> KOP; |
| 57 |
typedef Belos::MultiVec<ScalarType2> KMV2; |
| 58 |
typedef Belos::Operator<ScalarType2> KOP2; |
| 59 |
typedef Kokkos::DefaultExecutionSpace EXSP; |
| 60 |
|
| 61 |
// Create an output manager to handle the I/O from the solver (defaults to std::cout). |
| 62 |
Teuchos::RCP<Belos::OutputManager<ScalarType> > myOutputMgr = Teuchos::rcp( new Belos::OutputManager<ScalarType>() ); |
| 63 |
Teuchos::RCP<Belos::OutputManager<ScalarType2> > myOutputMgr2 = Teuchos::rcp( new Belos::OutputManager<ScalarType2>() ); |
| 64 |
if (verbose) { |
| 65 |
myOutputMgr->setVerbosity( Warnings ); |
| 66 |
myOutputMgr2->setVerbosity( Warnings ); |
| 67 |
} |
| 68 |
try { |
| 69 |
// number of global elements |
| 70 |
int dim = 10; |
| 71 |
int blockSize = 5; |
| 72 |
std::vector<ScalarType> norms(blockSize); |
| 73 |
|
| 74 |
|
| 75 |
//***************************************************************************************************************************** |
| 76 |
//***************************************************************************************************************************** |
| 77 |
// Run native Kokkos::Multivec test (double). |
| 78 |
isPassed = TestKokkosMultiVecOneScalar<ScalarType>(myOutputMgr); |
| 79 |
success = isPassed && success; |
| 80 |
if (isPassed) { |
| 81 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter PASSED TestKokkosMultiVecOneScalar() double. \n"); |
| 82 |
} |
| 83 |
else { |
| 84 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter FAILED TestKokkosMultiVecOneScalar() double. ***\n\n"); |
| 85 |
} |
| 86 |
|
| 87 |
// Run native Kokkos::Multivec test (single). |
| 88 |
isPassed = TestKokkosMultiVecOneScalar<ScalarType2>(myOutputMgr2); |
| 89 |
success = isPassed && success; |
| 90 |
if (isPassed) { |
| 91 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter PASSED TestKokkosMultiVecOneScalar() single. \n"); |
| 92 |
} |
| 93 |
else { |
| 94 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter FAILED TestKokkosMultiVecOneScalar() single. ***\n\n"); |
| 95 |
} |
| 96 |
|
| 97 |
//***************************************************************************************************************************** |
| 98 |
//***************************************************************************************************************************** |
| 99 |
// Run native Kokkos::Multivec tests with mixed single-double precisions: |
| 100 |
isPassed = TestKokkosMultiVecTwoScalar<ScalarType, ScalarType2>(myOutputMgr); |
| 101 |
success = isPassed && success; |
| 102 |
if (isPassed) { |
| 103 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter PASSED TestKokkosMultiVecTwoScalar() \n"); |
| 104 |
} |
| 105 |
else { |
| 106 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter FAILED TestKokkosMultiVecTwoScalar() ***\n\n"); |
| 107 |
} |
| 108 |
|
| 109 |
//***************************************************************************************************************************** |
| 110 |
//***************************************************************************************************************************** |
| 111 |
// Run Belos tests on Kokkos MultiVec (double precision): |
| 112 |
Teuchos::RCP<Belos::KokkosMultiVec<ScalarType>> ivec = Teuchos::rcp( new Belos::KokkosMultiVec<ScalarType>(dim, blockSize) ); |
| 113 |
ivec->MvRandom(); |
| 114 |
isPassed = Belos::TestKokkosMultiVecTraits<ScalarType,KMV>(myOutputMgr,ivec); |
| 115 |
success = isPassed && success; |
| 116 |
if (isPassed) { |
| 117 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter PASSED TestMultiVecTraits() double.\n"); |
| 118 |
} |
| 119 |
else { |
| 120 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter FAILED TestMultiVecTraits() double. ***\n\n"); |
| 121 |
} |
| 122 |
|
| 123 |
// Run Belos tests on Kokkos MultiVec (single precision): |
| 124 |
Teuchos::RCP<Belos::KokkosMultiVec<ScalarType2>> ivec_2 = Teuchos::rcp( new Belos::KokkosMultiVec<ScalarType2>(dim, blockSize) ); |
| 125 |
ivec_2->MvRandom(); |
| 126 |
isPassed = Belos::TestKokkosMultiVecTraits<ScalarType2,KMV2>(myOutputMgr2,ivec_2); |
| 127 |
success = isPassed && success; |
| 128 |
if (isPassed) { |
| 129 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter PASSED TestMultiVecTraits() single. \n"); |
| 130 |
} |
| 131 |
else { |
| 132 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter FAILED TestMultiVecTraits() single. ***\n\n"); |
| 133 |
} |
| 134 |
//***************************************************************************************************************************** |
| 135 |
//***************************************************************************************************************************** |
| 136 |
// Read in a matrix Market file and use it to test the Kokkos Operator (double precision). |
| 137 |
KokkosSparse::CrsMatrix<ScalarType, int, EXSP> crsMat = |
| 138 |
KokkosSparse::Impl::read_kokkos_crst_matrix<KokkosSparse::CrsMatrix<ScalarType, int, EXSP>>("bcsstk13.mtx"); |
| 139 |
Teuchos::RCP<Belos::KokkosCrsOperator<ScalarType, int, EXSP>> myOp = |
| 140 |
Teuchos::rcp(new Belos::KokkosCrsOperator<ScalarType,int,EXSP>(crsMat)); |
| 141 |
|
| 142 |
Teuchos::RCP<Belos::KokkosMultiVec<ScalarType>> ivec3 = Teuchos::rcp( new Belos::KokkosMultiVec<ScalarType>(2003, 2) ); |
| 143 |
|
| 144 |
isPassed = Belos::TestKokkosOperatorTraits<ScalarType,KMV,KOP>(myOutputMgr,ivec3,myOp); |
| 145 |
success = isPassed && success; |
| 146 |
if (isPassed) { |
| 147 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter PASSED TestOperatorTraits() double. \n"); |
| 148 |
} |
| 149 |
else { |
| 150 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter FAILED TestOperatorTraits() double ***\n\n"); |
| 151 |
} |
| 152 |
// Read in a matrix Market file and use it to test the Kokkos Operator (single precision). |
| 153 |
KokkosSparse::CrsMatrix<ScalarType2, int, EXSP> crsMat2 = |
| 154 |
KokkosSparse::Impl::read_kokkos_crst_matrix<KokkosSparse::CrsMatrix<ScalarType2, int, EXSP>>("bcsstk13.mtx"); |
| 155 |
Teuchos::RCP<Belos::KokkosCrsOperator<ScalarType2, int, EXSP>> myOp2 = |
| 156 |
Teuchos::rcp(new Belos::KokkosCrsOperator<ScalarType2,int,EXSP>(crsMat2)); |
| 157 |
|
| 158 |
Teuchos::RCP<Belos::KokkosMultiVec<ScalarType2>> ivec3_2 = Teuchos::rcp( new Belos::KokkosMultiVec<ScalarType2>(2003, 2) ); |
| 159 |
|
| 160 |
isPassed = Belos::TestKokkosOperatorTraits<ScalarType2,KMV2,KOP2>(myOutputMgr2,ivec3_2,myOp2); |
| 161 |
success = isPassed && success; |
| 162 |
if (isPassed) { |
| 163 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter PASSED TestOperatorTraits() single\n"); |
| 164 |
} |
| 165 |
else { |
| 166 |
myOutputMgr->print(Belos::Warnings,"*** KokkosAdapter FAILED TestOperatorTraits() single ***\n\n"); |
| 167 |
} |
| 168 |
//***************************************************************************************************************************** |
| 169 |
//***************************************************************************************************************************** |
| 170 |
|
| 171 |
if (!success) { |
| 172 |
myOutputMgr->print(Belos::Warnings,"End Result: TEST FAILED\n"); |
| 173 |
} else { |
| 174 |
myOutputMgr->print(Belos::Warnings,"End Result: TEST PASSED\n"); |
| 175 |
} |
| 176 |
}//end try block |
| 177 |
|
| 178 |
|
| 179 |
TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose,std::cerr,success); |
| 180 |
} |
| 181 |
Kokkos::finalize(); |
| 182 |
#ifdef HAVE_MPI |
| 183 |
MPI_Finalize(); |
| 184 |
#endif |
| 185 |
return success ? EXIT_SUCCESS : EXIT_FAILURE; |
| 186 |
} |
| 187 |
|
| 188 |
template <class ScalarType> |
| 189 |
bool TestKokkosMultiVecOneScalar(const Teuchos::RCP<OutputManager<ScalarType> > & outputMgr){ |
| 190 |
int dim = 10; |
| 191 |
int blockSize = 5; |
| 192 |
std::vector<ScalarType> norms(blockSize); |
| 193 |
|
| 194 |
/// Test KokkosMultiVec constructors: |
| 195 |
// Test constructor #1: |
| 196 |
Belos::KokkosMultiVec<ScalarType> myVec1("myLabel", dim, blockSize); |
| 197 |
if ( myVec1.GetNumberVecs() != blockSize ) { |
| 198 |
outputMgr->stream(Warnings) |
| 199 |
<< "*** ERROR *** KokkosMultiVec constructor 1 returned wrong value " |
| 200 |
<< "for GetNumberVecs()." << endl; |
| 201 |
return false; |
| 202 |
} |
| 203 |
if ( myVec1.GetGlobalLength() != dim ) { |
| 204 |
outputMgr->stream(Warnings) |
| 205 |
<< "*** ERROR *** KokkosMultiVec constructor 1 returned wrong value " |
| 206 |
<< "for GetGlobalLength()." << endl; |
| 207 |
return false; |
| 208 |
} |
| 209 |
myVec1.MvNorm(norms); |
| 210 |
for(int i = 0; i < blockSize; i++){ |
| 211 |
if( norms[i] != 0 ){ |
| 212 |
outputMgr->stream(Warnings) |
| 213 |
<< "*** ERROR *** KokkosMultiVec constructor 1 returned wrong nrm2 value. " |
| 214 |
<< "Vector was not initialized to zeros." << endl; |
| 215 |
return false; |
| 216 |
} |
| 217 |
} |
| 218 |
// Test constructor #2: |
| 219 |
Belos::KokkosMultiVec<ScalarType> myVec2(dim, blockSize); |
| 220 |
if ( myVec2.GetNumberVecs() != blockSize ) { |
| 221 |
outputMgr->stream(Warnings) |
| 222 |
<< "*** ERROR *** KokkosMultiVec constructor 2 returned wrong value " |
| 223 |
<< "for GetNumberVecs()." << endl; |
| 224 |
return false; |
| 225 |
} |
| 226 |
if ( myVec2.GetGlobalLength() != dim ) { |
| 227 |
outputMgr->stream(Warnings) |
| 228 |
<< "*** ERROR *** KokkosMultiVec constructor 2 returned wrong value " |
| 229 |
<< "for GetGlobalLength()." << endl; |
| 230 |
return false; |
| 231 |
} |
| 232 |
myVec2.MvNorm(norms); |
| 233 |
for(int i = 0; i < blockSize; i++){ |
| 234 |
if( norms[i] != 0 ){ |
| 235 |
outputMgr->stream(Warnings) |
| 236 |
<< "*** ERROR *** KokkosMultiVec constructor 2 returned wrong nrm2 value. " |
| 237 |
<< "Vector was not initialized to zeros." << endl; |
| 238 |
return false; |
| 239 |
} |
| 240 |
} |
| 241 |
// Test constructor #3: |
| 242 |
Belos::KokkosMultiVec<ScalarType> myVec3(2*dim); |
| 243 |
if ( myVec3.GetNumberVecs() != 1 ) { |
| 244 |
outputMgr->stream(Warnings) |
| 245 |
<< "*** ERROR *** KokkosMultiVec constructor 3 returned wrong value " |
| 246 |
<< "for GetNumberVecs()." << endl; |
| 247 |
return false; |
| 248 |
} |
| 249 |
if ( myVec3.GetGlobalLength() != 2*dim ) { |
| 250 |
outputMgr->stream(Warnings) |
| 251 |
<< "*** ERROR *** KokkosMultiVec constructor 3 returned wrong value " |
| 252 |
<< "for GetGlobalLength()." << endl; |
| 253 |
return false; |
| 254 |
} |
| 255 |
myVec3.MvNorm(norms); |
| 256 |
if( norms[0] != 0 ){ |
| 257 |
outputMgr->stream(Warnings) |
| 258 |
<< "*** ERROR *** KokkosMultiVec constructor 3 returned wrong nrm2 value. " |
| 259 |
<< "Vector was not initialized to zeros." << endl; |
| 260 |
return false; |
| 261 |
} |
| 262 |
// Test copy constructor (should deep copy). |
| 263 |
Belos::KokkosMultiVec<ScalarType> myVecCopy(myVec3); |
| 264 |
if ( myVecCopy.GetNumberVecs() != 1 ) { |
| 265 |
outputMgr->stream(Warnings) |
| 266 |
<< "*** ERROR *** KokkosMultiVec copy constructor returned wrong value " |
| 267 |
<< "for GetNumberVecs()." << endl; |
| 268 |
return false; |
| 269 |
} |
| 270 |
if ( myVecCopy.GetGlobalLength() != 2*dim ) { |
| 271 |
outputMgr->stream(Warnings) |
| 272 |
<< "*** ERROR *** KokkosMultiVec copy constructor returned wrong value " |
| 273 |
<< "for GetGlobalLength()." << endl; |
| 274 |
return false; |
| 275 |
} |
| 276 |
myVecCopy.MvRandom(); |
| 277 |
myVecCopy.MvNorm(norms); |
| 278 |
if( norms[0] == 0 ){ |
| 279 |
outputMgr->stream(Warnings) |
| 280 |
<< "*** ERROR *** KokkosMultiVec MvRandom did not fill with random values. " << endl; |
| 281 |
return false; |
| 282 |
} |
| 283 |
myVec3.MvNorm(norms); |
| 284 |
if( norms[0] != 0 ){ |
| 285 |
outputMgr->stream(Warnings) |
| 286 |
<< "*** ERROR *** KokkosMultiVec copy constructor did not deep copy. " << endl; |
| 287 |
return false; |
| 288 |
} |
| 289 |
// Test assignment operator (should also deep copy). |
| 290 |
myVecCopy = myVec2; |
| 291 |
if ( myVecCopy.GetNumberVecs() != blockSize ) { |
| 292 |
outputMgr->stream(Warnings) |
| 293 |
<< "*** ERROR *** KokkosMultiVec assignment = returned wrong value " |
| 294 |
<< "for GetNumberVecs()." << endl; |
| 295 |
return false; |
| 296 |
} |
| 297 |
if ( myVecCopy.GetGlobalLength() != dim ) { |
| 298 |
outputMgr->stream(Warnings) |
| 299 |
<< "*** ERROR *** KokkosMultiVec assignment = returned wrong value " |
| 300 |
<< "for GetGlobalLength()." << endl; |
| 301 |
return false; |
| 302 |
} |
| 303 |
myVec2.MvInit(3.0); |
| 304 |
myVecCopy.MvNorm(norms); |
| 305 |
for(int i = 0; i < blockSize; i++){ |
| 306 |
if( norms[i] != 0 ){ |
| 307 |
outputMgr->stream(Warnings) |
| 308 |
<< "*** ERROR *** KokkosMultiVec assignment = returned wrong nrm2 value. " |
| 309 |
<< "Vector was not deep copied." << endl; |
| 310 |
return false; |
| 311 |
} |
| 312 |
} |
| 313 |
// Test view to multivec: |
| 314 |
int numCols2 = 4; |
| 315 |
int numRows2 = 60; |
| 316 |
Kokkos::View<ScalarType**, Kokkos::LayoutLeft> myView("View2MV", numRows2, numCols2); |
| 317 |
typename Kokkos::View<ScalarType**>::HostMirror myView_h("View2MV_host", numRows2, numCols2); |
| 318 |
Kokkos::deep_copy(myView, 42); |
| 319 |
Belos::KokkosMultiVec<ScalarType> myVec4( myView ); |
| 320 |
if ( myVec4.GetNumberVecs() != (int)myView.extent(1) ) { |
| 321 |
outputMgr->stream(Warnings) |
| 322 |
<< "*** ERROR *** KokkosMultiVec view to multivec returned wrong value " |
| 323 |
<< "for GetNumberVecs()." << endl; |
| 324 |
return false; |
| 325 |
} |
| 326 |
if ( myVec4.GetGlobalLength() != (int)myView.extent(0) ) { |
| 327 |
outputMgr->stream(Warnings) |
| 328 |
<< "*** ERROR *** KokkosMultiVec view to multivec returned wrong value " |
| 329 |
<< "for GetGlobalLength()." << endl; |
| 330 |
return false; |
| 331 |
} |
| 332 |
Kokkos::deep_copy(myView, 55); |
| 333 |
Kokkos::deep_copy(myView_h, myVec4.GetInternalViewConst()); |
| 334 |
if ( myView_h(5,1) != 42 ) { |
| 335 |
outputMgr->stream(Warnings) |
| 336 |
<< "*** ERROR *** KokkosMultivec view to multivec did not make a deep copy!" << endl; |
| 337 |
return false; |
| 338 |
} |
| 339 |
// Tesst view to multivec with shallow copy: |
| 340 |
Kokkos::deep_copy(myView, 100); |
| 341 |
Belos::KokkosMultiVec<ScalarType> myVec5( myView, false ); |
| 342 |
if ( myVec5.GetNumberVecs() != (int)myView.extent(1) ) { |
| 343 |
outputMgr->stream(Warnings) |
| 344 |
<< "*** ERROR *** KokkosMultiVec view to multivec shallow returned wrong value " |
| 345 |
<< "for GetNumberVecs()." << endl; |
| 346 |
return false; |
| 347 |
} |
| 348 |
if ( myVec5.GetGlobalLength() != (int)myView.extent(0) ) { |
| 349 |
outputMgr->stream(Warnings) |
| 350 |
<< "*** ERROR *** KokkosMultiVec view to multivec shallow returned wrong value " |
| 351 |
<< "for GetGlobalLength()." << endl; |
| 352 |
return false; |
| 353 |
} |
| 354 |
Kokkos::deep_copy(myView, 500); |
| 355 |
Kokkos::deep_copy(myView_h, myVec5.GetInternalViewConst()); |
| 356 |
if ( myView_h(5,1) != 500 ) { |
| 357 |
outputMgr->stream(Warnings) |
| 358 |
<< "*** ERROR *** KokkosMultivec view to multivec shallow made a deep copy!" << endl; |
| 359 |
return false; |
| 360 |
} |
| 361 |
// Test GetInternalViewNonConst: |
| 362 |
auto myView2 = myVec5.GetInternalViewNonConst(); |
| 363 |
Kokkos::deep_copy(myView2, 0); |
| 364 |
std::vector<ScalarType> norms2(4); |
| 365 |
myVec5.MvNorm(norms2); |
| 366 |
for(int i = 0; i < (int)myView2.extent(1); i++){ |
| 367 |
if( norms[i] != 0 ){ |
| 368 |
outputMgr->stream(Warnings) |
| 369 |
<< "*** ERROR *** KokkosMultiVec GetInternalViewNonConst returned wrong nrm2 value. " |
| 370 |
<< "Vector was not editable." << endl; |
| 371 |
return false; |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
return true; |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
template <class ScalarType1, class ScalarType2> |
| 380 |
bool TestKokkosMultiVecTwoScalar(const Teuchos::RCP<OutputManager<ScalarType1> > & outputMgr){ |
| 381 |
// Test view to multivec ST1 to ST2: |
| 382 |
int numCols = 4; |
| 383 |
int numRows = 60; |
| 384 |
Kokkos::View<ScalarType1**, Kokkos::LayoutLeft, Kokkos::DefaultExecutionSpace> myViewST1("View2MV1", numRows, numCols); |
| 385 |
typename Kokkos::View<ScalarType2**>::HostMirror myViewST2_h("View2MV1_host", numRows, numCols); |
| 386 |
Kokkos::deep_copy(myViewST1, 42); |
| 387 |
Belos::KokkosMultiVec<ScalarType2> myVecST2A( myViewST1 ); |
| 388 |
if ( myVecST2A.GetNumberVecs() != (int)myViewST1.extent(1) ) { |
| 389 |
outputMgr->stream(Warnings) |
| 390 |
<< "*** ERROR *** KokkosMultiVec view to multivec 2 scalar returned wrong value " |
| 391 |
<< "for GetNumberVecs()." << endl; |
| 392 |
return false; |
| 393 |
} |
| 394 |
if ( myVecST2A.GetGlobalLength() != (int)myViewST1.extent(0) ) { |
| 395 |
outputMgr->stream(Warnings) |
| 396 |
<< "*** ERROR *** KokkosMultiVec view to multivec 2 scalar returned wrong value " |
| 397 |
<< "for GetGlobalLength()." << endl; |
| 398 |
return false; |
| 399 |
} |
| 400 |
Kokkos::deep_copy(myViewST1, 55); |
| 401 |
std::cout << "At line 424. " << std::endl; |
| 402 |
Kokkos::deep_copy(myViewST2_h, myVecST2A.GetInternalViewConst()); |
| 403 |
if ( myViewST2_h(5,1) != 42 ) { |
| 404 |
outputMgr->stream(Warnings) |
| 405 |
<< "*** ERROR *** KokkosMultivec view to multivec 2 scalar did not make a deep copy!" << endl; |
| 406 |
return false; |
| 407 |
} |
| 408 |
// Test view to multivec ST2 to ST1: |
| 409 |
Kokkos::View<ScalarType2**, Kokkos::LayoutLeft, Kokkos::DefaultExecutionSpace> myViewST2("View2MV2", numRows, numCols); |
| 410 |
typename Kokkos::View<ScalarType1**>::HostMirror myViewST1_h("View2MV2_host", numRows, numCols); |
| 411 |
Kokkos::deep_copy(myViewST2, 56); |
| 412 |
Belos::KokkosMultiVec<ScalarType1> myVecST1A( myViewST2 ); |
| 413 |
if ( myVecST1A.GetNumberVecs() != (int)myViewST2.extent(1) ) { |
| 414 |
outputMgr->stream(Warnings) |
| 415 |
<< "*** ERROR *** KokkosMultiVec view to multivec 2 scalar returned wrong value " |
| 416 |
<< "for GetNumberVecs()." << endl; |
| 417 |
return false; |
| 418 |
} |
| 419 |
if ( myVecST1A.GetGlobalLength() != (int)myViewST2.extent(0) ) { |
| 420 |
outputMgr->stream(Warnings) |
| 421 |
<< "*** ERROR *** KokkosMultiVec view to multivec 2 scalar returned wrong value " |
| 422 |
<< "for GetGlobalLength()." << endl; |
| 423 |
return false; |
| 424 |
} |
| 425 |
Kokkos::deep_copy(myViewST2, 22); |
| 426 |
std::cout << "At line 449. " << std::endl; |
| 427 |
Kokkos::deep_copy(myViewST1_h, myVecST1A.GetInternalViewConst()); |
| 428 |
if ( myViewST1_h(5,1) != 56 ) { |
| 429 |
outputMgr->stream(Warnings) |
| 430 |
<< "*** ERROR *** KokkosMultivec view to multivec 2 scalar did not make a deep copy!" << endl; |
| 431 |
return false; |
| 432 |
} |
| 433 |
//Test multivec copy constructor ST1 to ST2: |
| 434 |
Belos::KokkosMultiVec<ScalarType2> myVecST2B( myVecST1A ); |
| 435 |
if ( myVecST1A.GetNumberVecs() != myVecST2B.GetNumberVecs() ) { |
| 436 |
outputMgr->stream(Warnings) |
| 437 |
<< "*** ERROR *** KokkosMultiVec templated copy constructor returned wrong value " |
| 438 |
<< "for GetNumberVecs()." << endl; |
| 439 |
return false; |
| 440 |
} |
| 441 |
if ( myVecST1A.GetGlobalLength() != myVecST2B.GetGlobalLength() ) { |
| 442 |
outputMgr->stream(Warnings) |
| 443 |
<< "*** ERROR *** KokkosMultiVec templated copy constructor returned wrong value " |
| 444 |
<< "for GetGlobalLength()." << endl; |
| 445 |
return false; |
| 446 |
} |
| 447 |
myVecST1A.MvInit(3.0); |
| 448 |
std::cout << "At line 471. " << std::endl; |
| 449 |
Kokkos::deep_copy(myViewST2_h, myVecST2B.GetInternalViewConst()); |
| 450 |
if ( myViewST2_h(5,1) != 56 ) { |
| 451 |
outputMgr->stream(Warnings) |
| 452 |
<< "*** ERROR *** KokkosMultivec templated copy constructor did not make a deep copy!" << endl; |
| 453 |
return false; |
| 454 |
} |
| 455 |
//Test multivec copy constructor ST2 to ST1: |
| 456 |
Belos::KokkosMultiVec<ScalarType1> myVecST1B( myVecST2A ); |
| 457 |
if ( myVecST1B.GetNumberVecs() != myVecST2A.GetNumberVecs() ) { |
| 458 |
outputMgr->stream(Warnings) |
| 459 |
<< "*** ERROR *** KokkosMultiVec templated copy constructor returned wrong value " |
| 460 |
<< "for GetNumberVecs()." << endl; |
| 461 |
return false; |
| 462 |
} |
| 463 |
if ( myVecST1B.GetGlobalLength() != myVecST2A.GetGlobalLength() ) { |
| 464 |
outputMgr->stream(Warnings) |
| 465 |
<< "*** ERROR *** KokkosMultiVec templated copy constructor returned wrong value " |
| 466 |
<< "for GetGlobalLength()." << endl; |
| 467 |
return false; |
| 468 |
} |
| 469 |
myVecST2A.MvInit(3.0); |
| 470 |
Kokkos::deep_copy(myViewST1_h, myVecST1B.GetInternalViewConst()); |
| 471 |
if ( myViewST1_h(5,1) != 42 ) { |
| 472 |
outputMgr->stream(Warnings) |
| 473 |
<< "*** ERROR *** KokkosMultivec templated copy constructor did not make a deep copy!" << endl; |
| 474 |
return false; |
| 475 |
} |
| 476 |
//Test assignment operator ST1 to ST2: |
| 477 |
Belos::KokkosMultiVec<ScalarType2> myVecST2C = myVecST1A; |
| 478 |
if ( myVecST1A.GetNumberVecs() != myVecST2C.GetNumberVecs() ) { |
| 479 |
outputMgr->stream(Warnings) |
| 480 |
<< "*** ERROR *** KokkosMultiVec templated assignment operator returned wrong value " |
| 481 |
<< "for GetNumberVecs()." << endl; |
| 482 |
return false; |
| 483 |
} |
| 484 |
if ( myVecST1A.GetGlobalLength() != myVecST2C.GetGlobalLength() ) { |
| 485 |
outputMgr->stream(Warnings) |
| 486 |
<< "*** ERROR *** KokkosMultiVec templated copy constructor returned wrong value " |
| 487 |
<< "*** ERROR *** KokkosMultiVec templated assignment operator returned wrong value " |
| 488 |
<< "for GetGlobalLength()." << endl; |
| 489 |
return false; |
| 490 |
} |
| 491 |
myVecST1A.MvInit(1.0); |
| 492 |
std::cout << "At line 515. " << std::endl; |
| 493 |
Kokkos::deep_copy(myViewST2_h, myVecST2C.GetInternalViewConst()); |
| 494 |
if ( myViewST2_h(5,1) != 3 ) { |
| 495 |
outputMgr->stream(Warnings) |
| 496 |
<< "*** ERROR *** KokkosMultivec templated assign op did not make a deep copy!" << endl; |
| 497 |
return false; |
| 498 |
} |
| 499 |
//Test assignement operator ST2 to ST1: |
| 500 |
Belos::KokkosMultiVec<ScalarType1> myVecST1C = myVecST2A; |
| 501 |
if ( myVecST1C.GetNumberVecs() != myVecST2A.GetNumberVecs() ) { |
| 502 |
outputMgr->stream(Warnings) |
| 503 |
<< "*** ERROR *** KokkosMultiVec templated assignment operator returned wrong value " |
| 504 |
<< "for GetNumberVecs()." << endl; |
| 505 |
return false; |
| 506 |
} |
| 507 |
if ( myVecST1C.GetGlobalLength() != myVecST2A.GetGlobalLength() ) { |
| 508 |
outputMgr->stream(Warnings) |
| 509 |
<< "*** ERROR *** KokkosMultiVec templated assignment operator returned wrong value " |
| 510 |
<< "for GetGlobalLength()." << endl; |
| 511 |
return false; |
| 512 |
} |
| 513 |
myVecST2A.MvInit(2.0); |
| 514 |
Kokkos::deep_copy(myViewST1_h, myVecST1C.GetInternalViewConst()); |
| 515 |
if ( myViewST1_h(5,1) != 3 ) { |
| 516 |
outputMgr->stream(Warnings) |
| 517 |
<< "*** ERROR *** KokkosMultivec templated assign op did not make a deep copy!" << endl; |
| 518 |
return false; |
| 519 |
} |
| 520 |
|
| 521 |
return true; |
| 522 |
} |