简体   繁体   中英

Boost mpi x64 warning “size_t to int”

I have built Boost with mpi successfully, but I got lots of warnings using boost mpi under x64 platform. I am using Boost 1.59.0 + vs2015. Please help me get rid of these warnings

Here's my test code.

#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;
}

And some of the warnings look like this:

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>]

IMHO the MSVC C4267 warning is too sensitive. It even pops up when converting an int to a double. However, in this instance it may be valid, as @sjsam commented.

When I'm confident that the conversion is valid, I often disable the warning locally using:

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

before the code, and re-enable it using:

#ifdef _MSC_VER
#pragma warning( pop )
#endif

If you are confident that the boost::mpi value will never exceed std::numeric_limits<int>::max() then put them around:

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

so you can disable the C4267 warning for boost::mpi only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM