TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( SpmdLocalDataAccess,
  getNonconstLocalSubVectorView_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<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::SubVectorView<Scalar> lsv = 
    getNonconstLocalSubVectorView<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);
  }
}
Пример #2
0
void VectorDefaultBase<Scalar>::acquireNonconstDetachedMultiVectorViewImpl(
  const Range1D &rowRng,
  const Range1D &colRng,
  RTOpPack::SubMultiVectorView<Scalar> *sub_mv
  )
{
#ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
  THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
  *dbgout << "\nThyra::VectorDefaultBase<"
          <<Teuchos::ScalarTraits<Scalar>::name()
          <<">::acquireNonconstDetachedMultiVectorViewImpl() called!\n";
#endif
#ifdef TEUCHOS_DEBUG
  TEUCHOS_TEST_FOR_EXCEPT(sub_mv==NULL);
#endif
  validateColRng(colRng);
  RTOpPack::SubVectorView<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));
      }
    }
  }

}