【问题标题】:Boost MPI and serialization - size of serialized object提升 MPI 和序列化 - 序列化对象的大小
【发布时间】:2014-04-22 17:51:09
【问题描述】:

在我的大学里,我必须测量使用 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 文档不是很熟悉,所以我可能会遗漏一些东西。

【问题讨论】:

    标签: c++ serialization boost mpi


    【解决方案1】:

    这里是:

    #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 可能会进行额外的压缩。我在快速扫描的文档中没有找到这个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      • 2018-12-22
      • 2014-04-04
      • 2011-09-07
      • 2013-08-25
      相关资源
      最近更新 更多