Rookie HPC

Addressing

Datatypes

C

MPI_Aint

Definition

MPI_Aint is an MPI_Datatype that represents a type able to contain a memory address. It is used in heterogeneous datatype creation routines for instance, such as MPI_Type_create_hindexed, MPI_Type_create_hindexed_block, MPI_Type_create_hvector and MPI_Type_create_struct. To see the FORTRAN counterpart (both legacy and 2008), please see MPI_ADDRESS_KIND.

Example

Copy

Feedback

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

/**
 * @brief Illustrate how to manipulate the MPI_Aint datatype.
 * @details This application takes the address of elements at different
 * locations and calculates the distance, in bytes, between the two.
 **/
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;
}