[Trilinos-Users] [EXTERNAL] Only using non-owning RCPs

Bartlett, Roscoe A rabartl at sandia.gov
Thu Dec 22 12:59:54 EST 2016


Bart,

I am the architect of the Teuchos Memory Management classes and the author of the detailed document describing it:

    https://trilinos.org/docs/dev/packages/teuchos/doc/html/TeuchosMemoryManagementSAND.pdf

What you describe may result is segfaults for some use cases that I can think of.  The problem is that Julia can’t know about all of the C++ persisting object associations because many of them are created inside of C++ objects that Julia never sees.  Instead, Julia (or any client) should always create C++ objects wrapped as RCPs, manage them as RCPs, pass them to other C++ objects when persisting associations are required, and then the Julia finalizer should just set its RCP pointing to the object to null.  I think this is exactly what PyTrilinos does with the SWIG wrappers for Python.  I think Julia (or any client) needs to do something similar.

NOTE: The same thing would equally apply to a C++ class library that used std::shared_ptr to manage its persisting associations as well.  This is the nature of reference counting.

Can we create a Trilinos GitHub Issue and discuss this topic in there?  Then other people who are interested can @mention themselves and get updates on the conversation.

Thanks,

-Ross

Dr. Roscoe A. Bartlett, PhD
Sandia National Laboratories

From: Trilinos-Users [mailto:trilinos-users-bounces at trilinos.org] On Behalf Of Bart Janssens
Sent: Thursday, December 22, 2016 10:47 AM
To: Trilinos-users at trilinos.org
Subject: [EXTERNAL] [Trilinos-Users] Only using non-owning RCPs

Hi all,
I am taking the first small steps towards providing an interface from the Julia language to Trilinos (starting with Tpetra). In Julia, memory management happens through garbage collection. For interfacing with C++ code, this means that we can allocate using new and add a so-called finalizer to Julia objects that gets called by the garbage collector when the object is no longer referenced. In the case of a wrapped C++ object, that finalizer would then call delete. In effect, this is as if the C++ object is already stored in a smart pointer.

To deal with the Teuchos RCP, I was thinking of using the following approach:
- Objects allocated from the Julia interface just use the Julia finalizer system, and are not stored in an RCP
- Whenever an RCP to such an object is needed, it is obtained using rcpFromRef
The consequence of this is that structures like a Tpetra matrix would never have an owning RCP refer to them. Is this approach compatible with the way Trilinos works?
Kind regards,
Bart
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://trilinos.org/pipermail/trilinos-users/attachments/20161222/d31faf23/attachment.html>


More information about the Trilinos-Users mailing list