本文介绍了使用 MPI 发送 size_t 类型的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 MPI 中发送 size_t 类型数字的最安全方法是什么?例如,我确信将其作为 MPI_INT 盲目发送是不安全的.MPI_LONG 会一直工作吗?
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?
推荐答案
如何使用宏?
#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
然后在您的代码中,每次要传输 size_t
类型的数据时,都使用 my_MPI_SIZE_T
作为数据类型.
Then in your code, you use my_MPI_SIZE_T
as data type every time you want to transfer data of type size_t
.
这篇关于使用 MPI 发送 size_t 类型的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!