Unclear documentation about serialization

Issue #446 new
Kataev Victor created an issue

I apologize for such a strong issue title, but I want to clarify the blaze::Archive documentation: the serialization is not cross-platform, it does not take into account type size, alignment and version of the library itself?

And there is no reasonable way to bypass.

So for cross-platform application where data save/load is required I definitely shouldn't create read/write module based on blaze::Archive()?

It should only be used within the context of the same operating system, compiler version and blaze library version.

Right?

Comments (2)

  1. Klaus Iglberger

    Hi Kataev!

    Thanks for taking the time to create the issue. To our best knowledge, there are no limitations with respect to switching operating systems, compiler versions and/or the Blaze version when writing archives. Even the size of the written data type is taken into account when switching from a 32-bit operating system to a 64-bit one. The following example demonstrates that the archive is independent of all aspects of the source and target vectors (type of vector, alignment, and padding), but merely represents the content of the vectors. It also demonstrates the runtime checks used to guarantee the correctness:

    // Serialization of both vectors
    {
       blaze::StaticVector<double,5UL,rowVector,aligned,padded> d;
       blaze::CompressedVector<int,columnVector> s;
    
       d = { 1, 2, 3, 4, 5 };
       s = { 1, 0, 2, 0, 3 };
    
       // Creating an archive that writes into a the file "vectors.blaze"
       blaze::Archive<std::ofstream> archive( "vectors.blaze" );
    
       // Serialization of both vectors into the same archive. Note that d lies before s!
       archive << d << s;
    }
    
    // Reconstitution of both vectors
    {
       blaze::StaticVector<double,5UL,rowVector,unaligned,unpadded> d1;  // Needs to be double, otherwise a 'std::runtime_error' is thrown
       blaze::StaticVector<int,5UL,rowVector,aligned,padded> d2;         // Needs to be 'int', otherwise a 'std::runtime_error is thrown'
    
       // Creating an archive that reads from the file "vectors.blaze"
       blaze::Archive<std::ifstream> archive( "vectors.blaze" );
    
       // Reconstituting the former d vector into d1.
       archive >> d1;
    
       // Reconstituting the former s vector into d2.
       archive >> d2;
    
       std::cout << "\n"
                 << " d1 = " << d1 << "\n"  // Prints ( 1, 2, 3, 4, 5 )
                 << " d2 = " << d2 << "\n"  // Prints ( 1, 0, 2, 0, 3 )
                 << "\n";
    }
    

    I hope this answers the question. If you experience any problems when switching systems, please let us know.

    Best regards,

    Klaus!

  2. Log in to comment