Discussion:
[OMPI users] How to Free Memory Allocated with MPI_Win_allocate()?
Benjamin Brock
2017-04-24 17:40:02 UTC
Permalink
How are we meant to free memory allocated with MPI_Win_allocate()? The
following crashes for me with OpenMPI 1.10.6:

#include <cstdlib>
#include <cstdio>
#include <mpi.h>

int main(int argc, char **argv) {
MPI_Init(&argc, &argv);

int n = 1000;
int *a;

MPI_Win win;
MPI_Win_allocate(n*sizeof(int), sizeof(int), MPI_INFO_NULL,
MPI_COMM_WORLD, &a, &win);

/* Why does the following crash? */
MPI_Free_mem(a);

MPI_Finalize();

return 0;
}

Any suggestions?

Ben
Nathan Hjelm
2017-04-24 18:38:55 UTC
Permalink
You don't. The memory is freed when the window is freed by MPI_Win_free (). See MPI-3.1 § 11.2.5

-Nathan

On Apr 24, 2017, at 11:41 AM, Benjamin Brock <***@berkeley.edu> wrote:

How are we meant to free memory allocated with MPI_Win_allocate()?  The following crashes for me with OpenMPI 1.10.6:

#include <cstdlib>
#include <cstdio>
#include <mpi.h>

int main(int argc, char **argv) {
  MPI_Init(&argc, &argv);

  int n = 1000;
  int *a;

  MPI_Win win;
  MPI_Win_allocate(n*sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &a, &win);

  /* Why does the following crash? */
  MPI_Free_mem(a);

  MPI_Finalize();

  return 0;
}

Any suggestions?

Ben

Loading...