提升mpi x64警告“size_t to int”

时间:2016-04-16 18:27:44

标签: c++ boost mpi

我用mpi成功构建了Boost,但是我在x64平台下使用boost mpi得到了很多警告。我正在使用Boost 1.59.0 + vs2015。请帮我摆脱这些警告

这是我的测试代码。

#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <iostream>

namespace mpi = boost::mpi;

int main(int argc, char* argv[]) {
    mpi::environment env(argc, argv);
    mpi::communicator world;

    std::cout << "I am process " << world.rank() << " of " << world.size()
        << "." << std::endl;
    return 0;
}

有些警告看起来像这样:

1>d:\dependencies\boost_1_59_0\boost\mpi\detail\mpi_datatype_primitive.hpp(61) : warning C4267 : 'argument' : conversion from 'size_t' to 'int', possible loss of data
1>d:\dependencies\boost_1_59_0\boost\mpi\detail\mpi_datatype_primitive.hpp(80) : warning C4267 : 'argument' : conversion from 'size_t' to 'int', possible loss of data
1>d:\dependencies\boost_1_59_0\boost\mpi\detail\packed_iprimitive.hpp(62) : warning C4267 : 'argument' : conversion from 'size_t' to 'int', possible loss of data
1>d:\dependencies\boost_1_59_0\boost\mpi\detail\packed_iprimitive.hpp(106) : warning C4267 : 'argument' : conversion from 'size_t' to 'int', possible loss of data
1>d:\dependencies\boost_1_59_0\boost\mpi\detail\binary_buffer_iprimitive.hpp(64) : warning C4267 : 'argument' : conversion from 'size_t' to 'int', possible loss of data
1>d:\dependencies\boost_1_59_0\boost\mpi\detail\packed_oprimitive.hpp(52) : warning C4267 : 'argument' : conversion from 'size_t' to 'int', possible loss of data
1>d:\dependencies\boost_1_59_0\boost\mpi\detail\packed_oprimitive.hpp(96) : warning C4267 : “初始化” : conversion from 'size_t' to 'int', possible loss of data
1>d:\dependencies\boost_1_59_0\boost\mpi\detail\packed_oprimitive.hpp(100) : warning C4267 : 'argument' : conversion from 'size_t' to 'int', possible loss of data
1>d:\dependencies\boost_1_59_0\boost\mpi\detail\binary_buffer_oprimitive.hpp(53) : warning C4267 : 'argument' : conversion from 'size_t' to 'int', possible loss of data
1>d:\dependencies\boost_1_59_0\boost\mpi\detail\binary_buffer_oprimitive.hpp(87) : warning C4267 : 'argument' : conversion from 'size_t' to 'int', possible loss of data
1>  d:\dependencies\boost_1_59_0\boost\archive\detail\oserializer.hpp(88) : note : see reference to function template instantiation'void boost::mpi::binary_buffer_oprimitive::save<char>(const std::basic_string<char, std::char_traits<char>, std::allocator<char>> &)'
1>  d:\dependencies\boost_1_59_0\boost\archive\detail\oserializer.hpp(232) : note : see reference to function template instantiation 'void boost::archive::save_access::save_primitive<Archive, T>(Archive &, const T &)'
1>          with
1>[
1>              Archive = boost::mpi::packed_oarchive,
1>              T = std::string
1>]

1 个答案:

答案 0 :(得分:0)

恕我直言,MSVC C4267警告过于敏感。它甚至在将int转换为double时弹出。但是,在这种情况下,它可能是有效的,正如@sjsam评论的那样。

当我确信转换有效时,我经常使用以下方式在本地禁用警告:

#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable : 4244 ) // implicit conversion, possible loss of data
#endif
在代码之前

,并使用:

重新启用它
#ifdef _MSC_VER
#pragma warning( pop )
#endif

如果您确信boost::mpi值永远不会超过std::numeric_limits<int>::max(),那就把它们放在一边:

#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>

因此您只能为boost::mpi停用C4267警告。