1 /* selector with default/naive Simgrid algorithms. These should not be trusted for performance evaluations */
3 /* Copyright (c) 2009-2020. 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"
14 int bcast__default(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
16 return bcast__binomial_tree(buf, count, datatype, root, comm);
19 int barrier__default(MPI_Comm comm)
21 return barrier__ompi_basic_linear(comm);
25 int gather__default(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
26 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
29 colls::igather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, &request, 0);
30 return Request::wait(&request, MPI_STATUS_IGNORE);
33 int reduce_scatter__default(const void *sendbuf, void *recvbuf, const int *recvcounts, MPI_Datatype datatype, MPI_Op op,
36 int rank = comm->rank();
38 /* arbitrarily choose root as rank 0 */
39 int size = comm->size();
41 int* displs = new int[size];
42 for (int i = 0; i < size; i++) {
44 count += recvcounts[i];
46 unsigned char* tmpbuf = smpi_get_tmp_sendbuffer(count * datatype->get_extent());
48 int ret = reduce__default(sendbuf, tmpbuf, count, datatype, op, 0, comm);
50 ret = colls::scatterv(tmpbuf, recvcounts, displs, datatype, recvbuf, recvcounts[rank], datatype, 0, comm);
52 smpi_free_tmp_buffer(tmpbuf);
57 int allgather__default(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
58 void *recvbuf,int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
61 colls::iallgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, &request);
62 return Request::wait(&request, MPI_STATUS_IGNORE);
65 int allgatherv__default(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf,
66 const int *recvcounts, const int *displs, MPI_Datatype recvtype, MPI_Comm comm)
69 colls::iallgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm, &request, 0);
70 MPI_Request* requests = request->get_nbc_requests();
71 int count = request->get_nbc_requests_size();
72 Request::waitall(count, requests, MPI_STATUS_IGNORE);
73 for (int other = 0; other < count; other++) {
74 Request::unref(&requests[other]);
77 Request::unref(&request);
81 int scatter__default(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
82 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
85 colls::iscatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, &request, 0);
86 return Request::wait(&request, MPI_STATUS_IGNORE);
89 int reduce__default(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root,
92 //non commutative case, use a working algo from openmpi
93 if (op != MPI_OP_NULL && (datatype->flags() & DT_FLAG_DERIVED || not op->is_commutative())) {
94 return reduce__ompi_basic_linear(sendbuf, recvbuf, count, datatype, op, root, comm);
97 colls::ireduce(sendbuf, recvbuf, count, datatype, op, root, comm, &request, 0);
98 return Request::wait(&request, MPI_STATUS_IGNORE);
101 int allreduce__default(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
103 //FIXME: have mpi_ireduce and iallreduce handle derived datatypes correctly
104 if(datatype->flags() & DT_FLAG_DERIVED)
105 return allreduce__ompi(sendbuf, recvbuf, count, datatype, op, comm);
107 ret = reduce__default(sendbuf, recvbuf, count, datatype, op, 0, comm);
109 ret = bcast__default(recvbuf, count, datatype, 0, comm);
113 int alltoall__default(const void *sbuf, int scount, MPI_Datatype sdtype, void* rbuf, int rcount, MPI_Datatype rdtype, MPI_Comm comm)
115 return alltoall__ompi(sbuf, scount, sdtype, rbuf, rcount, rdtype, comm);
118 int alltoallv__default(const void *sendbuf, const int *sendcounts, const int *senddisps, MPI_Datatype sendtype,
119 void *recvbuf, const int *recvcounts, const int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
122 colls::ialltoallv(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype, comm, &request,
124 return Request::wait(&request, MPI_STATUS_IGNORE);