Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/TiledArray/tiled_range1.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TiledRange1 {
TiledRange1()
: range_(0, 0), elements_range_(0, 0), tiles_ranges_(), elem2tile_() {}

/// Constructs a range with the boundaries provided by
/// Constructs a range with the tile boundaries ("hashmarks") provided by
/// the range [ \p first , \p last ).
/// \note validity of the [ \p first , \p last ) range is checked using
/// #TA_ASSERT() only if preprocessor macro \c NDEBUG is not defined
Expand All @@ -79,7 +79,7 @@ class TiledRange1 {

/// Construct a 1D tiled range.

/// This will construct a 1D tiled range with tile boundaries
/// This will construct a 1D tiled range with tile boundaries ("hashmarks")
/// {\p t0 , \p t_rest... }
/// The number of tile boundaries is n + 1, where n is the number of tiles.
/// Tiles are defined as [\p t0, t1), [t1, t2), [t2, t3), ...
Expand All @@ -96,7 +96,7 @@ class TiledRange1 {

/// Construct a 1D tiled range.

/// This will construct a 1D tiled range with tile boundaries
/// This will construct a 1D tiled range with tile boundaries ("hashmarks")
/// {\p t0 , \p t_rest... }
/// The number of tile boundaries is n + 1, where n is the number of tiles.
/// Tiles are defined as [\p t0 , t1), [t1, t2), [t2, t3), ...
Expand Down Expand Up @@ -242,22 +242,32 @@ class TiledRange1 {
/// @brief makes a uniform (or, as uniform as possible) TiledRange1

/// @param[in] range_size the range size
/// @param[in] target_block_size the desired block size
/// @return TiledRange1 obtained by tiling range `[0,range_size)` into `(range_size + target_block_size - 1)/target_block_size`
/// blocks of approximately @p target_block_size size
/// @param[in] target_tile_size the desired tile size
/// @return TiledRange1 obtained by tiling range `[0,range_size)` into
/// `ntiles = (range_size + target_tile_size - 1)/target_tile_size`
/// tiles; if `x = range_size % ntiles` is not zero, first `x` tiles
/// have size `target_tile_size` and last
/// `ntiles - x` tiles have size `target_tile_size - 1`, else
/// all tiles have size `target_tile_size` .
// clang-format on
static TiledRange1 make_uniform(std::size_t range_size,
std::size_t target_block_size) {
std::size_t target_tile_size) {
if (range_size > 0) {
TA_ASSERT(target_block_size > 0);
std::size_t nblocks =
(range_size + target_block_size - 1) / target_block_size;
std::size_t block_size = (range_size + nblocks - 1) / nblocks;
TA_ASSERT(target_tile_size > 0);
std::size_t ntiles =
(range_size + target_tile_size - 1) / target_tile_size;
auto dv = std::div((long)(range_size + ntiles - 1), (long)ntiles);
auto avg_tile_size = dv.quot - 1, num_avg_plus_one = dv.rem + 1;
std::vector<std::size_t> hashmarks;
hashmarks.reserve(nblocks + 1);
hashmarks.push_back(0);
for (auto i = block_size; i < range_size; i += block_size) {
hashmarks.push_back(i);
hashmarks.reserve(ntiles + 1);
std::size_t element = 0;
for (auto i = 0; i < num_avg_plus_one;
++i, element += avg_tile_size + 1) {
hashmarks.push_back(element);
}
for (auto i = num_avg_plus_one; i < ntiles;
++i, element += avg_tile_size) {
hashmarks.push_back(element);
}
hashmarks.push_back(range_size);
return TiledRange1(hashmarks.begin(), hashmarks.end());
Expand Down
5 changes: 2 additions & 3 deletions tests/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*
*/

#include "kmp5_compute_trange1.h"
#include "range_fixture.h"
#include "tiledarray.h"
#include "unit_test_config.h"
Expand Down Expand Up @@ -340,8 +339,8 @@ BOOST_AUTO_TEST_CASE(tiles_of_arrays_non_unit_blocking) {
std::size_t dim_one = 1336;
std::size_t dim_two = 552;
{
TA::TiledRange1 tr1_mode0 = kmp5_compute_trange1(dim_one, block_size);
TA::TiledRange1 tr1_mode1 = kmp5_compute_trange1(dim_two, 10);
TA::TiledRange1 tr1_mode0 = TiledRange1::make_uniform(dim_one, block_size);
TA::TiledRange1 tr1_mode1 = TiledRange1::make_uniform(dim_two, 10);
tr = TiledArray::TiledRange({tr1_mode0, tr1_mode1});
tr_split = TiledArray::TiledRange({tr1_mode1});
}
Expand Down
61 changes: 0 additions & 61 deletions tests/kmp5_compute_trange1.h

This file was deleted.

18 changes: 18 additions & 0 deletions tests/tiled_range1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,22 @@ BOOST_AUTO_TEST_CASE(concatenation) {
BOOST_CHECK(concat(r2, r1) == (TiledRange1{0, 3, 4, 5, 7, 11, 13}));
}

BOOST_AUTO_TEST_CASE(make_uniform) {
BOOST_REQUIRE_NO_THROW(TiledRange1::make_uniform(0, 0));
BOOST_CHECK(TiledRange1::make_uniform(0, 0) == TiledRange1{});
BOOST_REQUIRE_NO_THROW(TiledRange1::make_uniform(0, 1));
BOOST_CHECK(TiledRange1::make_uniform(0, 1) == TiledRange1{});
BOOST_REQUIRE_NO_THROW(TiledRange1::make_uniform(3, 10));
BOOST_CHECK(TiledRange1::make_uniform(3, 10) == (TiledRange1{0, 3}));
BOOST_REQUIRE_NO_THROW(TiledRange1::make_uniform(50, 10));
BOOST_CHECK(TiledRange1::make_uniform(50, 10) ==
(TiledRange1{0, 10, 20, 30, 40, 50}));
BOOST_REQUIRE_NO_THROW(TiledRange1::make_uniform(55, 10));
BOOST_CHECK(TiledRange1::make_uniform(55, 10) ==
(TiledRange1{0, 10, 19, 28, 37, 46, 55}));
BOOST_REQUIRE_NO_THROW(TiledRange1::make_uniform(59, 10));
BOOST_CHECK(TiledRange1::make_uniform(59, 10) ==
(TiledRange1{0, 10, 20, 30, 40, 50, 59}));
}

BOOST_AUTO_TEST_SUITE_END()