One-sided

C | Fortran-2008 | Fortran-90

MPI_Win_free

Definition

MPI_Win_free, as it name suggests, frees the resources behind an MPI_Win. It also returns a null handle, equal to MPI_WIN_NULL. MPI_Win_free is a collective operation; it must be called by all the MPI processes involved in the corresponding group. Each MPI process must call it only after it has completed all its pending RMA communications with that window.
Freeing a window that was created with a call to MPI_Win_create_dynamic detaches all associated memory. That is, MPI_Win_free has the same effect as if all attached memory was detached by calls to MPI_Win_detach.

Copy

Feedback

MPI_Win_free(MPI_Win window);

Parameters

window

The window to destroy. On success, it will contain the null handle MPI_WIN_NULL.

Return value

The error code returned from the window destruction:

Example

Copy

Feedback

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>

/**
 * @brief Illustrate how to destroy a window.
 * @details This application consists in creating a window and destroying it.
 **/
int main(int argc, char* argv[])
{
    MPI_Init(&argc, &argv);

    // Get my rank
    int my_rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    // Create the window
    const int ARRAY_SIZE = 2;
    int window_buffer[ARRAY_SIZE];
    MPI_Win window;
    MPI_Win_create(window_buffer, ARRAY_SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &window);
    printf("[MPI process %d] Window created.\n", my_rank);
    
    // Issue RMA communications
    // ...
    // Wait for all RMA communications to complete

    // Destroy the window
    MPI_Win_free(&window);
    printf("[MPI process %d] Window destroyed.\n", my_rank);

    MPI_Finalize();

    return EXIT_SUCCESS;
}