Skip to content

Commit

Permalink
the distribute function works when the error checking is disabled fro…
Browse files Browse the repository at this point in the history
…m mdspan, very likely due to the assignment to the default constructed subspan when the vector of subspans is created
  • Loading branch information
hamsteri15 committed Jan 19, 2024
1 parent 8d7b6f6 commit aecffcd
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 50 deletions.
9 changes: 4 additions & 5 deletions include/bits/communication/gather.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ template <class Container>
static inline Container all_gather(const Container& local_data,
MPI_Comm communicator = MPI_COMM_WORLD) {

int rank = mpi::get_rank(communicator);
int size = mpi::comm_size(communicator);
size_t size = size_t(mpi::comm_size(communicator));

// Determine the size of data on each process
int localSize = local_data.size();
size_t localSize = local_data.size();
std::vector<int> recvCounts(size);

// Calculate the total size of data on all processes
Expand All @@ -46,7 +45,7 @@ static inline Container all_gather(const Container& local_data,

// Determine displacements for the gathered data
std::vector<int> displacements(size, 0);
for (int i = 1; i < size; ++i) {
for (size_t i = 1; i < size; ++i) {
displacements[i] = displacements[i - 1] + recvCounts[i - 1];
}

Expand All @@ -57,7 +56,7 @@ static inline Container all_gather(const Container& local_data,

// Use MPI_Allgatherv to send the gathered data to all processes
mpi::all_gatherv(local_data.data(),
localSize,
int(localSize),
temp(),
global_data.data(),
recvCounts.data(),
Expand Down
30 changes: 30 additions & 0 deletions include/bits/communication/topology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,36 @@ std::ostream& operator<<(std::ostream& os, const Topology<L>& topo) {

os << "Domain: " << topo.m_domain << std::endl;
for (auto e : topo.get_boxes()) { os << e << std::endl; }

os << "Topology: " << std::endl;
if constexpr (L < 3) {

std::vector<int> v(flat_size(topo.get_domain().get_extent()), 0);

auto span = make_span(v, topo.get_domain().get_extent());
auto boxes = topo.get_boxes();

for (auto box : boxes) {
auto subspan = make_subspan(span, box.box.m_begin, box.box.m_end);
for_each(subspan, [=](auto& e) { e = box.rank; });
}

if constexpr (rank(span) == 1) {
for (size_t i = 0; i < span.extent(0); ++i) {
os << span(i) << " ";
}
os << std::endl;
}
else if constexpr (rank(span) == 2) {
for (size_t i = 0; i < span.extent(0); ++i) {
for (size_t j = 0; j < span.extent(1); ++j) {
os << span(i, j) << " ";
}
os << std::endl;
}
}
}

return os;
}

Expand Down
4 changes: 4 additions & 0 deletions include/bits/core/mdspan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ static constexpr auto make_span(const Container& c, Dims dims) {
return span<value_type, rank(ext)>(std::data(c), ext);
}





} // namespace jada
8 changes: 5 additions & 3 deletions include/bits/core/mdspan_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1725,13 +1725,13 @@ struct __no_unique_address_emulation<
// If the type isn't trivially destructible, its destructor
// won't be called at the right time, so don't use this
// specialization
_MDSPAN_TRAIT(is_trivially_destructible, _T)>> :
_MDSPAN_TRAIT(is_trivially_destructible, _T)>> :
#ifdef _MDSPAN_COMPILER_MSVC
// MSVC doesn't allow you to access public static member functions of a type
// when you *happen* to privately inherit from that type.
protected
#else
// But we still want this to be private if possible so that we don't accidentally
// But we still want this to be private if possible so that we don't accidentally
// access members of _T directly rather than calling __ref() first, which wouldn't
// work if _T happens to be stateful and thus we're using the unspecialized definition
// of __no_unique_address_emulation above.
Expand Down Expand Up @@ -3613,7 +3613,7 @@ struct __extents_to_partially_static_sizes;
template <class IndexType, size_t... ExtentsPack>
struct __extents_to_partially_static_sizes<::std::experimental::extents<IndexType, ExtentsPack...>> {
using type = detail::__partially_static_sizes<
typename ::std::experimental::extents<IndexType, ExtentsPack...>::index_type, size_t,
typename ::std::experimental::extents<IndexType, ExtentsPack...>::index_type, size_t,
ExtentsPack...>;
};

Expand Down Expand Up @@ -4286,6 +4286,7 @@ class layout_right::mapping {
* TODO: check precondition
* other.required_span_size() is a representable value of type index_type
*/

#ifndef __CUDA_ARCH__
size_t stride = 1;
for(rank_type r=__extents.rank(); r>0; r--) {
Expand All @@ -4294,6 +4295,7 @@ class layout_right::mapping {
stride *= __extents.extent(r-1);
}
#endif

}

MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED mapping& operator=(mapping const&) noexcept = default;
Expand Down
2 changes: 1 addition & 1 deletion test/test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ template <size_t Dir, class Span> void set_linear(Span s) {
e = T(ii);
};
for_each_indexed(s, op);

}
struct simpleDiff{
static constexpr size_t begin_padding = 1;
Expand Down
Loading

0 comments on commit aecffcd

Please sign in to comment.