Skip to content

Commit

Permalink
incorporate review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mschimek committed Jul 10, 2024
1 parent 40b508f commit 458e860
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 164 deletions.
71 changes: 58 additions & 13 deletions examples/usage/allgather_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "helpers_for_examples.hpp"
#include "kamping/checking_casts.hpp"
#include "kamping/collectives/allgather.hpp"
#include "kamping/collectives/alltoall.hpp"
#include "kamping/communicator.hpp"
#include "kamping/data_buffer.hpp"
#include "kamping/environment.hpp"
Expand All @@ -30,21 +29,67 @@ int main() {
using namespace kamping;
kamping::Environment e;
kamping::Communicator comm;
std::vector<int> input(comm.size(), comm.rank_signed());
// std::vector<int> input(comm.size(), comm.rank_signed());

{ // Basic form: Provide a send buffer and let KaMPIng allocate the receive buffer.
auto output = comm.allgather(send_buf(input));
print_result_on_root(output, comm);
}
//{ // Basic form: Provide a send buffer and let KaMPIng allocate the receive buffer.
// auto output = comm.allgather(send_buf(input));
// print_result_on_root(output, comm);
//}

// print_on_root("------", comm);

print_on_root("------", comm);
//{ // We can also send only parts of the input and specify an explicit receive buffer.
// std::vector<int> output;

{ // We can also send only parts of the input and specify an explicit receive buffer.
std::vector<int> output;
// // this can also be achieved with `kamping::Span`
// comm.allgather(send_buf(Span(input.begin(), 2)), recv_buf<resize_to_fit>(output));
// print_result_on_root(output, comm);
// return 0;
//}

// this can also be achieved with `kamping::Span`
comm.allgather(send_buf(Span(input.begin(), 2)), recv_buf<resize_to_fit>(output));
print_result_on_root(output, comm);
return 0;
MPI_Comm mpi_graph_comm;
int in_degree = -1, out_degree = -1;
std::vector<int> input{comm.rank_signed()};
std::vector<int> recv_buf(10, -1);
int send_count = -1, recv_count = -1;
std::vector<int> in_ranks, out_ranks;
if (comm.rank() == 0) {
in_degree = 0;
out_degree = 0;
send_count = 1;
recv_count = 1;
} else if (comm.rank() == 1) {
in_degree = 0;
out_degree = 1;
out_ranks.push_back(2);
send_count = 1;
recv_count = 1;
} else if (comm.rank() == 2) {
in_degree = 1;
out_degree = 1;
in_ranks.push_back(1);
out_ranks.push_back(3);
send_count = 1;
recv_count = 1;
} else if (comm.rank() == 3) {
in_degree = 1;
out_degree = 0;
in_ranks.push_back(2);
send_count = 1;
recv_count = 1;
}
MPI_Dist_graph_create_adjacent(
comm.mpi_communicator(),
in_degree,
in_ranks.data(),
MPI_UNWEIGHTED,
out_degree,
out_ranks.data(),
MPI_UNWEIGHTED,
MPI_INFO_NULL,
false,
&mpi_graph_comm
);

MPI_Neighbor_alltoall(input.data(), send_count, MPI_INT, recv_buf.data(), recv_count, MPI_INT, mpi_graph_comm);
}
15 changes: 7 additions & 8 deletions include/kamping/collectives/neighborhood/alltoall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@

/// @brief Wrapper for \c MPI_Neighbor_alltoall.
///
/// This wrapper for \c MPI_Neighbor_alltoall sends the same amount of data from a rank i to each of its neighbour j for
/// which an edge (i,j) in the communication graph exists. The following buffers are required:
/// @todo check again once the concrete semantics (potential differing number of send/recv counts) of
/// MPI_Neighbor_alltoall has been clarified. This wrapper for \c MPI_Neighbor_alltoall sends the same amount of data
/// from a rank i to each of its neighbour j for which an edge (i,j) in the communication graph exists. The following
/// buffers are required:
/// - \ref kamping::send_buf() containing the data that is sent to each neighbor. This buffer has to be divisible by the
/// size of the communicator unless a send_count or a send_type is explicitly given as parameter.
/// out degree unless a send_count or a send_type is explicitly given as parameter.
///
/// The following parameters are optional:
/// - \ref kamping::send_count() specifying how many elements are sent. If
/// omitted, the size of send buffer divided by number of neighbors is used.
/// omitted, the size of send buffer divided by number of outgoing neighbors is used.
/// This has to be the same on all ranks.
/// This parameter is mandatory if \ref kamping::send_type() is given.
///
Expand All @@ -59,17 +61,14 @@
/// This parameter is mandatory if \ref kamping::recv_type() is given.
///
/// - \ref kamping::recv_buf() specifying a buffer for the output. A buffer of at least
/// `recv_count * communicator size` is required.
/// `recv_count * in degree` is required.
///
/// - \ref kamping::send_type() specifying the \c MPI datatype to use as send type. If omitted, the \c MPI datatype is
/// derived automatically based on send_buf's underlying \c value_type.
///
/// - \ref kamping::recv_type() specifying the \c MPI datatype to use as recv type. If omitted, the \c MPI datatype is
/// derived automatically based on recv_buf's underlying \c value_type.
///
/// Inplace alltoall is supported by passing send_recv_buf as parameter. This changes the requirements for the other
/// parameters, see \ref Communicator::alltoall_inplace.
///
/// @tparam Args Automatically deduced template parameters.
/// @param args All required and any number of the optional buffers described above.
/// @return Result type wrapping the output parameters to be returned by value.
Expand Down
Loading

0 comments on commit 458e860

Please sign in to comment.