Skip to content

Commit 4a5a33d

Browse files
committed
Merge branch 'development' of https://github.com/dash-project/dash into feat-halo
2 parents d281d99 + e1af056 commit 4a5a33d

File tree

9 files changed

+166
-32
lines changed

9 files changed

+166
-32
lines changed

CMakeExt/GenerateDASHCXX.cmake

+8-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,16 @@ if (";${DART_IMPLEMENTATIONS_LIST};" MATCHES ";mpi;")
3939
set(ADDITIONAL_LIBRARIES_WRAP
4040
"${ADDITIONAL_LIBRARIES_WRAP} ${MPI_C_LIB}")
4141
endforeach()
42-
set(ADDITIONAL_INCLUDES_WRAP "${ADDITIONAL_INCLUDES_WRAP} -I${MPI_INCLUDE_PATH}")
42+
foreach (ADDITIONAL_INCLUDE_PATH ${MPI_INCLUDE_PATH})
43+
set(ADDITIONAL_INCLUDES_WRAP
44+
"${ADDITIONAL_INCLUDES_WRAP} -I${ADDITIONAL_INCLUDE_PATH}")
45+
endforeach()
4346
set(DASHCC ${CMAKE_CXX_COMPILER})
4447
set(DART_IMPLEMENTATION "mpi")
45-
set(ADDITIONAL_COMPILE_FLAGS_WRAP "${ADDITIONAL_COMPILE_FLAGS_WRAP} ${MPI_ADDITIONAL_COMPILE_FLAGS}")
48+
foreach (ADDITIONAL_COMPILE_FLAG ${MPI_ADDITIONAL_COMPILE_FLAGS})
49+
set(ADDITIONAL_COMPILE_FLAGS_WRAP
50+
"${ADDITIONAL_COMPILE_FLAGS_WRAP} ${ADDITIONAL_COMPILE_FLAG}")
51+
endforeach()
4652
configure_file(
4753
${CMAKE_SOURCE_DIR}/dash/scripts/dashcc/dashcxx.in
4854
${CMAKE_BINARY_DIR}/bin/dash-mpicxx

dart-impl/base/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ target_link_libraries(
112112
# Compile flags
113113
set_target_properties(
114114
${DASH_DART_BASE_LIBRARY} PROPERTIES
115-
COMPILE_FLAGS ${ADDITIONAL_COMPILE_FLAGS}
115+
COMPILE_FLAGS "${ADDITIONAL_COMPILE_FLAGS}"
116116
C_STANDARD ${DART_C_STD_PREFERED}
117117
C_STANDARD_REQUIRED ON
118118
POSITION_INDEPENDENT_CODE TRUE

dart-impl/mpi/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ endif()
213213
# Compile flags
214214
set_target_properties(
215215
${DASH_DART_IMPL_MPI_LIBRARY} PROPERTIES
216-
COMPILE_FLAGS ${ADDITIONAL_COMPILE_FLAGS_STR}
216+
COMPILE_FLAGS "${ADDITIONAL_COMPILE_FLAGS_STR}"
217217
C_STANDARD ${DART_C_STD_PREFERED}
218218
C_STANDARD_REQUIRED ON
219219
)

dart-impl/mpi/src/dart_communication.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ static dart_ret_t put_shared_mem(
149149
size_t nelem,
150150
dart_datatype_t dtype)
151151
{
152-
DART_LOG_DEBUG("dart_get: using shared memory window in segment %d enabled",
152+
DART_LOG_DEBUG("dart_put: using shared memory window in segment %d enabled",
153153
seginfo->segid);
154154
dart_team_unit_t luid = team_data->sharedmem_tab[unitid.id];
155155
char * baseptr = seginfo->baseptr[luid.id];
156156

157157
baseptr += offset;
158158
DART_LOG_DEBUG(
159-
"dart_get: memcpy %zu bytes", nelem * dart__mpi__datatype_sizeof(dtype));
159+
"dart_put: memcpy %zu bytes", nelem * dart__mpi__datatype_sizeof(dtype));
160160
memcpy(baseptr, src, nelem * dart__mpi__datatype_sizeof(dtype));
161161
return DART_OK;
162162
}

dart-impl/shmem/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ target_link_libraries(
6666

6767
set_target_properties(
6868
${DASH_DART_IMPL_SHMEM_LIBRARY} PROPERTIES
69-
COMPILE_FLAGS ${ADDITIONAL_COMPILE_FLAGS}
69+
COMPILE_FLAGS "${ADDITIONAL_COMPILE_FLAGS}"
7070
)
7171

7272
DeployLibrary(${DASH_DART_IMPL_SHMEM_LIBRARY})

dash/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ foreach (dart_variant ${DART_IMPLEMENTATIONS_LIST})
338338
)
339339
set_target_properties(
340340
${DASH_LIBRARY} PROPERTIES
341-
CXX_STANDARD ${DASH_CXX_STD_PREFERED}
341+
CXX_STANDARD "${DASH_CXX_STD_PREFERED}"
342342
CXX_STANDARD_REQUIRED ON
343343
)
344344

dash/include/dash/io/hdf5/StorageDriver.h

+34-5
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,13 @@ class StoreHDF {
544544
}
545545

546546
/**
547-
* Convert a dash pattern into a hdf5 pattern in form of a list of hdf5 slabs.
547+
* Convert a dash pattern into a hdf5 pattern in form of a list of hdf5 slabs and
548+
* is used for Patterns supporting underfilled blocks
548549
*/
549-
template <dim_t ndim, MemArrange Arr, typename index_t>
550-
const static inline std::vector<hdf5_hyperslab_spec<ndim>>
551-
/// The dash pattern to convert to hdf5 slabs
552-
_get_hdf_slabs(const dash::Pattern<ndim, Arr, index_t>& pattern) {
550+
template <typename PatternT>
551+
const static inline std::vector<hdf5_hyperslab_spec<PatternT::ndim()>>
552+
_get_hdf_slabs_with_underfilled(const PatternT& pattern) {
553+
static constexpr auto ndim = PatternT::ndim();
553554
std::vector<hdf5_hyperslab_spec<ndim>> specs_hyperslab;
554555
std::vector<dim_t> dimensions;
555556

@@ -575,9 +576,37 @@ class StoreHDF {
575576
return specs_hyperslab;
576577
}
577578

579+
/**
580+
* Convert a dash pattern into a hdf5 pattern in form of a list of hdf5 slabs.
581+
* Spezialization for BlockPattern
582+
*/
583+
template <dim_t ndim, MemArrange Arr, typename index_t>
584+
const static inline std::vector<hdf5_hyperslab_spec<ndim>>
585+
/// The dash pattern to convert to hdf5 slabs
586+
_get_hdf_slabs(const dash::Pattern<ndim, Arr, index_t>& pattern) {
587+
588+
return _get_hdf_slabs_with_underfilled(pattern);
589+
}
590+
591+
/**
592+
* Convert a dash pattern into a hdf5 pattern in form of a list of hdf5 slabs.
593+
* Spezialization for TilePattern
594+
*/
595+
template <dim_t ndim, MemArrange Arr, typename index_t>
596+
const static inline std::vector<hdf5_hyperslab_spec<ndim>>
597+
/// The dash pattern to convert to hdf5 slabs
598+
_get_hdf_slabs(const dash::TilePattern<ndim, Arr, index_t>& pattern) {
599+
600+
return _get_hdf_slabs_with_underfilled(pattern);
601+
}
602+
603+
/**
604+
* Convert a dash pattern into a hdf5 pattern in form of a list of hdf5 slabs.
605+
*/
578606
template <class pattern_t>
579607
const static inline std::vector<hdf5_hyperslab_spec<pattern_t::ndim()>>
580608
_get_hdf_slabs(const pattern_t& pattern) {
609+
581610
return std::vector<hdf5_hyperslab_spec<pattern_t::ndim()>>(
582611
1, _get_hdf_slab_body(pattern, {}));
583612
}

dash/include/dash/pattern/TilePattern.h

+50-6
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,7 @@ class TilePattern
12401240
"unit:", unit,
12411241
"lblock_idx:", local_block_index,
12421242
"lblockspec:", _local_blockspec.extents());
1243+
12431244
// Local block index to local block coords:
12441245
auto l_block_coords = _local_blockspec.coords(local_block_index);
12451246
auto unit_ts_coords = _teamspec.coords(unit);
@@ -1248,10 +1249,20 @@ class TilePattern
12481249
std::array<size_type, NumDimensions> extents{};
12491250
for (auto d = 0; d < NumDimensions; ++d) {
12501251
auto blocksize_d = _blocksize_spec.extent(d);
1251-
auto nunits_d = _teamspec.extent(d);
1252+
12521253
// Block offsets are lobal coordinates of first block element:
1254+
auto nunits_d = _teamspec.extent(d);
12531255
offsets[d] = ((l_block_coords[d] * nunits_d) + unit_ts_coords[d]) *
12541256
blocksize_d;
1257+
// checks if the local block is the last one in this dimension
1258+
auto num_blocks_d =_local_blockspec.extent(d);
1259+
if(l_block_coords[d] == (num_blocks_d - 1)){
1260+
size_type remaining = local_extent(d) % blocksize_d;
1261+
// if block is underfilled the extent will be decreased
1262+
if(remaining > 0) {
1263+
blocksize_d = remaining;
1264+
}
1265+
}
12551266
extents[d] = blocksize_d;
12561267
}
12571268
ViewSpec_t block_vs(offsets, extents);
@@ -1484,6 +1495,26 @@ class TilePattern
14841495
return NumDimensions;
14851496
}
14861497

1498+
/**
1499+
* Number of elements missing in the overflow block of given dimension
1500+
* compared to the regular blocksize (\see blocksize(d)), with
1501+
* 0 <= \c underfilled_blocksize(d) < blocksize(d).
1502+
*/
1503+
SizeType underfilled_blocksize(dim_t dimension) const
1504+
{
1505+
// Underflow blocksize = regular blocksize - overflow blocksize:
1506+
auto ovf_blocksize = _memory_layout.extent(dimension) %
1507+
blocksize(dimension);
1508+
1509+
if (ovf_blocksize == 0) {
1510+
return 0;
1511+
}
1512+
1513+
DASH_LOG_DEBUG_VAR("TilePattern.underfilled_blocksize", ovf_blocksize);
1514+
auto reg_blocksize = blocksize(dimension);
1515+
return reg_blocksize - ovf_blocksize;
1516+
}
1517+
14871518
private:
14881519

14891520
TilePattern(const PatternArguments_t & arguments)
@@ -1543,11 +1574,7 @@ class TilePattern
15431574
extent_d, // size of range (extent)
15441575
units_d // number of blocks (units)
15451576
);
1546-
DASH_ASSERT_EQ(0, extent_d % blocksize_d,
1547-
"TilePattern requires balanced block sizes: " <<
1548-
"extent " << extent_d << " is no multiple of " <<
1549-
"block size" << blocksize_d << " in " <<
1550-
"dimension " << d);
1577+
15511578
s_blocks[d] = blocksize_d;
15521579
}
15531580
DASH_LOG_TRACE_VAR("TilePattern.init_blocksizespec >", s_blocks);
@@ -1628,6 +1655,7 @@ class TilePattern
16281655
l_blocks[d] = num_l_blocks_d;
16291656
}
16301657
DASH_LOG_TRACE_VAR("TilePattern.init_local_blockspec >", l_blocks);
1658+
DASH_LOG_DEBUG_VAR("TilePattern.init_local_extents >", initialize_local_extents(unit_id));
16311659
return BlockSpec_t(l_blocks);
16321660
}
16331661

@@ -1698,9 +1726,25 @@ class TilePattern
16981726
if (num_odd_blocks_d > unit_ts_coords[d]) {
16991727
++num_l_blocks_d;
17001728
}
1729+
1730+
// Coordinate of this unit id in teamspec in dimension:
1731+
auto unit_ts_coord = unit_ts_coords[d];
17011732
// Possibly there are more blocks than units in dimension and no
17021733
// block left for this unit. Local extent in d then becomes 0.
17031734
l_extents[d] = num_l_blocks_d * blocksize_d;
1735+
// Unit id assigned to the last block in dimension:
1736+
team_unit_t last_block_unit_d((num_blocks_d % num_units_d == 0)
1737+
? num_units_d - 1
1738+
: (num_blocks_d % num_units_d) - 1);
1739+
1740+
if(unit_ts_coord == last_block_unit_d) {
1741+
// If the last block in the dimension is underfilled and
1742+
// assigned to the local unit, subtract the missing extent:
1743+
auto undfill_blocksize_d = underfilled_blocksize(d);
1744+
DASH_LOG_TRACE_VAR("TilePattern.init_local_extents",
1745+
undfill_blocksize_d);
1746+
l_extents[d] -= undfill_blocksize_d;
1747+
}
17041748
}
17051749
DASH_LOG_DEBUG_VAR("TilePattern.init_local_extents >", l_extents);
17061750
return l_extents;

dash/test/io/HDF5MatrixTest.cc

+68-13
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,61 @@ TEST_F(HDF5MatrixTest, UnderfilledPattern) {
277277
verify_matrix(matrix_b, 1);
278278
}
279279

280+
template<typename MatrixT>
281+
void print_matrix(const MatrixT& matrix) {
282+
using namespace std;
283+
dash::barrier();
284+
if(!dash::myid()) {
285+
auto rows = matrix.extent(0);
286+
auto cols = matrix.extent(1);
287+
cout << fixed;
288+
cout.precision(4);
289+
cout << "Matrix:" << endl;
290+
for (auto r = 0; r < rows; ++r) {
291+
for (auto c = 0; c < cols; ++c) {
292+
auto lindex = matrix.pattern().local_index({r,c});
293+
cout << " " << setw(3) << (double) matrix[r][c] << "(" << lindex.unit << "," << lindex.index << ")";
294+
}
295+
cout << endl;
296+
}
297+
}
298+
dash::barrier();
299+
}
300+
301+
/**
302+
* Allocate a matrix with extents that cannot fit into full blocks
303+
* TilePattern
304+
*/
305+
TEST_F(HDF5MatrixTest, UnderfilledPatternTile) {
306+
using Matrix_t = dash::Matrix<double, 2>;
307+
308+
auto team_size = dash::Team::All().size();
309+
310+
int ext_x = 5 * team_size + 1;
311+
int ext_y = 10 * team_size;
312+
313+
double test_value = dash::myid()+1;
314+
315+
LOG_MESSAGE("Matrix extent (%i,%i)", ext_x, ext_y);
316+
317+
auto size_spec = dash::SizeSpec<2>(ext_x, ext_y);
318+
319+
{
320+
Matrix_t matrix_a(size_spec);
321+
//dash::fill(matrix_a.begin(), matrix_a.end(), test_value);
322+
fill_matrix(matrix_a, test_value);
323+
dio::OutputStream os(_filename);
324+
os << dio::dataset(_dataset) << matrix_a;
325+
}
326+
327+
Matrix_t matrix_b(size_spec);
328+
dio::InputStream is(_filename);
329+
is >> dio::dataset(_dataset) >> matrix_b;
330+
dash::barrier();
331+
332+
verify_matrix(matrix_b, test_value);
333+
}
334+
280335
TEST_F(HDF5MatrixTest, UnderfilledPatMultiple) {
281336
typedef dash::Pattern<2, dash::ROW_MAJOR> pattern_t;
282337
typedef typename pattern_t::index_type index_t;
@@ -519,23 +574,23 @@ TEST_F(HDF5MatrixTest, DashView)
519574
int secret = 0;
520575
dash::NArray<int,2> matrix2d(100,80);
521576
fill_matrix(matrix2d, secret);
522-
577+
523578
{
524579
auto output_view = dash::sub(0,5, matrix2d);
525-
580+
526581
// TODO: Does not work
527582
dash::fill(dash::begin(output_view), dash::end(output_view), 5);
528583

529584
// Store View
530585
dio::OutputStream os(_filename);
531586
os << output_view;
532587
}
533-
588+
534589
// Load data into a existing view
535590
auto input_view = dash::sub(0,10, matrix2d);
536591
dio::InputStream is(_filename);
537592
is >> input_view;
538-
593+
539594
// Load data into new matrix
540595
dash::Array<int> matrix1d;
541596
is >> matrix1d;
@@ -548,20 +603,20 @@ TEST_F(HDF5MatrixTest, HDFView)
548603
int secret = 0;
549604
dash::NArray<int,3> matrix3d(10,8,5);
550605
fill_matrix(matrix3d, secret);
551-
606+
552607
{
553608
dio::OutputStream os(_filename);
554609
os << matrix3d;
555610
}
556-
611+
557612
// Load subset of data into new matrix
558613
dash::NArray<int,3> sub_matrix3d;
559614
auto position = std::array<size_t,3>({2,4,1}); // top left corner of desired block
560615
auto extent = std::array<size_t,3>({4,2,1}); // extents of block
561616
dio::InputStream is(_filename);
562617
is >> dash::block(position, extent)
563618
>> sub_matrix3d;
564-
619+
565620
// post condition
566621
// sub_matrix3d has extent {4,2,1}
567622
}
@@ -571,29 +626,29 @@ TEST_F(HDF5MatrixTest, WriteCorresponding)
571626
int secret = 0;
572627
dash::NArray<int,3> matrix3d(10,8,5);
573628
fill_matrix(matrix3d, secret);
574-
629+
575630
{
576631
dio::OutputStream os(_filename);
577632
os << matrix3d;
578633
}
579-
634+
580635
auto view = matrix3d.col(1);
581636
// modify view
582637
dash::fill(view.begin(), view.end(), 0);
583-
638+
584639
// write slice back
585640
dio::OutputStream os(_filename, dio::DeviceMode::App);
586641
is >> dio::modify_dataset()
587642
>> dash::block(position, extent)
588643
>> sub_matrix3d;
589-
644+
590645
// post condition
591646
// slice in file is updated
592647
dash::NArray<int,3> new_matrix3d(10,8,5);
593-
648+
594649
dio::InputStream is(_filename);
595650
is << new_matrix3d;
596-
651+
597652
auto view = new_matrix3d.col(1);
598653
dash::for_each(view.begin(), view.end(), [](int & el){ASSERT_EQ_U(0, el)});
599654
}

0 commit comments

Comments
 (0)