One-sided

C | Fortran-2008 | Fortran-90

MPI_Put

Definition

MPI_Put permits to one-sidedly send data to the window of another MPI process. MPI_Put can be seen as executing a send by the origin process and a matching receive by the target process. The difference is that all arguments are provided by the origin process in a single routine. The read equivalent of MPI_Put is MPI_Get. A variants of MPI_Put is MPI_Rput.

Copy

Feedback

int MPI_Put(const 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 containing the data to send.

origin_count

The number of elements to send from 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 receive the 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 in the target buffer.

target_datatype

The type of an element in the target buffer.

window

The window to which put the data on the target MPI process.

Return value

The error code returned from the data put:

Example

Copy

Feedback

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

/**
 * @brief Illustrate how to put data into a target window.
 * @details This application consists of two MPI processes. MPI process 1
 * exposes a window containing an integer. MPI process 0 puts the value 12345
 * in it via MPI_Put. After the MPI_Put 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;
    MPI_Win window;
    MPI_Win_create(&window_buffer, sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &window);
    if(my_rank == 1)
    {
        printf("[MPI process 1] Value in my window_buffer before MPI_Put: %d.\n", window_buffer);
    }
    MPI_Win_fence(0, window);

    if(my_rank == 0)
    {
        // Push my value into the first integer in MPI process 1 window
        int my_value = 12345;
        MPI_Put(&my_value, 1, MPI_INT, 1, 0, 1, MPI_INT, window);
        printf("[MPI process 0] I put data %d in MPI process 1 window via MPI_Put.\n", my_value);
    }

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

    if(my_rank == 1)
    {
        printf("[MPI process 1] Value in my window_buffer after MPI_Put: %d.\n", window_buffer);
    }

    // Destroy the window
    MPI_Win_free(&window);

    MPI_Finalize();

    return EXIT_SUCCESS;
}