提升MPI和序列化 - 序列化对象的大小

And*_*dna 2 c++ serialization boost mpi

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

测量时间很容易,但是如果我想测量例如需要多少字节来发送vector1000个字符和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 /库/ 1_55_0 /库/串行化/ DOC /

Boost.Serialization在序列化期间使用归档,但是我无法看到是否有一种方法可以从归档中提取所需的字节数量?我对升级文档不是很熟悉所以我可能会遗漏一些东西.

seh*_*ehe 6

开始:

#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";
}
Run Code Online (Sandbox Code Playgroud)

在我的系统上打印:

The number of bytes taken for the vector in an archive is 1048
Run Code Online (Sandbox Code Playgroud)

看到Live On Coliru

MPI可能packed_oarchive会进行额外的压缩.我没有在快速扫描的文档中找到这个.