TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DefaultSpmdVectorSpace_Parallel, emptyProcGetFullSubVector,
  Scalar )
{
  const Ordinal localSubDim = g_localDim;
  const RCP<const DefaultSpmdVectorSpace<Scalar> > vs =
    createZeroEleProcVS<Scalar>(localSubDim);
  const RCP<VectorBase<Scalar> > v = createMember<Scalar>(vs);
  ECHO(assign(v.ptr(), as<Scalar>(1.5)));
  RTOpPack::ConstSubVectorView<Scalar> subVec;
  v->acquireDetachedView(Teuchos::Range1D(), &subVec);
  TEST_EQUALITY(subVec.subDim(),
    as<Ordinal>(localSubDim*(vs->getComm()->getSize()-1)));
}
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( SpmdLocalDataAccess,
  getLocalSubVectorView_empty_p0, Scalar )
{
  typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag;
  const RCP<const DefaultSpmdVectorSpace<Scalar> > vs =
    createZeroEleProcVS<Scalar>(g_localDim);
  TEST_ASSERT(!vs->isLocallyReplicated());
  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<VectorBase<Scalar> > v = createMember<Scalar>(vs);
  const Scalar val = as<Scalar>(1.5);
  PRINT_VAR(val);
  assign<Scalar>(v.ptr(), val);
  out << "*** Test that we get the view correctly including an empty view on p0 ...\n";
  RTOpPack::ConstSubVectorView<Scalar> lsv = 
    getLocalSubVectorView<Scalar>(v);
  if (procRank == 0) {
    TEST_EQUALITY_CONST(lsv.globalOffset(), 0);
    TEST_EQUALITY_CONST(lsv.subDim(), 0);
    TEST_EQUALITY_CONST(lsv.values(), null);
  }
  else {
    TEST_EQUALITY(lsv.globalOffset(), as<Ordinal>((procRank-1)*g_localDim));
    TEST_EQUALITY(lsv.subDim(), g_localDim);
  }
  TEST_EQUALITY_CONST(lsv.stride(), 1);
  for (int k = 0; k < lsv.subDim(); ++k) {
    TEST_EQUALITY(lsv[k], val);
  }
}
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( SpmdLocalDataAccess, 
  getLocalSubVectorView_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);
  TEST_EQUALITY(vs->isLocallyReplicated(), numProcs==1);

  out << "*** A) Get view directly through an SPMD Vector object ...\n";
  {
    const RCP<VectorBase<Scalar> > v = createMember<Scalar>(vs);
    const Scalar val = as<Scalar>(1.5);
    PRINT_VAR(val);
    assign<Scalar>(v.ptr(), val);
    const ScalarMag tol = 100.0*ScalarTraits<Scalar>::eps();
    TEST_FLOATING_EQUALITY(sum<Scalar>(*v), as<Scalar>(vs->dim())*val, tol);
    RTOpPack::ConstSubVectorView<Scalar> lsv = 
      getLocalSubVectorView<Scalar>(v);
    TEST_EQUALITY(lsv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2));
    TEST_EQUALITY(lsv.subDim(), procRank+1);
    TEST_EQUALITY_CONST(lsv.stride(), 1);
    for (int k = 0; k < lsv.subDim(); ++k) {
      TEST_EQUALITY(lsv[k], val);
    }
  }

  out << "*** B) Get view indirectly through a product vector with one block ...\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.7);
    PRINT_VAR(val);
    assign<Scalar>(pv.ptr(), val);
    RTOpPack::ConstSubVectorView<Scalar> lsv = 
      getLocalSubVectorView<Scalar>(pv);
    TEST_EQUALITY(lsv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2));
    TEST_EQUALITY(lsv.subDim(), procRank+1);
    TEST_EQUALITY_CONST(lsv.stride(), 1);
    for (int k = 0; k < lsv.subDim(); ++k) {
      TEST_EQUALITY(lsv[k], val);
    }
  }

}
Example #4
0
RCP<const VectorBase<Scalar> >
DefaultSpmdVectorSpace<Scalar>::createMemberView(
  const RTOpPack::ConstSubVectorView<Scalar> &raw_v
  ) const
{
#ifdef TEUCHOS_DEBUG
  TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_v.subDim() );
#endif
  return Teuchos::rcp(
    new DefaultSpmdVector<Scalar>(
      weakSelfPtr_.create_strong(),
      Teuchos::arcp(const_cast<Scalar*>(raw_v.values().get()),0,raw_v.subDim(),false),
      raw_v.stride()
      )
    );
}
Teuchos::RCP<const VectorBase<Scalar> >
VectorSpaceDefaultBase<Scalar>::createMemberView( const RTOpPack::ConstSubVectorView<Scalar> &raw_v ) const
{
#ifdef TEUCHOS_DEBUG
  TEST_FOR_EXCEPT( raw_v.subDim() != this->dim() );
#endif
  // Create a vector
  RCP<VectorBase<Scalar> > v = this->createMember();
  // Copy initial values in raw_v into vector
  RTOpPack::SubVectorView<Scalar> sv;
  v->acquireDetachedView(Range1D(),&sv);
  RTOpPack::assign_entries<Scalar>(
    Teuchos::ptr_implicit_cast<const RTOpPack::SubVectorView<Scalar> >(Teuchos::outArg(sv)),
    raw_v );
  v->commitDetachedView(&sv);
  return v;
}
 void initialize(
   const Teuchos::RCP<const VectorBase<Scalar> > &v,
   const Range1D &rng, const bool forceUnitStride
   )
   {
     v_ = v;
     v_->acquireDetachedView(rng,&sv_s_);
     if( forceUnitStride && sv_s_.stride() != 1 ) {
       TEST_FOR_EXCEPT_MSG(true, "I don't think non-unit stride has ever been tested!");
       //const ArrayRCP<Scalar> values = Teuchos::arcp(sv_s_.subDim());
       //Teuchos_Index i; const Scalar *sv_v;
       //for( sv_v = sv_s_.values().get(), i=0; i < sv_s_.subDim(); ++i, sv_v += sv_s_.stride() )
       //  values[i] = *sv_v;
       //sv_.initialize(sv_s_.globalOffset(),sv_s_.subDim(),values,1);
     }
     else {
       sv_ = sv_s_;
     }
   }
Example #7
0
void VectorDefaultBase<Scalar>::acquireDetachedMultiVectorViewImpl(
  const Range1D &rowRng,
  const Range1D &colRng,
  RTOpPack::ConstSubMultiVectorView<Scalar> *sub_mv
  ) const
{
#ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
  THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
  *dbgout << "\nThyra::VectorDefaultBase<"
          <<Teuchos::ScalarTraits<Scalar>::name()
          <<">::acquireDetachedMultiVectorViewImpl() const called!\n";
#endif
#ifdef TEUCHOS_DEBUG
  TEUCHOS_TEST_FOR_EXCEPT(sub_mv==NULL);
#endif
  validateColRng(colRng);
  RTOpPack::ConstSubVectorView<Scalar> sv;
  this->acquireDetachedView(rowRng,&sv);
#ifdef TEUCHOS_DEBUG
  TEUCHOS_TEST_FOR_EXCEPT( sv.stride() != 1 ); // Can't handle non-unit stride yet but we could
#endif
  sub_mv->initialize( sv.globalOffset(), sv.subDim(), 0, 1, sv.values(), sv.subDim() );
}
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( SpmdLocalDataAccess,
  getNonconstLocalSubVectorView_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 that we get and change the nonconst view"
      << " directly through an SPMD Vector ...\n";
  {
    const RCP<VectorBase<Scalar> > v = createMember<Scalar>(vs);
    const Scalar val = as<Scalar>(1.5);
    PRINT_VAR(val);
    assign<Scalar>(v.ptr(), val);
    const ScalarMag tol = 100.0*ScalarTraits<Scalar>::eps();
    TEST_FLOATING_EQUALITY(sum<Scalar>(*v), as<Scalar>(vs->dim())*val, tol);
    {
      out << "*** A.1) Get the non-const view and set the local elements ...\n";
      RTOpPack::SubVectorView<Scalar> lsv = 
        getNonconstLocalSubVectorView<Scalar>(v);
      TEST_EQUALITY(lsv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2));
      TEST_EQUALITY(lsv.subDim(), procRank+1);
      TEST_EQUALITY_CONST(lsv.stride(), 1);
      for (int k = 0; k < lsv.subDim(); ++k) {
        lsv[k] = lsv.globalOffset() + k + 1;
      }
      const Ordinal n = vs->dim();
      TEST_FLOATING_EQUALITY(sum<Scalar>(*v), as<Scalar>((n*(n+1))/2.0), tol);
    }
    {
      out << "*** A.2) Get the const view and check the local elemetns ...\n";
      RTOpPack::ConstSubVectorView<Scalar> lsv = 
        getLocalSubVectorView<Scalar>(v);
      TEST_EQUALITY(lsv.subDim(), procRank+1);
      TEST_EQUALITY_CONST(lsv.stride(), 1);
      for (int k = 0; k < lsv.subDim(); ++k) {
        TEST_EQUALITY(lsv[k], as<Scalar>(lsv.globalOffset() + k + 1));
      }
    }
  }

  out << "*** B) Test that we get and change the nonconst view"
      << " indirectly through a product vector with one block ...\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.7);
    PRINT_VAR(val);
    assign<Scalar>(pv.ptr(), val);
    const ScalarMag tol = 100.0*ScalarTraits<Scalar>::eps();
    {
      out << "*** B.1) Get the non-const view and set the local elements ...\n";
      RTOpPack::SubVectorView<Scalar> lsv = 
        getNonconstLocalSubVectorView<Scalar>(pv);
      TEST_EQUALITY(lsv.globalOffset(), as<Ordinal>((procRank*(procRank+1))/2));
      TEST_EQUALITY(lsv.subDim(), procRank+1);
      TEST_EQUALITY_CONST(lsv.stride(), 1);
      for (int k = 0; k < lsv.subDim(); ++k) {
        lsv[k] = lsv.globalOffset() + k + 1;
      }
      const Ordinal n = vs->dim();
      TEST_FLOATING_EQUALITY(sum<Scalar>(*pv), as<Scalar>((n*(n+1))/2.0), tol);
    }
    {
      out << "*** B.2) Get the const view and check the local elemetns ...\n";
      RTOpPack::ConstSubVectorView<Scalar> lsv = 
        getLocalSubVectorView<Scalar>(pv);
      TEST_EQUALITY(lsv.subDim(), procRank+1);
      TEST_EQUALITY_CONST(lsv.stride(), 1);
      for (int k = 0; k < lsv.subDim(); ++k) {
        TEST_EQUALITY(lsv[k], as<Scalar>(lsv.globalOffset() + k + 1));
      }
    }
  }

}