Non-deterministic results with unaligned reductions
Submitted by Jose Rubio
Assigned to Nobody
Link to original bugzilla bug (#1728)
Version: 3.3 (current stable)
Description
OS: Debian 4.9.30-2+deb9u5 (2017-09-19) x86_64 GNU/Linux
I observed subtle differences when summing a sparse matrix across different runs.
This test reproduces the issue (fails around 50% of the time it's run)
#include <Eigen/Sparse>
#include <gtest/gtest.h>
#include <stdlib.h>
#include <time.h>
TEST(Sparse, Reduction)
{
srand(time(NULL));
int nrows = 11300;
int ncols = 600;
int num_non_zeros = 100;
std::vector<Eigen::Triplet<float, int> > triplets;
for (int i = 0; i < num_non_zeros; i++) {
int row = rand() % nrows;
int col = rand() % ncols;
float value = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
triplets.push_back(Eigen::Triplet<float, int>(row, col, value));
}
Eigen::SparseMatrix<float, 0, int> mat = Eigen::SparseMatrix<float, 0, int>(nrows, ncols);
mat.reserve(num_non_zeros);
mat.setFromTriplets(triplets.begin(), triplets.end());
int num_trials = 10000;
for (int tr = 0; tr < num_trials; tr++) {
Eigen::SparseMatrix<float, 0, int> mat2 = Eigen::SparseMatrix<float, 0, int>(nrows, ncols);
mat2.reserve(num_non_zeros);
mat2.setFromTriplets(triplets.begin(), triplets.end());
EXPECT_TRUE(mat.sum() == mat2.sum());
}
}
Blocking
Edited by Charles Schlosser