One-sided

C | Fortran-2008 | Fortran-90

MPI_Get

Definition

MPI_Get permits to one-sidedly fetch data from the window of another MPI process. The write equivalent of MPI_Get is MPI_Put. A variant of MPI_Get is MPI_Rget.

Copy

Feedback

int MPI_Get(void* origin_address,
            int origin_count,
            MPI_Datatype origin_datatype,
            int target_rank,
            MPI_Aint target_displacement,
            int target_count,
            MPI_Datatype target_datatype,
            MPI_Win window)

Parameters

origin_address

The address of the origin buffer; the one in which store the data fetched.

origin_count

The number of elements in the origin buffer.

origin_datatype

The type of an element in the origin buffer.

target_rank

The rank of the MPI process whose window is to be read for data.

target_displacement

The index position of the target buffer. This is made possible by the displacement unit specified on the target when creating the window. Incrementing the target_displacement by 1 will increment the position in the target buffer by <displacement_unit> bytes.

target_count

The number of elements to get from the target buffer.

target_datatype

The type of an element in the target buffer.

window

The window from which fetch the data.

Return value

The error code returned during the data fetch:

Example

Copy

Feedback

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

/**
 * @brief Illustrate how to get data from a target window.
 * @details This application consists of two MPI processes. MPI process 1
 * exposes a window containing an integer. MPI process 0 gets the value in it.
 * After the MPI_Get is issued, synchronisation takes place via MPI_Win_fence
 * and the MPI process 1 prints the value in its window.
 **/
int main(int argc, char* argv[])
{
    MPI_Init(&argc, &argv);

    // Check that only 2 MPI processes are spawn
    int comm_size;
    MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
    if(comm_size != 2)
    {
        printf("This application is meant to be run with 2 MPI processes, not %d.\n", comm_size);
        MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
    }

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

    // Create the window
    int window_buffer = 0;
    if(my_rank == 1)
    {
        window_buffer = 12345;
    }
    MPI_Win window;
    MPI_Win_create(&window_buffer, sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &window);
    MPI_Win_fence(0, window);

    int value_fetched;
    if(my_rank == 0)
    {
        // Fetch the value from the MPI process 1 window
        MPI_Get(&value_fetched, 1, MPI_INT, 1, 0, 1, MPI_INT, window);
    }

    // Wait for the MPI_Get issued to complete before going any further
    MPI_Win_fence(0, window);

    if(my_rank == 0)
    {
        printf("[MPI process 0] Value fetched from MPI process 1 window: %d.\n", value_fetched);
    }

    // Destroy the window
    MPI_Win_free(&window);

    MPI_Finalize();

    return EXIT_SUCCESS;
}