Definition
MPI_INT64_T is an MPI_Datatype that represents an 8-byte integer type in MPI, it corresponds to an int64_t in C. For the FORTRAN counterpart, please see MPI_INTEGER8.
Datatypes
C
MPI_INT64_T is an MPI_Datatype that represents an 8-byte integer type in MPI, it corresponds to an int64_t in C. For the FORTRAN counterpart, please see MPI_INTEGER8.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <mpi.h>
/**
* @brief Illustrate how to communicate a 8-byte int between 2 MPI processes.
* @details This application is meant to be run with 2 MPI processes: 1 sender
* and 1 receiver. The former sends a 8-byte int to the latter, which prints it.
**/
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
// Check that 2 MPI processes are used.
int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
if(size != 2)
{
printf("This application is meant to be run with 2 MPI processes.\n");
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
// Get my rank and do the corresponding job.
enum role_ranks { SENDER, RECEIVER };
int my_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
switch(my_rank)
{
case SENDER:
{
// Send the int
int64_t intToSend = 123456789;
printf("[MPI process %d] I send int: %lld.\n", my_rank, intToSend);
MPI_Ssend(&intToSend, 1, MPI_INT64_T, RECEIVER, 0, MPI_COMM_WORLD);
break;
}
case RECEIVER:
{
// Receive the int
int64_t intReceived;
MPI_Recv(&intReceived, 1, MPI_INT64_T, SENDER, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("[MPI process %d] I received int: %lld.\n", my_rank, intReceived);
break;
}
}
MPI_Finalize();
return EXIT_SUCCESS;
}
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
/**
* @brief Illustrate how to communicate an array of 8-byte ints between 2 MPI
* processes.
* @details This application is meant to be run with 2 MPI processes: 1 sender
* and 1 receiver. The former sends an array of 8-byte ints to the latter, which
* prints it.
**/
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
// Check that 2 MPI processes are used.
int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
if(size != 2)
{
printf("This application is meant to be run with 2 MPI processes.\n");
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
// Get my rank and do the corresponding job.
enum role_ranks { SENDER, RECEIVER };
int my_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
switch(my_rank)
{
case SENDER:
{
// Send the ints
int64_t intsToSend[2] = { 12345, 67890 };
printf("[MPI process %d] I send ints: %lld and %lld.\n", my_rank, intsToSend[0], intsToSend[1]);
MPI_Ssend(intsToSend, 2, MPI_INT64_T, RECEIVER, 0, MPI_COMM_WORLD);
break;
}
case RECEIVER:
{
// Receive the ints
int64_t intsReceived[2];
MPI_Recv(intsReceived, 2, MPI_INT64_T, SENDER, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("[MPI process %d] I received ints: %lld and %lld.\n", my_rank, intsReceived[0], intsReceived[1]);
break;
}
}
MPI_Finalize();
return EXIT_SUCCESS;
}