Skip to content

Commit

Permalink
Allow compatibility in serialization
Browse files Browse the repository at this point in the history
When HMAT_READ_NRCHILD_CHAR environment variable is set, files are read
using old format.
We always write in new format though in order to ensure that we can get
rid of this compatibility layer in a near future.
  • Loading branch information
dbarbier committed Dec 5, 2024
1 parent 2b4bc1f commit 368b88d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
*/

#include "serialization.hpp"
#include <vector>
#include "compression.hpp"
#include "rk_matrix.hpp"
#include "common/my_assert.h"

#include <cstdlib>
#include <vector>

namespace hmat {

// TODO decide what to todo with read/write return value
Expand Down Expand Up @@ -205,7 +207,14 @@ template<typename TR> TR * MatrixStructUnmarshaller<T>::readTree(TR * tree) {
tree = readTreeNode(tree);
if(tree != NULL) {
tree->depth = depth;
int nrChild = readValue<int>();
// Number of children was initially written as a char, and now as an int.
// When environment variable HMAT_READ_NRCHILD_CHAR is set, read_nrchild_char
// is set to 1 and number of children is read as a char.
static int read_nrchild_char = -1;
if (read_nrchild_char == -1) {
read_nrchild_char = getenv("HMAT_READ_NRCHILD_CHAR") != nullptr;
}
int nrChild = read_nrchild_char == 0 ? readValue<int>() : readValue<char>();
for(int i = 0; i < nrChild; i++) {
tree->insertChild(i, readTree(tree));
}
Expand Down

0 comments on commit 368b88d

Please sign in to comment.