Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending size_t type data with MPI

Tags:

c

size-t

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?

like image 928
bob.sacamento Avatar asked Nov 25 '16 15:11

bob.sacamento


1 Answers

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.

like image 177
Gilles Avatar answered Sep 30 '22 11:09

Gilles