提高MPI和序列化对象的大小

Boost MPI and size of serialized object

本文关键字:对象 序列化 MPI 提高      更新时间:2023-10-16

在我的大学里,我必须测量使用MPI发送的c++ STL类型序列化的开销。

测量时间很容易,但如果我想测量例如发送1000个字符的vector和1000个字符的数组需要多少字节,我就会遇到问题。看看Boost.MPI文档:http://www.boost.org/doc/libs/1_55_0/doc/html/mpi/tutorial.html#mpi.user_data_types我可以看到它使用Boost.Serialization进行序列化:http://www.boost.org/doc/libs/1_55_0/libs/serialization/doc/

Boost.Serialization在序列化期间使用存档,但我看不出是否有一种方法可以从存档中提取它所需的字节量?我不是很熟悉boost文档,所以我可能会错过一些东西。

开始:

#include <iostream>
#include <sstream>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/vector.hpp>
int main()
{
    std::ostringstream oss;
    boost::archive::binary_oarchive oa(oss);
    std::vector<char> v(1000);
    // stream
    oa << v;
    std::cout << "The number of bytes taken for the vector in an archive is " << oss.str().size() << "n";
}

在我的系统上它打印:

The number of bytes taken for the vector in an archive is 1048

查看Live On Coliru

有可能MPI的packed_oarchive做了额外的压缩。我在文档中没有发现这个