[Trilinos-Users] Tpetra MultiVector and View Semantics

Bartlett, Roscoe A. bartlettra at ornl.gov
Fri Jan 23 14:40:50 MST 2015


Tpetra bike backward compatibility.   Given what is currently implemented in Tpetra this is the right behavior from and is really doing you a favor wham a gpu is involved.  Can explain more.

-Ross
________________________________
From: trilinos-users-bounces at software.sandia.gov <trilinos-users-bounces at software.sandia.gov> on behalf of Hamilton, Steven P. <hamiltonsp at ornl.gov>
Sent: Friday, January 23, 2015 2:13:10 PM
To: trilinos-users at software.sandia.gov
Subject: [Trilinos-Users] Tpetra MultiVector and View Semantics

I came across some surprising (to me, at least) behavior involving Tpetra::MultiVector, ArrayRCP, and ArrayView when using the latest Trilinos from the public repo, I was hoping someone might be able to comment on it.  I'm attaching a small example that demonstrates the behavior in debug mode (i.e. array bounds checking is enabled), but the basic steps to reproduce are:

  1.  Create a Tpetra::MultiVector.
  2.  Create an ArrayRCP that points to the MultiVector's data via the getData(NonConst) accessor in MultiVector.
  3.  Create an ArrayView from the ArrayRCP via the operator() conversion in ArrayRCP.
  4.  Allow the ArrayRCP created in (2) to go out of scope while the MultiVector and ArrayView both remain within scope.
  5.  Observe that the ArrayView is now invalid.

The particular error resulting when an attempt is made to access the ArrayView is:
=================
terminate called after throwing an instance of 'Teuchos::DanglingReferenceError'
  what():  Trilinos/packages/teuchos/core/src/Teuchos_RCPNode.hpp:599:

Throw number = 2

Throw test that evaluated to true: true

Error, an attempt has been made to dereference the underlying object
from a weak smart pointer object where the underling object has already
been deleted since the strong count has already gone to zero.
=================

It seems to me that, because the MultiVector is still in scope, the ArrayView should still be valid.  In a release build (i.e. array bounds checking disabled), I see the expected behavior, and running the example through valgrind results in no memory errors.  In addition, the example worked prior to the conversion to the refactor version of Tpetra.  I'm speculating that the underlying data container of the MultiVector class has changed from an ArrayRCP to a Kokkos::View, leading to some subtle changes in the reference counting semantics.  The change in behavior from the older Tpetra along with the differing behavior between debug and release builds leads me to believe that the observed behavior is not correct, but please correct me if I'm wrong on that.


Thanks,
Steven

--
Steven Hamilton
Radiation Transport Group
Reactor and Nuclear Systems Division
Oak Ridge National Laboratory
Phone: (865) 574-3646




More information about the Trilinos-Users mailing list