bob.sacamento
bob.sacamento

Reputation: 6651

Sending size_t type data with MPI

What is the safest way to send a size_t type number in MPI? For instance, I am sure that it is not safe to send it blindly as an MPI_INT. Will MPI_LONG always work?

Upvotes: 9

Views: 3745

Answers (1)

Gilles
Gilles

Reputation: 9489

What about using a macro?

#include <stdint.h>
#include <limits.h>

#if SIZE_MAX == UCHAR_MAX
   #define my_MPI_SIZE_T MPI_UNSIGNED_CHAR
#elif SIZE_MAX == USHRT_MAX
   #define my_MPI_SIZE_T MPI_UNSIGNED_SHORT
#elif SIZE_MAX == UINT_MAX
   #define my_MPI_SIZE_T MPI_UNSIGNED
#elif SIZE_MAX == ULONG_MAX
   #define my_MPI_SIZE_T MPI_UNSIGNED_LONG
#elif SIZE_MAX == ULLONG_MAX
   #define my_MPI_SIZE_T MPI_UNSIGNED_LONG_LONG
#else
   #error "what is happening here?"
#endif

Then in your code, you use my_MPI_SIZE_T as data type every time you want to transfer data of type size_t.

Upvotes: 18

Related Questions