DLA-Future icon indicating copy to clipboard operation
DLA-Future copied to clipboard

Random matrix set gives always the same matrix setup

Open albestro opened this issue 6 years ago • 0 comments

The current implementation of dlaf::matrix::util::set_random and dlaf::matrix::util::set_random_hermitian_positive_definite always creates the same matrix at each call.

In fact, the current implementation uses a seed for each tile which is exclusively based on the GlobalTileIndex.

This means that the next proposed test would fail:

TYPED_TEST(MatrixUtilsTest, RandomHermitianPositiveDefiniteDoesNotRepeat) {
  const TileElementSize size_block{5, 5};
  const GlobalElementSize size_matrix{NUM_MPI_RANKS * size_block.rows(), NUM_MPI_RANKS * size_block.cols()};

  comm::CommunicatorGrid comm_grid(MPI_COMM_WORLD, NUM_MPI_RANKS, 1, common::Ordering::RowMajor);

  Matrix<TypeParam, Device::CPU> matrixA(size_matrix, size_block, comm_grid);
  Matrix<TypeParam, Device::CPU> matrixB(size_matrix, size_block, comm_grid);

  matrix::util::set_random_hermitian_positive_definite(matrixA);
  matrix::util::set_random_hermitian_positive_definite(matrixB);

  const auto& distribution = matrixA.distribution();

  for (auto j_tile = 0; j_tile < distribution.localNrTiles().cols(); ++j_tile) {
    for (auto i_tile = 0; i_tile < distribution.localNrTiles().rows(); ++i_tile) {
      LocalTileIndex current_tile{i_tile, j_tile};
      hpx::dataflow(hpx::util::unwrapping(
            [](auto&& tileA, auto&& tileB) {
              for (auto j = 0; j < tileA.size().cols(); ++j)
                for (auto i = 0; i < tileA.size().rows(); ++i) {
                  const TileElementIndex current_element{i, j};
                  EXPECT_NE(tileA(current_element), tileB(current_element));
                }
            }),
            matrixA.read(current_tile), matrixB.read(current_tile));
    }
  }
}

albestro avatar Feb 20 '20 12:02 albestro