Rookie HPC

Miscellaneous

C

MPI_Count

Definition

MPI_Count is an MPI_Datatype that is able to contain an address location in memory, an address offset in a file or just a count. The fact that the majority of MPI routines still rely on “int” count arguments is due to backward compatibility reasons. Please refer to MPI_COUNT_KIND to see the FORTRAN equivalent.

Example

Copy

Feedback

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

/**
 * @brief Illustrate how to use the MPI_Count datatype.
 * @details This application gets the size of an MPI Datatype via MPI_Count.
 **/
int main(int argc, char* argv[])
{
    MPI_Init(&argc, &argv);

    // Create the MPI datatype
    MPI_Datatype my_type;
    MPI_Type_contiguous(10, MPI_INT, &my_type);
    MPI_Type_commit(&my_type);

    // Retrieve the size of the MPI datatype created
    MPI_Count count;
    MPI_Type_size_x(my_type, &count);
    printf("The type created would generate a message of %lld bytes.\n", count);

    MPI_Finalize();

    return EXIT_SUCCESS;
}