Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#2002 closed Bugs (invalid)

bugs in load_binary and save_binary on 64 bit machines

Reported by: MIchele De Stefano <micdestefano@…> 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)

main.cpp (4.0 KB ) - added by MIchele De Stefano <micdestefano@…> 14 years ago.
Small test program for the bug

Download all attachments as: .zip

Change History (7)

by MIchele De Stefano <micdestefano@…>, 14 years ago

Attachment: main.cpp added

Small test program for the bug

comment:1 by Robert Ramey, 14 years ago

Owner: changed from Robert Ramey to Matias Capeletto

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:2 by Daryle Walker, 14 years ago

Closed the preceding bug in deference to this one

comment:3 by Matthias Troyer, 14 years ago

Owner: changed from Matias Capeletto to Matthias Troyer

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 Matthias Troyer, 14 years ago

Resolution: invalid
Status: newclosed

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 micdestefano@…, 14 years ago

You are right. I'm really sorry for the "false alarm". Thank you very much.

Michele.

comment:6 by (none), 14 years ago

Milestone: Boost 1.35.1

Milestone Boost 1.35.1 deleted

Note: See TracTickets for help on using tickets.