Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] freeing attributes on communicators
From: George Bosilca (bosilca_at_[hidden])
Date: 2009-03-14 17:06:56

Based on my understanding of the MPI standard, the attribute copy and
delete functions have to be called every time we duplicate or free a
communicator (if the attribute is attached to it). As in this
particular case, the copy function is empty (redirected to
MPI_NULL_COPY_FN) it should be illegal for the user to call
MPI_Keyval_free until the last reference to the attribute is gone. To
be more specific, if we kept a reference count on the keyval, your
code will not be correct because as a user you will only get one
reference count and you release this keyval twice (without talking
about the fact that we are not supposed to give you the keyval the
second time as you already free it in the first call to delete_fn).

I tend to say that if someone should have reference counts in this
particular case, is the user.


On Mar 14, 2009, at 08:53 , Jeff Squyres wrote:

> On Mar 12, 2009, at 12:43 PM, Robert Latham wrote:
>> I'm using openmpi-1.3 in this example, linux, gcc-4.3.2, configured
>> with nothing special.
>> If I run the following simple C code under valgrind, single
>> process, I
>> get some errors about reading and writing already-freed memory:
> Hmm. This is an interesting case. You end up calling delete_fn()
> (and therefore MPI_Keyval_free()) twice -- once on each
> communicator. This definitely borks up OMPI's keyval reference
> counts and Badness ensues.
> Is is correct to call MPI_Keyval_free() multiple times on the same
> keyval? I know you can call it "early", just like most other
> MPI_*_FREE functions, but I didn't think you were allowed to call
> MPI_Keyval_free() multiple times on the same keyval value...?
>> #include <mpi.h>
>> #include <stdlib.h>
>> int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra) {
>> MPI_Keyval_free(&keyval);
>> return 0;
>> }
>> int main (int argc, char **argv)
>> {
>> MPI_Comm duped;
>> int keyval;
>> MPI_Init(&argc, &argv);
>> MPI_Comm_dup(MPI_COMM_SELF, &duped);
>> MPI_Keyval_create(MPI_NULL_COPY_FN, delete_fn, &keyval,
>> NULL);
>> MPI_Attr_put(MPI_COMM_SELF, keyval, NULL);
>> MPI_Attr_put(duped, keyval, NULL);
>> MPI_Comm_free(&duped);
>> MPI_Finalize();
>> return 0;
>> }
> --
> Jeff Squyres
> Cisco Systems
> _______________________________________________
> users mailing list
> users_at_[hidden]