1 /* selector with default/naive SimGrid algorithms. These should not be trusted for performance evaluations */
3 /* Copyright (c) 2009-2023. The SimGrid Team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "colls_private.hpp"
9 #include "src/smpi/include/smpi_actor.hpp"
11 namespace simgrid::smpi {
13 int bcast__default(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
15 return bcast__binomial_tree(buf, count, datatype, root, comm);
18 int barrier__default(MPI_Comm comm)
20 return barrier__ompi_basic_linear(comm);
24 int gather__default(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
25 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
28 colls::igather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, &request, 0);
29 return Request::wait(&request, MPI_STATUS_IGNORE);
32 int reduce_scatter__default(const void *sendbuf, void *recvbuf, const int *recvcounts, MPI_Datatype datatype, MPI_Op op,
35 int rank = comm->rank();
37 /* arbitrarily choose root as rank 0 */
38 int size = comm->size();
40 int* displs = new int[size];
42 for (int i = 0; i < size; i++) {
43 if(recvcounts[i]!=recvcounts[0]){
48 count += recvcounts[i];
52 return reduce_scatter__mpich(sendbuf, recvbuf, recvcounts, datatype, op, comm);
55 unsigned char* tmpbuf = smpi_get_tmp_sendbuffer(count * datatype->get_extent());
57 int ret = reduce__default(sendbuf, tmpbuf, count, datatype, op, 0, comm);
59 ret = colls::scatterv(tmpbuf, recvcounts, displs, datatype, recvbuf, recvcounts[rank], datatype, 0, comm);
61 smpi_free_tmp_buffer(tmpbuf);
66 int allgather__default(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
67 void *recvbuf,int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
70 colls::iallgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, &request);
71 return Request::wait(&request, MPI_STATUS_IGNORE);
74 int allgatherv__default(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf,
75 const int *recvcounts, const int *displs, MPI_Datatype recvtype, MPI_Comm comm)
78 colls::iallgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm, &request, 0);
79 auto requests = request->get_nbc_requests();
80 Request::waitall(requests.size(), requests.data(), MPI_STATUS_IGNORE);
81 for(auto& req: requests)
83 Request::unref(&request);
87 int scatter__default(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
88 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
91 colls::iscatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, &request, 0);
92 return Request::wait(&request, MPI_STATUS_IGNORE);
95 int reduce__default(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root,
98 //non commutative case, use a working algo from openmpi
99 if (op != MPI_OP_NULL && (datatype->flags() & DT_FLAG_DERIVED || not op->is_commutative())) {
100 return reduce__ompi_basic_linear(sendbuf, recvbuf, count, datatype, op, root, comm);
103 colls::ireduce(sendbuf, recvbuf, count, datatype, op, root, comm, &request, 0);
104 return Request::wait(&request, MPI_STATUS_IGNORE);
107 int allreduce__default(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
109 //FIXME: have mpi_ireduce and iallreduce handle derived datatypes correctly
110 if(datatype->flags() & DT_FLAG_DERIVED)
111 return allreduce__ompi(sendbuf, recvbuf, count, datatype, op, comm);
113 ret = reduce__default(sendbuf, recvbuf, count, datatype, op, 0, comm);
115 ret = bcast__default(recvbuf, count, datatype, 0, comm);
119 int alltoall__default(const void *sbuf, int scount, MPI_Datatype sdtype, void* rbuf, int rcount, MPI_Datatype rdtype, MPI_Comm comm)
121 return alltoall__ompi(sbuf, scount, sdtype, rbuf, rcount, rdtype, comm);
124 int alltoallv__default(const void *sendbuf, const int *sendcounts, const int *senddisps, MPI_Datatype sendtype,
125 void *recvbuf, const int *recvcounts, const int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
128 colls::ialltoallv(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype, comm, &request,
130 return Request::wait(&request, MPI_STATUS_IGNORE);
133 } // namespace simgrid::smpi