2

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>]
定坤宋
  • 35
  • 3
  • 1
    One clever thing to do would be to check if sizeof(size_t) is lesser than or equal to sizeof(int) in your implementation(this is OS specific). If so you can neglect this warning. – sjsam Apr 16 '16 at 19:03
  • I would consider that a bug in boost. Before reporting make sure it is not fixed in the latest version (I just checked, it is not). – Zulan Apr 17 '16 at 08:34
  • 1
    @sjsam, `size_t` is unsigned, so there will be loss of data even for `sizeof(int) == sizeof(size_t)`. – Zulan Apr 17 '16 at 08:45
  • on most 64x machines size_t is `unsigned long`. i believe the correct way is to implement use of size_t in your code instead of ignoring the warnings. that way your code will *always* be true. – HazirBot Apr 17 '16 at 10:15
  • Agreed. This does look like a bug in boost. @Zulan. There is a boost.mpi function use std::size_t for int arguement – 定坤宋 Apr 17 '16 at 15:00
  • @Zulan: I overlooked the fact that size_t is unsigned. Considering that `int` by default will be signed you have a valid point. – sjsam Apr 17 '16 at 16:01

1 Answers1

0

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.

kenba
  • 4,303
  • 1
  • 23
  • 40