TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( SpmdLocalDataAccess,
  getNonconstLocalSubMultiVectorView_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 and change the nonconst view correctly ...\n";
    RTOpPack::SubMultiVectorView<Scalar> lsmv = 
      getNonconstLocalSubMultiVectorView<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_CONST(lsmv.colOffset(), 0);
    TEST_EQUALITY(lsmv.leadingDim(), lsmv.subDim());
    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 << "*** Test that we 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));
      }
    }
  }
}
Teuchos::RCP<MultiVectorBase<Scalar> >
VectorSpaceDefaultBase<Scalar>::createMembersView(
  const RTOpPack::SubMultiVectorView<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 initial 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);
  // Setup smart pointer to multi-vector to copy view back out just before multi-vector is destroyed
  Teuchos::set_extra_data(
    Teuchos::rcp(new CopyMultiVectorViewBack<Scalar>(&*mv,raw_mv)),
    "CopyMultiVectorViewBack",
    Teuchos::outArg(mv),
    Teuchos::PRE_DESTROY
    );
  return mv;
}
Exemple #3
0
RCP<MultiVectorBase<Scalar> >
DefaultSpmdVectorSpace<Scalar>::createMembersView(
  const RTOpPack::SubMultiVectorView<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(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));
      }
    }
  }

}