Skip to content

Commit

Permalink
Tpetra::Vector: Fix deprecated warning (Issue #104)
Browse files Browse the repository at this point in the history
@trilinos/tpetra Vector::normWeighted is deprecated.  It calls its
parent class' method MultiVector::normWeighted, which is also
deprecated.  Even though nothing calls Vector::normWeighted any more,
some compilers still emit a deprecated warning when building it, because
it calls a deprecated method.  This breaks builds that turn on warnings
as errors, and also adds useless noise to the build output.

This commit reimplements Vector::normWeighted so that it doesn't call
MultiVector::normWeighted.  This should fix Issue #104.

Build/Test Cases Summary
Enabled Packages: TpetraCore
Disabled Packages: FEI,STK,PyTrilinos,NOX,Teko,Piro
0) MPI_DEBUG => Test case MPI_DEBUG was not run! => Does not affect push readiness! (-1.00 min)
1) SERIAL_RELEASE => Test case SERIAL_RELEASE was not run! => Does not affect push readiness! (-1.00 min)
2) MPI_DEBUG_COMPLEX => passed: passed=85,notpassed=0 (7.06 min)
3) SERIAL_RELEASE => passed: passed=65,notpassed=0 (9.08 min)
  • Loading branch information
Mark Hoemmen committed Jan 27, 2016
1 parent 6d70e6d commit 9f19975
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions packages/tpetra/core/src/Tpetra_Vector_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

#include "Tpetra_MultiVector.hpp"
#include "KokkosCompat_View.hpp"
#include "Kokkos_Blas1_MV.hpp"

namespace Tpetra {

Expand Down Expand Up @@ -200,9 +201,56 @@ namespace Tpetra {
Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic>::
normWeighted (const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic>& weights) const
{
mag_type norm;
this->normWeighted (weights, Teuchos::arrayView (&norm, 1));
return norm;
using Kokkos::ALL;
using Kokkos::subview;
using Teuchos::Comm;
using Teuchos::RCP;
using Teuchos::reduceAll;
using Teuchos::REDUCE_SUM;
typedef Kokkos::Details::ArithTraits<impl_scalar_type> ATS;
typedef Kokkos::Details::ArithTraits<mag_type> ATM;
typedef Kokkos::View<mag_type, device_type> norm_view_type; // just one
const char tfecfFuncName[] = "normWeighted: ";

#ifdef HAVE_TPETRA_DEBUG
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
! this->getMap ()->isCompatible (*weights.getMap ()), std::runtime_error,
"Vectors do not have compatible Maps:" << std::endl
<< "this->getMap(): " << std::endl << *this->getMap()
<< "weights.getMap(): " << std::endl << *weights.getMap() << std::endl);
#else
const size_t lclNumRows = this->getLocalLength ();
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
lclNumRows != weights.getLocalLength (), std::runtime_error,
"Vectors do not have the same local length.");
#endif // HAVE_TPETRA_DEBUG

norm_view_type lclNrm ("lclNrm"); // local norm
mag_type gblNrm = ATM::zero (); // return value

auto X_lcl = this->template getLocalView<device_type> ();
auto W_lcl = this->template getLocalView<device_type> ();
KokkosBlas::nrm2w_squared (lclNrm,
subview (X_lcl, ALL (), 0),
subview (W_lcl, ALL (), 0));
const mag_type OneOverN =
ATM::one () / static_cast<mag_type> (this->getGlobalLength ());
RCP<const Comm<int> > comm = this->getMap ().is_null () ?
Teuchos::null : this->getMap ()->getComm ();

if (! comm.is_null () && this->isDistributed ()) {
// Assume that MPI can access device memory.
reduceAll<int, mag_type> (*comm, REDUCE_SUM, 1, lclNrm.ptr_on_device (),
&gblNrm);
gblNrm = ATM::sqrt (gblNrm * OneOverN);
}
else {
auto lclNrm_h = Kokkos::create_mirror_view (lclNrm);
Kokkos::deep_copy (lclNrm_h, lclNrm);
gblNrm = ATM::sqrt (ATS::magnitude (lclNrm_h()) * OneOverN);
}

return gblNrm;
}

template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic>
Expand Down

0 comments on commit 9f19975

Please sign in to comment.