Cannot load Archive in another thread?

Issue #162 wontfix
Frank LSF created an issue

I'm using the following code to load an archive of sparse matrix:

  blaze::Archive<std::ifstream> archive(FLAGS_matrixSavePath);
  archive >> features_matrix_;

Everything's fine when I'm doing this on main thread; but once I offload it to another thread (using folly::via() and lambda function), I can still get the correct results (rows, cols, nnz), but all entries seem to be NaN. And when I multiply the matrix by a vector, all results are NaN.

Is the Archive not supposed to be called in a different thread? Or should I allocate it on the heap? What am I missing here?

Comments (1)

  1. Klaus Iglberger

    Hi Frank!

    Thanks for creating this issue. We tried to reproduce your problem, but couldn't find anything wrong with the Blaze serialization functionality in combination with threads. The following code works fine and as expected:

    CompressedMatrix<int> A{ { 1, 0, 2, 3, 0 }
                           , { 4, 0, 0, 5, 0 }
                           , { 0, 0, 6, 7, 8 } };
    CompressedMatrix<int> B;
    
    {
       std::thread writer( []( CompressedMatrix<int> const& mat ) {
                              Archive<std::ofstream> archive( "mat.txt" );
                              archive << mat;
                           }
                         , std::ref(A) );
       writer.join();
    }
    
    {
       std::thread reader( []( CompressedMatrix<int>& mat ) {
                              Archive<std::ifstream> archive( "mat.txt" );
                              archive >> mat;
                           }
                         , std::ref(B) );
       reader.join();
    }
    
    assert( A == B );
    

    Unfortunately we have too little information to debug this issue. However, since serialization and threading are two orthogonal issues, we expect that this is very likely a threading or less likely a folly issue. We are sorry for not being able to point you to a possible solution,

    Best regards,

    Klaus!

  2. Log in to comment