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: Jeff Squyres (jsquyres_at_[hidden])
Date: 2009-03-14 08:53:48


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