Skip to content
Merged
Changes from 2 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
17 changes: 14 additions & 3 deletions cpp/src/cluster/detail/kmeans_mg.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,20 @@ void initKMeansPlusPlus(const raft::resources& handle,
// X which will be used as the initial centroid for kmeans++
// 1.3 - Communicate the initial centroid chosen by rank-r' to all other
// ranks
std::mt19937 gen(params.rng_state.seed);
std::uniform_int_distribution<> dis(0, n_rank - 1);
int rp = dis(gen);
// Choose rp on rank 0 and broadcast to all ranks to guarantee agreement
int rp = 0;
if (my_rank == KMEANS_COMM_ROOT) {
std::mt19937 gen(params.rng_state.seed);
std::uniform_int_distribution<> dis(0, n_rank - 1);
rp = dis(gen);
}
{
rmm::device_scalar<int> rp_d(stream);
raft::copy(rp_d.data(), &rp, 1, stream);
comm.bcast<int>(rp_d.data(), 1, /*root=*/KMEANS_COMM_ROOT, stream);
raft::copy(&rp, rp_d.data(), 1, stream);
raft::resource::sync_stream(handle);
}

// buffer to flag the sample that is chosen as initial centroids
std::vector<std::uint8_t> h_isSampleCentroid(n_samples);
Expand Down
Loading