Rookie HPC

Addressing

C | FORTRAN-legacy | FORTRAN-2008

MPI_Aint_diff

Definition

MPI_Aint_diff calculates the difference between two addresses. As the standard states, “the resulting address is valid only at the process that generated addr1 and addr2, and addr1 and addr2 must correspond to locations in the same object in the same process”.

Copy

Feedback

MPI_Aint MPI_Aint_diff(MPI_Aint addr_1,
                       MPI_Aint addr_2);

Parameters

addr_1
The address from which will be subtracted the address contained in the second parameter.
addr_2
The address to subtract from the address passed as the first parameter.

Returned value

The difference between the two addresses.

Example

Copy

Feedback

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

/**
 * @brief Illustrate how to get the difference between addresses.
 * @details This application takes the address of two elements in an array and
 * calculates the difference between the two before printing the difference.
 **/
int main(int argc, char* argv[])
{
    MPI_Init(&argc, &argv);

    int a[10];

    MPI_Aint addr_1;
    MPI_Get_address(&a[2], &addr_1);

    MPI_Aint addr_2;
    MPI_Get_address(&a[8], &addr_2);

    MPI_Aint addr_gap;
    addr_gap = MPI_Aint_diff(addr_2, addr_1);

    printf("Difference between the address of the 3rd int and 9th int is %ld bytes.\n", addr_gap);

    MPI_Finalize();

    return EXIT_SUCCESS;
}