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
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,15 @@
const unsigned int root_id=0,
const bool identical_sizes=false) const;

template <typename T, typename A>
template <typename T, typename A,
typename std::enable_if<StandardType<T>::is_fixed_type, int>::type = 0>
inline
void broadcast(std::vector<T,A> &data,
const unsigned int root_id=0,
const bool identical_sizes=false) const;

template <typename T, typename A,
typename std::enable_if<!StandardType<T>::is_fixed_type, int>::type = 0>
inline
void broadcast(std::vector<T,A> &data,
const unsigned int root_id=0,
Expand Down
35 changes: 34 additions & 1 deletion src/parallel/include/timpi/parallel_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,8 @@ inline void Communicator::broadcast (std::basic_string<T> & data,



template <typename T, typename A>
template <typename T, typename A,
typename std::enable_if<StandardType<T>::is_fixed_type, int>::type>
inline void Communicator::broadcast (std::vector<T,A> & data,
const unsigned int root_id,
const bool identical_sizes) const
Expand Down Expand Up @@ -1630,6 +1631,38 @@ inline void Communicator::broadcast (std::vector<T,A> & data,
StandardType<T>(data_ptr), root_id, this->get()));
}

template <typename T, typename A,
typename std::enable_if<!StandardType<T>::is_fixed_type, int>::type>
inline void Communicator::broadcast (std::vector<T,A> & data,
const unsigned int root_id,
const bool identical_sizes) const
{
if (this->size() == 1)
{
timpi_assert (!this->rank());
timpi_assert (!root_id);
return;
}

timpi_assert_less (root_id, this->size());
timpi_assert (this->verify(identical_sizes));

TIMPI_LOG_SCOPE("broadcast()", "Parallel");

std::size_t data_size = data.size();

if (identical_sizes)
timpi_assert(this->verify(data_size));
else
this->broadcast(data_size, root_id);

data.resize(data_size);

timpi_assert_less(root_id, this->size());

this->broadcast_packed_range((void *)(NULL), data.begin(), data.end(), (void *)(NULL), data.begin(), root_id);
}



template <typename T, typename A>
Expand Down
34 changes: 34 additions & 0 deletions test/dispatch_to_packed_unit.C
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,47 @@ Communicator *TestCommWorld;
}
}

void testContainerBroadcast()
{
std::vector<std::set<unsigned int>> vals;
const unsigned int my_rank = TestCommWorld->rank();
const std::size_t comm_size = TestCommWorld->size();

if (my_rank == 0)
{
vals.resize(comm_size + 1);
unsigned int counter = 1;
for (auto & val : vals)
{
for (unsigned int number = 0; number < counter; ++number)
val.insert(number);
++counter;
}
}
TestCommWorld->broadcast(vals);

const std::size_t vec_size = vals.size();
TIMPI_UNIT_ASSERT((comm_size + 1) == vec_size);

std::size_t counter = 1;
for (const auto & current_set : vals)
{
TIMPI_UNIT_ASSERT(current_set.size() == counter);
unsigned int number = 0;
for (auto elem : current_set)
TIMPI_UNIT_ASSERT(elem == number++);
++counter;
}
}


int main(int argc, const char * const * argv)
{
TIMPI::TIMPIInit init(argc, argv);
TestCommWorld = &init.comm();

testContainerAllGather();
testContainerBroadcast();

return 0;
}