1 /* selector with default/naive Simgrid algorithms. These should not be trusted for performance evaluations */
3 /* Copyright (c) 2009-2021. 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];
43 for (int i = 0; i < size; i++) {
44 if(recvcounts[i]!=recvcounts[0]){
49 count += recvcounts[i];
52 return reduce_scatter__ompi(sendbuf, recvbuf, recvcounts, datatype, op, comm);
54 unsigned char* tmpbuf = smpi_get_tmp_sendbuffer(count * datatype->get_extent());
56 int ret = reduce__default(sendbuf, tmpbuf, count, datatype, op, 0, comm);
58 ret = colls::scatterv(tmpbuf, recvcounts, displs, datatype, recvbuf, recvcounts[rank], datatype, 0, comm);
60 smpi_free_tmp_buffer(tmpbuf);
65 int allgather__default(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
66 void *recvbuf,int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
69 colls::iallgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, &request);
70 return Request::wait(&request, MPI_STATUS_IGNORE);
73 int allgatherv__default(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf,
74 const int *recvcounts, const int *displs, MPI_Datatype recvtype, MPI_Comm comm)
77 colls::iallgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm, &request, 0);
78 MPI_Request* requests = request->get_nbc_requests();
79 int count = request->get_nbc_requests_size();
80 Request::waitall(count, requests, MPI_STATUS_IGNORE);
81 for (int other = 0; other < count; other++) {
82 Request::unref(&requests[other]);
85 Request::unref(&request);
89 int scatter__default(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
90 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
93 colls::iscatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, &request, 0);
94 return Request::wait(&request, MPI_STATUS_IGNORE);
97 int reduce__default(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root,
100 //non commutative case, use a working algo from openmpi
101 if (op != MPI_OP_NULL && (datatype->flags() & DT_FLAG_DERIVED || not op->is_commutative())) {
102 return reduce__ompi_basic_linear(sendbuf, recvbuf, count, datatype, op, root, comm);
105 colls::ireduce(sendbuf, recvbuf, count, datatype, op, root, comm, &request, 0);
106 return Request::wait(&request, MPI_STATUS_IGNORE);
109 int allreduce__default(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
111 //FIXME: have mpi_ireduce and iallreduce handle derived datatypes correctly
112 if(datatype->flags() & DT_FLAG_DERIVED)
113 return allreduce__ompi(sendbuf, recvbuf, count, datatype, op, comm);
115 ret = reduce__default(sendbuf, recvbuf, count, datatype, op, 0, comm);
117 ret = bcast__default(recvbuf, count, datatype, 0, comm);
121 int alltoall__default(const void *sbuf, int scount, MPI_Datatype sdtype, void* rbuf, int rcount, MPI_Datatype rdtype, MPI_Comm comm)
123 return alltoall__ompi(sbuf, scount, sdtype, rbuf, rcount, rdtype, comm);
126 int alltoallv__default(const void *sendbuf, const int *sendcounts, const int *senddisps, MPI_Datatype sendtype,
127 void *recvbuf, const int *recvcounts, const int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
130 colls::ialltoallv(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype, comm, &request,
132 return Request::wait(&request, MPI_STATUS_IGNORE);