Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tpetra: restore deprecated BlockMultiVector and BlockVector functions for #9082 #9084

Merged
merged 2 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/ifpack2/src/Ifpack2_Details_GaussSeidel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ namespace Details
row = useApplyRows ? applyRows[numApplyRows - 1 - i] : numApplyRows - 1 - i;
for(LO v = 0; v < numVecs; v++)
{
auto bRow = b.getLocalBlock (row, v, Tpetra::Access::ReadOnly);
auto bRow = b.getLocalBlockHost (row, v, Tpetra::Access::ReadOnly);
for(LO k = 0; k < blockSize; k++)
{
accum(k, v) = KAT::zero();
Expand All @@ -250,7 +250,7 @@ namespace Details
IST* blk = &Avalues(j * bs2);
for(LO v = 0; v < numVecs; v++)
{
auto xCol = x.getLocalBlock (col, v, Tpetra::Access::ReadOnly);
auto xCol = x.getLocalBlockHost (col, v, Tpetra::Access::ReadOnly);
for(LO br = 0; br < blockSize; br++)
{
for(LO bc = 0; bc < blockSize; bc++)
Expand All @@ -266,7 +266,7 @@ namespace Details
Kokkos::deep_copy(dinv_accum, KAT::zero());
for(LO v = 0; v < numVecs; v++)
{
auto bRow = b.getLocalBlock (row, v, Tpetra::Access::ReadOnly);
auto bRow = b.getLocalBlockHost (row, v, Tpetra::Access::ReadOnly);
for(LO br = 0; br < blockSize; br++)
{
accum(br, v) = bRow(br) - accum(br, v);
Expand All @@ -285,7 +285,7 @@ namespace Details
//Update x
for(LO v = 0; v < numVecs; v++)
{
auto xRow = x.getLocalBlock (row, v, Tpetra::Access::ReadWrite);
auto xRow = x.getLocalBlockHost (row, v, Tpetra::Access::ReadWrite);
for(LO k = 0; k < blockSize; k++)
{
xRow(k) += omega * dinv_accum(k, v);
Expand Down
18 changes: 12 additions & 6 deletions packages/ifpack2/src/Ifpack2_Experimental_RBILUK_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,10 @@ apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_t
for (size_t i = 0; i < D_block_->getNodeNumRows(); ++i)
{
local_ordinal_type local_row = i;
const_host_little_vec_type xval = xBlock.getLocalBlock(local_row, imv, Tpetra::Access::ReadOnly);
little_host_vec_type cval = cBlock.getLocalBlock(local_row, imv, Tpetra::Access::OverwriteAll);
const_host_little_vec_type xval =
xBlock.getLocalBlockHost(local_row, imv, Tpetra::Access::ReadOnly);
little_host_vec_type cval =
cBlock.getLocalBlockHost(local_row, imv, Tpetra::Access::OverwriteAll);
//cval.assign(xval);
Tpetra::COPY (xval, cval);

Expand All @@ -860,7 +862,8 @@ apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_t
for (local_ordinal_type j = 0; j < NumL; ++j)
{
local_ordinal_type col = colValsL[j];
const_host_little_vec_type prevVal = cBlock.getLocalBlock(col, imv, Tpetra::Access::ReadOnly);
const_host_little_vec_type prevVal =
cBlock.getLocalBlockHost(col, imv, Tpetra::Access::ReadOnly);

const local_ordinal_type matOffset = blockMatSize*j;
little_block_type lij((typename little_block_type::value_type*) &valsL[matOffset],blockSize_,rowStride);
Expand All @@ -881,8 +884,10 @@ apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_t
for (local_ordinal_type i = 0; i < numRows; ++i)
{
local_ordinal_type local_row = (numRows-1)-i;
const_host_little_vec_type rval = rBlock.getLocalBlock(local_row, imv, Tpetra::Access::ReadOnly);
little_host_vec_type yval = yBlock.getLocalBlock(local_row, imv, Tpetra::Access::OverwriteAll);
const_host_little_vec_type rval =
rBlock.getLocalBlockHost(local_row, imv, Tpetra::Access::ReadOnly);
little_host_vec_type yval =
yBlock.getLocalBlockHost(local_row, imv, Tpetra::Access::OverwriteAll);
//yval.assign(rval);
Tpetra::COPY (rval, yval);

Expand All @@ -895,7 +900,8 @@ apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_t
for (local_ordinal_type j = 0; j < NumU; ++j)
{
local_ordinal_type col = colValsU[NumU-1-j];
const_host_little_vec_type prevVal = yBlock.getLocalBlock(col, imv, Tpetra::Access::ReadOnly);
const_host_little_vec_type prevVal =
yBlock.getLocalBlockHost(col, imv, Tpetra::Access::ReadOnly);

const local_ordinal_type matOffset = blockMatSize*(NumU-1-j);
little_block_type uij((typename little_block_type::value_type*) &valsU[matOffset], blockSize_, rowStride);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Ifpack2BlockRelaxation, TestDiagonalBlockCrsMa
const Scalar exactSol = 0.2;

for (int k = 0; k < num_rows_per_proc; ++k) {
auto ylcl = yBlock.getLocalBlock(k, 0, Tpetra::Access::ReadOnly);
auto ylcl = yBlock.getLocalBlockHost(k, 0, Tpetra::Access::ReadOnly);
for (int j = 0; j < blockSize; ++j) {
TEST_FLOATING_EQUALITY(ylcl(j), exactSol, 1e-14);
}
Expand Down Expand Up @@ -1269,7 +1269,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Ifpack2BlockRelaxation, TestLowerTriangularBlo

for (size_t k = 0; k < num_rows_per_proc; ++k) {
LO lcl_row = k;
auto ylcl = yBlock.getLocalBlock(lcl_row, 0, Tpetra::Access::ReadOnly);
auto ylcl = yBlock.getLocalBlockHost(lcl_row, 0, Tpetra::Access::ReadOnly);
for (int j = 0; j < blockSize; ++j) {
TEST_FLOATING_EQUALITY(ylcl(j), exactSol[k], 1e-14);
}
Expand Down Expand Up @@ -1329,7 +1329,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Ifpack2BlockRelaxation, TestUpperTriangularBlo
exactSol[2] = 0.5;

for (int k = 0; k < num_rows_per_proc; ++k) {
auto ylcl = yBlock.getLocalBlock(k, 0, Tpetra::Access::ReadOnly);
auto ylcl = yBlock.getLocalBlockHost(k, 0, Tpetra::Access::ReadOnly);
for (int j = 0; j < blockSize; ++j) {
TEST_FLOATING_EQUALITY(ylcl(j), exactSol[k], 1e-14);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/ifpack2/test/unit_tests/Ifpack2_UnitTestRBILUK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(RBILUK, LowerTriangularBlockCrsMatrix, Scalar,

for (size_t k = 0; k < num_rows_per_proc; ++k) {
LO lcl_row = k;
auto ylcl = yBlock.getLocalBlock(lcl_row, 0, Tpetra::Access::ReadOnly);
auto ylcl = yBlock.getLocalBlockHost(lcl_row, 0, Tpetra::Access::ReadOnly);
for (int j = 0; j < blockSize; ++j) {
TEST_FLOATING_EQUALITY(ylcl(j),exactSol[k],1e-14);
}
Expand Down Expand Up @@ -260,7 +260,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(RBILUK, UpperTriangularBlockCrsMatrix, Scalar,
exactSol[2] = 0.5;

for (int k = 0; k < num_rows_per_proc; ++k) {
auto ylcl = yBlock.getLocalBlock(k, 0, Tpetra::Access::ReadOnly);
auto ylcl = yBlock.getLocalBlockHost(k, 0, Tpetra::Access::ReadOnly);
for (int j = 0; j < blockSize; ++j) {
TEST_FLOATING_EQUALITY(ylcl(j), exactSol[k], 1e-14);
}
Expand Down Expand Up @@ -313,7 +313,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(RBILUK, FullLocalBlockCrsMatrix, Scalar, Local
exactSol[2] = 2.0/7.0;

for (int k = 0; k < num_rows_per_proc; ++k) {
auto ylcl = yBlock.getLocalBlock(k, 0, Tpetra::Access::ReadOnly);
auto ylcl = yBlock.getLocalBlockHost(k, 0, Tpetra::Access::ReadOnly);
for (int j = 0; j < blockSize; ++j) {
TEST_FLOATING_EQUALITY(ylcl(j), exactSol[k], 1e-14);
}
Expand Down Expand Up @@ -728,7 +728,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(RBILUK, DiagonalBlockCrsMatrix, Scalar, LocalO
const Scalar exactSol = 0.2;

for (int k = 0; k < num_rows_per_proc; ++k) {
auto ylcl = yBlock.getLocalBlock(k, 0, Tpetra::Access::ReadOnly);
auto ylcl = yBlock.getLocalBlockHost(k, 0, Tpetra::Access::ReadOnly);
for (int j = 0; j < blockSize; ++j) {
TEST_FLOATING_EQUALITY(ylcl(j), exactSol, 1e-14);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Ifpack2Relaxation, TestDiagonalBlockCrsMatrix,
const auto tol = mag_type(100.0) * STS::eps();

for (int k = 0; k < num_rows_per_proc; ++k) {
auto ylcl = yBlock.getLocalBlock(k, 0, Tpetra::Access::ReadOnly);
auto ylcl = yBlock.getLocalBlockHost(k, 0, Tpetra::Access::ReadOnly);
for (int j = 0; j < blockSize; ++j) {
TEST_FLOATING_EQUALITY(ylcl(j), exactSol, tol);
}
Expand Down Expand Up @@ -1031,7 +1031,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Ifpack2Relaxation, TestLowerTriangularBlockCrs

for (size_t k = 0; k < num_rows_per_proc; ++k) {
LO lcl_row = k;
auto ylcl = yBlock.getLocalBlock(lcl_row, 0, Tpetra::Access::ReadOnly);
auto ylcl = yBlock.getLocalBlockHost(lcl_row, 0, Tpetra::Access::ReadOnly);
for (int j = 0; j < blockSize; ++j) {
TEST_FLOATING_EQUALITY(ylcl(j), exactSol[k], 1e-14);
}
Expand Down Expand Up @@ -1081,7 +1081,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Ifpack2Relaxation, TestUpperTriangularBlockCrs
exactSol[2] = 0.5;

for (int k = 0; k < num_rows_per_proc; ++k) {
auto ylcl = yBlock.getLocalBlock(k, 0, Tpetra::Access::ReadOnly);
auto ylcl = yBlock.getLocalBlockHost(k, 0, Tpetra::Access::ReadOnly);
for (int j = 0; j < blockSize; ++j) {
TEST_FLOATING_EQUALITY(ylcl(j), exactSol[k], 1e-14);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ localApplyBlockNoTrans (Tpetra::BlockCrsMatrix<Scalar, LO, GO, Node>& A,

for (LO j = 0; j < numVecs; ++j) {
for (LO lclRow = 0; lclRow < numLocalMeshRows; ++lclRow) {
auto Y_cur = Y.getLocalBlock (lclRow, j, Tpetra::Access::ReadWrite);
auto Y_cur = Y.getLocalBlockHost (lclRow, j, Tpetra::Access::ReadWrite);
if (beta == zero) {
FILL (Y_lcl, zero);
} else if (beta == one) {
Expand All @@ -132,7 +132,7 @@ localApplyBlockNoTrans (Tpetra::BlockCrsMatrix<Scalar, LO, GO, Node>& A,

auto A_cur_1d = Kokkos::subview (val, absBlkOff * blockSize * blockSize);
little_blk_type A_cur (A_cur_1d.data (), blockSize, blockSize);
auto X_cur = X.getLocalBlock (meshCol, j, Tpetra::Access::ReadOnly);
auto X_cur = X.getLocalBlockHost (meshCol, j, Tpetra::Access::ReadOnly);

GEMV (alpha, A_cur, X_cur, Y_lcl); // Y_lcl += alpha*A_cur*X_cur
} // for each entry in the current local row of the matrix
Expand Down
52 changes: 38 additions & 14 deletions packages/tpetra/core/src/Tpetra_BlockMultiVector_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,39 +577,63 @@ class BlockMultiVector :
/// is invalid on the calling process.
bool sumIntoGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]);

#ifdef TPETRA_ENABLE_DEPRECATED_CODE
/// \brief Get a writeable view of the entries at the given mesh
/// point, using a local index.
///
/// \param localRowIndex [in] Local index of the mesh point.
/// \param colIndex [in] Column (vector) to view.
/// \param vals [out] View of the entries at the given mesh point.
///
/// \return true if successful, else false. This method will
/// <i>not</i> succeed if the given local index of the mesh point
/// is invalid on the calling process.
// TPETRA_DEPRECATED
bool getLocalRowView (const LO localRowIndex, const LO colIndex, Scalar*& vals);

/// \brief Get a writeable view of the entries at the given mesh
/// point, using a global index.
///
/// \param globalRowIndex [in] Global index of the mesh point.
/// \param colIndex [in] Column (vector) to view.
/// \param vals [out] View of the entries at the given mesh point.
///
/// \return true if successful, else false. This method will
/// <i>not</i> succeed if the given global index of the mesh point
/// is invalid on the calling process.
// TPETRA_DEPRECATED
bool getGlobalRowView (const GO globalRowIndex, const LO colIndex, Scalar*& vals);

/// \brief Get a host view of the degrees of freedom at the given
/// mesh point.
///
/// \warning This method's interface may change or disappear at any
/// time. Please do not rely on it in your code yet.
///
/// Prefer using \c auto to let the compiler compute the return
/// type. This gives us the freedom to change this type in the
/// future. If you insist not to use \c auto, then please use the
/// \c little_vec_type typedef to deduce the correct return type;
/// don't try to hard-code the return type yourself.
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
//TPETRA_DEPRECATED
little_host_vec_type getLocalBlock (const LO localRowIndex, const LO colIndex) const;
#endif //TPETRA_DEPRECATED
little_host_vec_type getLocalBlock (const LO localRowIndex, const LO colIndex);

#endif // TPETRA_ENABLE_DEPRECATED_CODE

const_little_host_vec_type getLocalBlock(
const_little_host_vec_type getLocalBlockHost(
const LO localRowIndex,
const LO colIndex,
Access::ReadOnlyStruct) const;
const Access::ReadOnlyStruct) const;

little_host_vec_type getLocalBlock(
little_host_vec_type getLocalBlockHost(
const LO localRowIndex,
const LO colIndex,
Access::ReadWriteStruct);
const Access::ReadWriteStruct);

/// \brief Get a local block on host, with the intent to overwrite all blocks in the BlockMultiVector
/// before accessing the data on device. If you only intend to modify some blocks on host, use ReadWrite
/// instead (otherwise, previous changes on device may be lost)
little_host_vec_type getLocalBlock(
/// before accessing the data on device. If you intend to modify only some blocks on host, use
/// Access::ReadWrite instead (otherwise, previous changes on device may be lost)
little_host_vec_type getLocalBlockHost(
const LO localRowIndex,
const LO colIndex,
Access::OverwriteAllStruct);
const Access::OverwriteAllStruct);
//@}

protected:
Expand Down
60 changes: 46 additions & 14 deletions packages/tpetra/core/src/Tpetra_BlockMultiVector_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ replaceLocalValuesImpl (const LO localRowIndex,
const LO colIndex,
const Scalar vals[])
{
auto X_dst = getLocalBlock (localRowIndex, colIndex, Access::ReadWrite);
auto X_dst = getLocalBlockHost (localRowIndex, colIndex, Access::ReadWrite);
typename const_little_vec_type::HostMirror::const_type X_src (reinterpret_cast<const impl_scalar_type*> (vals),
getBlockSize ());
Kokkos::deep_copy (X_dst, X_src);
Expand Down Expand Up @@ -361,7 +361,7 @@ sumIntoLocalValuesImpl (const LO localRowIndex,
const LO colIndex,
const Scalar vals[])
{
auto X_dst = getLocalBlock (localRowIndex, colIndex, Access::ReadWrite);
auto X_dst = getLocalBlockHost (localRowIndex, colIndex, Access::ReadWrite);
typename const_little_vec_type::HostMirror::const_type X_src (reinterpret_cast<const impl_scalar_type*> (vals),
getBlockSize ());
AXPY (static_cast<impl_scalar_type> (STS::one ()), X_src, X_dst);
Expand Down Expand Up @@ -400,12 +400,43 @@ sumIntoGlobalValues (const GO globalRowIndex,

#ifdef TPETRA_ENABLE_DEPRECATED_CODE

template<class Scalar, class LO, class GO, class Node>
bool
// TPETRA_DEPRECATED
BlockMultiVector<Scalar, LO, GO, Node>::
getLocalRowView (const LO localRowIndex, const LO colIndex, Scalar*& vals)
{
if (! meshMap_.isNodeLocalElement (localRowIndex)) {
return false;
} else {
auto X_ij = getLocalBlockHost (localRowIndex, colIndex, Access::ReadWrite);
vals = reinterpret_cast<Scalar*> (X_ij.data ());
return true;
}
}

template<class Scalar, class LO, class GO, class Node>
bool
// TPETRA_DEPRECATED
BlockMultiVector<Scalar, LO, GO, Node>::
getGlobalRowView (const GO globalRowIndex, const LO colIndex, Scalar*& vals)
{
const LO localRowIndex = meshMap_.getLocalElement (globalRowIndex);
if (localRowIndex == Teuchos::OrdinalTraits<LO>::invalid ()) {
return false;
} else {
auto X_ij = getLocalBlockHost (localRowIndex, colIndex, Access::ReadWrite);
vals = reinterpret_cast<Scalar*> (X_ij.data ());
return true;
}
}

template<class Scalar, class LO, class GO, class Node>
typename BlockMultiVector<Scalar, LO, GO, Node>::little_host_vec_type
TPETRA_DEPRECATED
// TPETRA_DEPRECATED
BlockMultiVector<Scalar, LO, GO, Node>::
getLocalBlock (const LO localRowIndex,
const LO colIndex) const
const LO colIndex)
{
if (! isValidLocalMeshIndex (localRowIndex)) {
return little_host_vec_type ();
Expand All @@ -417,14 +448,15 @@ getLocalBlock (const LO localRowIndex,
return little_host_vec_type (blockRaw, blockSize);
}
}
#endif

#endif // TPETRA_ENABLE_DEPRECATED_CODE

template<class Scalar, class LO, class GO, class Node>
typename BlockMultiVector<Scalar, LO, GO, Node>::const_little_host_vec_type
BlockMultiVector<Scalar, LO, GO, Node>::
getLocalBlock (const LO localRowIndex,
const LO colIndex,
Access::ReadOnlyStruct) const
getLocalBlockHost (const LO localRowIndex,
const LO colIndex,
const Access::ReadOnlyStruct) const
{
if (!isValidLocalMeshIndex(localRowIndex)) {
return const_little_host_vec_type();
Expand All @@ -441,9 +473,9 @@ getLocalBlock (const LO localRowIndex,
template<class Scalar, class LO, class GO, class Node>
typename BlockMultiVector<Scalar, LO, GO, Node>::little_host_vec_type
BlockMultiVector<Scalar, LO, GO, Node>::
getLocalBlock (const LO localRowIndex,
const LO colIndex,
Access::OverwriteAllStruct)
getLocalBlockHost (const LO localRowIndex,
const LO colIndex,
const Access::OverwriteAllStruct)
{
if (!isValidLocalMeshIndex(localRowIndex)) {
return little_host_vec_type();
Expand All @@ -460,9 +492,9 @@ getLocalBlock (const LO localRowIndex,
template<class Scalar, class LO, class GO, class Node>
typename BlockMultiVector<Scalar, LO, GO, Node>::little_host_vec_type
BlockMultiVector<Scalar, LO, GO, Node>::
getLocalBlock (const LO localRowIndex,
const LO colIndex,
Access::ReadWriteStruct)
getLocalBlockHost (const LO localRowIndex,
const LO colIndex,
const Access::ReadWriteStruct)
{
if (!isValidLocalMeshIndex(localRowIndex)) {
return little_host_vec_type();
Expand Down
Loading