TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( SpmdLocalDataAccess, getLocalSubMultiVectorView_procRankLocalDim, Scalar ) { typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag; const RCP<const DefaultSpmdVectorSpace<Scalar> > vs = createProcRankLocalDimVS<Scalar>(); const RCP<const Teuchos::Comm<Ordinal> > comm = vs->getComm(); const int procRank = comm->getRank(); PRINT_VAR(procRank); const int numProcs = comm->getSize(); PRINT_VAR(numProcs); const RCP<MultiVectorBase<Scalar> > mv = createMembers<Scalar>(vs, g_numCols); const Scalar val = as<Scalar>(1.5); PRINT_VAR(val); assign<Scalar>(mv.ptr(), val); const ScalarMag tol = 100.0*ScalarTraits<Scalar>::eps(); TEST_EQUALITY_CONST(mv->domain()->dim(), g_numCols); for (int j = 0; j < g_numCols; ++j) { TEST_FLOATING_EQUALITY(sum<Scalar>(*mv->col(0)), as<Scalar>(vs->dim())*val, tol); } out << "*** Test that we get the view correctly ...\n"; RTOpPack::ConstSubMultiVectorView<Scalar> lsmv = getLocalSubMultiVectorView<Scalar>(mv); TEST_EQUALITY(lsmv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2)); TEST_EQUALITY(lsmv.subDim(), procRank+1); TEST_EQUALITY(lsmv.leadingDim(), lsmv.subDim()); TEST_EQUALITY_CONST(lsmv.colOffset(), 0); TEST_EQUALITY(lsmv.numSubCols(), g_numCols); for (int i = 0; i < lsmv.subDim(); ++i) { for (int j = 0; j < lsmv.numSubCols(); ++j) { TEST_EQUALITY(lsmv(i,j), val); } } }
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( SpmdLocalDataAccess, getLocalSubMultiVectorView_empty_p0, Scalar ) { typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag; const RCP<const DefaultSpmdVectorSpace<Scalar> > vs = createZeroEleProcVS<Scalar>(g_localDim); const RCP<const Teuchos::Comm<Ordinal> > comm = vs->getComm(); const int procRank = comm->getRank(); PRINT_VAR(procRank); const int numProcs = comm->getSize(); PRINT_VAR(numProcs); const RCP<MultiVectorBase<Scalar> > mv = createMembers<Scalar>(vs, g_numCols); const Scalar val = as<Scalar>(1.5); PRINT_VAR(val); assign<Scalar>(mv.ptr(), val); out << "*** Test that we get the view correctly including an empty view on p0 ...\n"; RTOpPack::ConstSubMultiVectorView<Scalar> lsmv = getLocalSubMultiVectorView<Scalar>(mv); if (procRank == 0) { TEST_EQUALITY_CONST(lsmv.globalOffset(), 0); TEST_EQUALITY_CONST(lsmv.subDim(), 0); TEST_EQUALITY_CONST(lsmv.values(), null); } else { TEST_EQUALITY(lsmv.globalOffset(), as<Ordinal>((procRank-1)*g_localDim)); TEST_EQUALITY(lsmv.subDim(), g_localDim); } TEST_EQUALITY(lsmv.leadingDim(), lsmv.subDim()); TEST_EQUALITY_CONST(lsmv.colOffset(), 0); TEST_EQUALITY(lsmv.numSubCols(), g_numCols); for (int i = 0; i < lsmv.subDim(); ++i) { for (int j = 0; j < lsmv.numSubCols(); ++j) { TEST_EQUALITY(lsmv(i,j), val); } } }
Teuchos::RCP<const MultiVectorBase<Scalar> > VectorSpaceDefaultBase<Scalar>::createMembersView( const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv ) const { #ifdef TEUCHOS_DEBUG TEST_FOR_EXCEPT( raw_mv.subDim() != this->dim() ); #endif // Create a multi-vector RCP< MultiVectorBase<Scalar> > mv = this->createMembers(raw_mv.numSubCols()); // Copy values in raw_mv into multi-vector RTOpPack::SubMultiVectorView<Scalar> smv; mv->acquireDetachedView(Range1D(),Range1D(),&smv); RTOpPack::assign_entries<Scalar>( Ptr<const RTOpPack::SubMultiVectorView<Scalar> >(Teuchos::outArg(smv)), raw_mv ); mv->commitDetachedView(&smv); return mv; }
RCP<const MultiVectorBase<Scalar> > DefaultSpmdVectorSpace<Scalar>::createMembersView( const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv ) const { #ifdef TEUCHOS_DEBUG TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_mv.subDim() ); #endif return Teuchos::rcp( new DefaultSpmdMultiVector<Scalar>( weakSelfPtr_.create_strong(), Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >( this->smallVecSpcFcty()->createVecSpc(raw_mv.numSubCols()),true), Teuchos::arcp( const_cast<Scalar*>(raw_mv.values().get()), 0,raw_mv.leadingDim()*raw_mv.numSubCols(),false), raw_mv.leadingDim() ) ); }
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( SpmdLocalDataAccess, getNonconstLocalSubMultiVectorView_procRankLocalDim, Scalar ) { typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag; const RCP<const DefaultSpmdVectorSpace<Scalar> > vs = createProcRankLocalDimVS<Scalar>(); const RCP<const Teuchos::Comm<Ordinal> > comm = vs->getComm(); const int procRank = comm->getRank(); PRINT_VAR(procRank); const int numProcs = comm->getSize(); PRINT_VAR(numProcs); out << "*** A) Test getting nonconst MV view directly from SPMD MultiVector ...\n"; { const RCP<MultiVectorBase<Scalar> > mv = createMembers<Scalar>(vs, g_numCols); const Scalar val = as<Scalar>(1.5); PRINT_VAR(val); assign<Scalar>(mv.ptr(), val); { out << "*** A.1) Get and change the nonconst view ...\n"; RTOpPack::SubMultiVectorView<Scalar> lsmv = getNonconstLocalSubMultiVectorView<Scalar>(mv); TEST_EQUALITY(lsmv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2)); TEST_EQUALITY(lsmv.subDim(), procRank+1); TEST_EQUALITY(lsmv.leadingDim(), lsmv.subDim()); TEST_EQUALITY_CONST(lsmv.colOffset(), 0); TEST_EQUALITY(lsmv.numSubCols(), g_numCols); for (int i = 0; i < lsmv.subDim(); ++i) { for (int j = 0; j < lsmv.numSubCols(); ++j) { lsmv(i,j) = lsmv.globalOffset() + i + 0.1 * j; } } } { out << "*** A.2) Get the same values when we grab const view ...\n"; RTOpPack::ConstSubMultiVectorView<Scalar> lsmv = getLocalSubMultiVectorView<Scalar>(mv); for (int i = 0; i < lsmv.subDim(); ++i) { for (int j = 0; j < lsmv.numSubCols(); ++j) { TEST_EQUALITY(lsmv(i,j), as<Scalar>(lsmv.globalOffset() + i + 0.1 * j)); } } } } out << "*** B) Test getting nonconst MV view indirectly from one-block" << " Product MultiVector ...\n"; { const RCP<const VectorSpaceBase<Scalar> > pvs = productVectorSpace<Scalar>(tuple<RCP<const VectorSpaceBase<Scalar> > >(vs)()); const RCP<MultiVectorBase<Scalar> > pmv = createMembers<Scalar>(pvs, g_numCols); const Scalar val = as<Scalar>(1.8); PRINT_VAR(val); assign<Scalar>(pmv.ptr(), val); { out << "*** B.1) Get and change the nonconst view ...\n"; RTOpPack::SubMultiVectorView<Scalar> lsmv = getNonconstLocalSubMultiVectorView<Scalar>(pmv); TEST_EQUALITY(lsmv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2)); TEST_EQUALITY(lsmv.subDim(), procRank+1); TEST_EQUALITY(lsmv.leadingDim(), lsmv.subDim()); TEST_EQUALITY_CONST(lsmv.colOffset(), 0); TEST_EQUALITY(lsmv.numSubCols(), g_numCols); for (int i = 0; i < lsmv.subDim(); ++i) { for (int j = 0; j < lsmv.numSubCols(); ++j) { lsmv(i,j) = lsmv.globalOffset() + i + 0.1 * j; } } } { out << "*** B.2) Get the same values when we grab const view ...\n"; RTOpPack::ConstSubMultiVectorView<Scalar> lsmv = getLocalSubMultiVectorView<Scalar>(pmv); TEST_EQUALITY(lsmv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2)); TEST_EQUALITY(lsmv.subDim(), procRank+1); TEST_EQUALITY(lsmv.leadingDim(), lsmv.subDim()); TEST_EQUALITY_CONST(lsmv.colOffset(), 0); TEST_EQUALITY(lsmv.numSubCols(), g_numCols); for (int i = 0; i < lsmv.subDim(); ++i) { for (int j = 0; j < lsmv.numSubCols(); ++j) { TEST_EQUALITY(lsmv(i,j), as<Scalar>(lsmv.globalOffset() + i + 0.1 * j)); } } } } out << "*** C) Test getting nonconst MV view directly from SPMD Vector ...\n"; if (1) { const RCP<VectorBase<Scalar> > v = createMember<Scalar>(vs); const Scalar val = as<Scalar>(2.1); PRINT_VAR(val); assign<Scalar>(v.ptr(), val); { out << "*** C.1) Get and change the nonconst MV view ...\n"; RTOpPack::SubMultiVectorView<Scalar> lsmv = getNonconstLocalSubMultiVectorView<Scalar>(v); TEST_EQUALITY(lsmv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2)); TEST_EQUALITY(lsmv.subDim(), procRank+1); TEST_EQUALITY(lsmv.leadingDim(), lsmv.subDim()); TEST_EQUALITY_CONST(lsmv.colOffset(), 0); TEST_EQUALITY_CONST(lsmv.numSubCols(), 1); for (int i = 0; i < lsmv.subDim(); ++i) { lsmv(i,0) = lsmv.globalOffset() + i; } } { out << "*** C.2) Get the same values when we grab const MV view ...\n"; RTOpPack::ConstSubMultiVectorView<Scalar> lsmv = getLocalSubMultiVectorView<Scalar>(v); TEST_EQUALITY(lsmv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2)); TEST_EQUALITY(lsmv.subDim(), procRank+1); TEST_EQUALITY(lsmv.leadingDim(), lsmv.subDim()); TEST_EQUALITY_CONST(lsmv.colOffset(), 0); TEST_EQUALITY_CONST(lsmv.numSubCols(), 1); for (int i = 0; i < lsmv.subDim(); ++i) { TEST_EQUALITY(lsmv(i,0), as<Scalar>(lsmv.globalOffset() + i)); } } } out << "*** D) Test getting nonconst MV view indirectly from one-block" << " Product MultiVector ...\n"; { const RCP<const VectorSpaceBase<Scalar> > pvs = productVectorSpace<Scalar>(tuple<RCP<const VectorSpaceBase<Scalar> > >(vs)()); const RCP<VectorBase<Scalar> > pv = createMember<Scalar>(pvs); const Scalar val = as<Scalar>(1.8); PRINT_VAR(val); assign<Scalar>(pv.ptr(), val); { out << "*** D.1) Get and change the nonconst view ...\n"; RTOpPack::SubMultiVectorView<Scalar> lsmv = getNonconstLocalSubMultiVectorView<Scalar>(pv); TEST_EQUALITY(lsmv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2)); TEST_EQUALITY(lsmv.subDim(), procRank+1); TEST_EQUALITY(lsmv.leadingDim(), lsmv.subDim()); TEST_EQUALITY_CONST(lsmv.colOffset(), 0); TEST_EQUALITY(lsmv.numSubCols(), 1); for (int i = 0; i < lsmv.subDim(); ++i) { lsmv(i,0) = lsmv.globalOffset() + i; } } { out << "*** D.2) Get the same values when we grab const view ...\n"; RTOpPack::ConstSubMultiVectorView<Scalar> lsmv = getLocalSubMultiVectorView<Scalar>(pv); TEST_EQUALITY(lsmv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2)); TEST_EQUALITY(lsmv.subDim(), procRank+1); TEST_EQUALITY(lsmv.leadingDim(), lsmv.subDim()); TEST_EQUALITY_CONST(lsmv.colOffset(), 0); TEST_EQUALITY(lsmv.numSubCols(), 1); for (int i = 0; i < lsmv.subDim(); ++i) { TEST_EQUALITY(lsmv(i,0), as<Scalar>(lsmv.globalOffset() + i)); } } } }