C++ 以MPI、C和x2B格式发送动态数组+;

C++ 以MPI、C和x2B格式发送动态数组+;,c++,boost,mpi,C++,Boost,Mpi,我的任务是测量两个进程之间的通信时间。 我想发送4,8,…,1000,…,10000字节的数据,并测量发送和接收回消息所需的时间。 所以我想我会送一系列短裤 当我发送这样初始化的数组时: mpi::communicator world; short message[100000]; .... world.send(1,0, message); short *message = new short[100000]; ... world.send(1,0, *message); 时间似乎还可以,

我的任务是测量两个进程之间的通信时间。 我想发送4,8,…,1000,…,10000字节的数据,并测量发送和接收回消息所需的时间。 所以我想我会送一系列短裤

当我发送这样初始化的数组时:

mpi::communicator world;
short message[100000];
....
world.send(1,0, message);
short *message = new short[100000];
...
world.send(1,0, *message);
时间似乎还可以,我可以看到消息[100000]和[1000]之间的时间差

但我想这样动态地分配数组:

mpi::communicator world;
short message[100000];
....
world.send(1,0, message);
short *message = new short[100000];
...
world.send(1,0, *message);
看起来第二次发送总是发送相同数量的数据,无论数组大小如何


因此,我的问题是,如何发送动态分配的数组?

在第二种情况下,
消息
属于
short*
类型,并且
*消息
取消对标量
short
的引用,即仅对数组的第一个元素的引用。使用

world.send(1, 0, message, n);
而是改变
n
的值。如果将指针强制转换为指向数组的指针,然后取消对其的引用,也应该(可能)起作用:

world.send(1, 0, *reinterpret_cast<int(*)[100]>(message));
world.send(1,0,*reinterpret_cast(message));

int(*)[100]
类型是指向包含100个元素的整数数组的指针。

它是mpi::communicator world;