#2002 closed Bugs (invalid)
bugs in load_binary and save_binary on 64 bit machines
Reported by: | Owned by: | Matthias Troyer | |
---|---|---|---|
Milestone: | Component: | serialization | |
Version: | Boost 1.35.0 | Severity: | Regression |
Keywords: | load_binary save_binary 64 bit | Cc: | Douglas Gregor |
Description
I discovered that load_binary and save_binary do not work properly on 64 bit machines.
I discovered the problem on CentOS 5.1, 32 and 64 bit machines, running the attached program with valgrind.
If you don't compile it with -DBOOST_SERIALIZATION_WORK_AROUND, the program runs correctly on the 32 bit machine only.
On the 64 bit machine, the program seems to terminate correctly, but, if run with valgrind, a lot of errors come out.
This can appear as a minor bug, but, if you try to use Boost.MPI in conjunction with serialization (for example to broadcast an object of the class Mtx_Wrap ... see ticket #1998), your program crashes if you run it with more than one process.
I have to add that, before boost 1.35.0 were released, I used the 1.35 development version without any problem on 32 and 64 bit machines both. At the moment, I have a lot of code that uses load_binary and save_binary like it is shown in the attached code.
Attachments (1)
Change History (7)
by , 14 years ago
comment:1 by , 14 years ago
Owner: | changed from | to
---|
Mattias,
Could you take a look at this please. It looks like that our basic assumption about arrays - that elements are contiguous and a multiple of the size of the element may not be holding true on a 64 bit platform. As this is intimately related to optimization for arrays maybe you know something about this.
Robert Ramey
comment:3 by , 14 years ago
Owner: | changed from | to
---|
Robert, I guess you wanted to assign this to me and not to matias. Contiguity of arrays and vectors is guaranteed by the standard. The first thing that comes to my mind is that actually instead of using save_binary and load_binary, array wrappers should be used. save_binary and load_binary can be dangerous. I don't have CentOS but can try it on one of our 64-bit machines.
comment:4 by , 14 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
The bug is in your code. You write:
ar.save_binary(data,Nel*sizeof(size_t));
while data is an array of type T, which in your example is float. On 32 bit machines this works by chance since there sizeof(float)==sizeof(size_t), but on 64-bit machines a size_t is bigger than a float. This is the reason for the bug. It is much safer to just serialize using array wrappers:
ar << serialization::make_array(data,Nel)
which gets the correct size automatically
Matthias
comment:5 by , 14 years ago
You are right. I'm really sorry for the "false alarm". Thank you very much.
Michele.
Small test program for the bug