1 /* selector with default/naive Simgrid algorithms. These should not be trusted for performance evaluations */
3 /* Copyright (c) 2009-2019. 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 Coll_bcast_default::bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
16 return Coll_bcast_binomial_tree::bcast(buf, count, datatype, root, comm);
19 int Coll_barrier_default::barrier(MPI_Comm comm)
21 return Coll_barrier_ompi_basic_linear::barrier(comm);
25 int Coll_gather_default::gather(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);
30 MPI_Request* requests = request->get_nbc_requests();
31 int count = request->get_nbc_requests_size();
32 Request::waitall(count, requests, MPI_STATUS_IGNORE);
33 for (int i = 0; i < count; i++) {
34 if(requests[i]!=MPI_REQUEST_NULL)
35 Request::unref(&requests[i]);
38 Request::unref(&request);
42 int Coll_reduce_scatter_default::reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op,
45 int rank = comm->rank();
47 /* arbitrarily choose root as rank 0 */
48 int size = comm->size();
50 int *displs = xbt_new(int, size);
51 for (int i = 0; i < size; i++) {
53 count += recvcounts[i];
55 void *tmpbuf = static_cast<void*>(smpi_get_tmp_sendbuffer(count*datatype->get_extent()));
57 int ret = Coll_reduce_default::reduce(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 Coll_allgather_default::allgather(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 MPI_Request* requests = request->get_nbc_requests();
72 int count = request->get_nbc_requests_size();
73 Request::waitall(count, requests, MPI_STATUS_IGNORE);
74 for (int other = 0; other < count; other++) {
75 Request::unref(&requests[other]);
78 Request::unref(&request);
82 int Coll_allgatherv_default::allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf,
83 int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
86 Colls::iallgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm, &request);
87 MPI_Request* requests = request->get_nbc_requests();
88 int count = request->get_nbc_requests_size();
89 Request::waitall(count, requests, MPI_STATUS_IGNORE);
90 for (int other = 0; other < count; other++) {
91 Request::unref(&requests[other]);
94 Request::unref(&request);
98 int Coll_scatter_default::scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
99 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
102 Colls::iscatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, &request);
103 MPI_Request* requests = request->get_nbc_requests();
104 int count = request->get_nbc_requests_size();
105 Request::waitall(count, requests, MPI_STATUS_IGNORE);
106 for (int dst = 0; dst < count; dst++) {
107 if(requests[dst]!=MPI_REQUEST_NULL)
108 Request::unref(&requests[dst]);
111 Request::unref(&request);
117 int Coll_reduce_default::reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root,
120 const int system_tag = COLL_TAG_REDUCE;
122 MPI_Aint dataext = 0;
124 char* sendtmpbuf = static_cast<char *>(sendbuf);
126 int rank = comm->rank();
127 int size = comm->size();
130 //non commutative case, use a working algo from openmpi
131 if (op != MPI_OP_NULL && not op->is_commutative()) {
132 return Coll_reduce_ompi_basic_linear::reduce(sendtmpbuf, recvbuf, count, datatype, op, root, comm);
135 if( sendbuf == MPI_IN_PLACE ) {
136 sendtmpbuf = static_cast<char *>(smpi_get_tmp_sendbuffer(count*datatype->get_extent()));
137 Datatype::copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
141 // Send buffer to root
142 Request::send(sendtmpbuf, count, datatype, root, system_tag, comm);
144 datatype->extent(&lb, &dataext);
145 // Local copy from root
146 if (sendtmpbuf != nullptr && recvbuf != nullptr)
147 Datatype::copy(sendtmpbuf, count, datatype, recvbuf, count, datatype);
148 // Receive buffers from senders
149 MPI_Request *requests = xbt_new(MPI_Request, size - 1);
150 void **tmpbufs = xbt_new(void *, size - 1);
152 for (int src = 0; src < size; src++) {
154 tmpbufs[index] = smpi_get_tmp_sendbuffer(count * dataext);
156 Request::irecv_init(tmpbufs[index], count, datatype, src, system_tag, comm);
160 // Wait for completion of irecv's.
161 Request::startall(size - 1, requests);
162 for (int src = 0; src < size - 1; src++) {
163 index = Request::waitany(size - 1, requests, MPI_STATUS_IGNORE);
164 XBT_DEBUG("finished waiting any request with index %d", index);
165 if(index == MPI_UNDEFINED) {
168 Request::unref(&requests[index]);
170 if(op) /* op can be MPI_OP_NULL that does nothing */
171 if(op!=MPI_OP_NULL) op->apply( tmpbufs[index], recvbuf, &count, datatype);
173 for(index = 0; index < size - 1; index++) {
174 smpi_free_tmp_buffer(tmpbufs[index]);
180 if( sendbuf == MPI_IN_PLACE ) {
181 smpi_free_tmp_buffer(sendtmpbuf);
186 int Coll_allreduce_default::allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
189 ret = Coll_reduce_default::reduce(sendbuf, recvbuf, count, datatype, op, 0, comm);
191 ret = Coll_bcast_default::bcast(recvbuf, count, datatype, 0, comm);
195 int Coll_alltoall_default::alltoall( void *sbuf, int scount, MPI_Datatype sdtype, void* rbuf, int rcount, MPI_Datatype rdtype, MPI_Comm comm)
197 return Coll_alltoall_ompi::alltoall(sbuf, scount, sdtype, rbuf, rcount, rdtype, comm);
202 int Coll_alltoallv_default::alltoallv(void *sendbuf, int *sendcounts, int *senddisps, MPI_Datatype sendtype,
203 void *recvbuf, int *recvcounts, int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
206 int err = Colls::ialltoallv(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype, comm, &request);
207 MPI_Request* requests = request->get_nbc_requests();
208 int count = request->get_nbc_requests_size();
209 XBT_DEBUG("<%d> wait for %d requests", comm->rank(), count);
210 Request::waitall(count, requests, MPI_STATUS_IGNORE);
211 for (int i = 0; i < count; i++) {
212 if(requests[i]!=MPI_REQUEST_NULL)
213 Request::unref(&requests[i]);
216 Request::unref(&request);