Sending size_t type data with MPI
Asked Answered
H

1

9

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?

Hexavalent answered 25/11, 2016 at 15:5 Comment(0)
B
18

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.

Blighter answered 25/11, 2016 at 15:40 Comment(1)
Simple, effective, awesome. I wonder why this is not plain MPI.Mydriatic

© 2022 - 2024 — McMap. All rights reserved.