#include "smpi_request.hpp"
#include "xbt/config.hpp"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_coll, smpi, "Logging specific to SMPI (coll)");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_coll, smpi, "Logging specific to SMPI collectives.");
#define COLL_SETTER(cat, ret, args, args2) \
int(*Colls::cat) args; \
- void Colls::set_##cat(const std::string& name) \
+ void Colls::_XBT_CONCAT(set_, cat)(const std::string& name) \
{ \
- int id = find_coll_description(mpi_coll_##cat##_description, name, #cat); \
- cat = reinterpret_cast<ret(*) args>(mpi_coll_##cat##_description[id].coll); \
+ int id = find_coll_description(_XBT_CONCAT3(mpi_coll_, cat, _description), name, _XBT_STRINGIFY(cat)); \
+ cat = reinterpret_cast<ret(*) args>(_XBT_CONCAT3(mpi_coll_, cat, _description)[id].coll); \
if (cat == nullptr) \
- xbt_die("Collective " #cat " set to nullptr!"); \
+ xbt_die("Collective " _XBT_STRINGIFY(cat) " set to nullptr!"); \
}
namespace simgrid{
return -1;
}
-COLL_APPLY(COLL_SETTER,COLL_GATHER_SIG,"");
+int(*Colls::gather) (const void *send_buff, int send_count, MPI_Datatype send_type,
+ void *recv_buff, int recv_count, MPI_Datatype recv_type,
+ int root, MPI_Comm comm);
+void Colls::set_gather(const std::string& name)
+{
+ int id = find_coll_description(mpi_coll_gather_description, name, "gather");
+ gather = reinterpret_cast<int(*)(const void *send_buff, int send_count, MPI_Datatype send_type,
+ void *recv_buff, int recv_count, MPI_Datatype recv_type,
+ int root, MPI_Comm comm)>(mpi_coll_gather_description[id].coll);
+ if (gather == nullptr)
+ xbt_die("Collective gather set to nullptr!");
+}
+
+//COLL_APPLY(COLL_SETTER,COLL_GATHER_SIG,"");
COLL_APPLY(COLL_SETTER,COLL_ALLGATHER_SIG,"");
COLL_APPLY(COLL_SETTER,COLL_ALLGATHERV_SIG,"");
COLL_APPLY(COLL_SETTER,COLL_REDUCE_SIG,"");
}
}
+//Implementations of the single algorithm collectives
-//Implementations of the single algorith collectives
-
-int Colls::gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
+int Colls::gatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, const int *recvcounts, const int *displs,
MPI_Datatype recvtype, int root, MPI_Comm comm)
{
MPI_Request request;
- Colls::igatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm, &request);
- MPI_Request* requests = request->get_nbc_requests();
- int count = request->get_nbc_requests_size();
- Request::waitall(count, requests, MPI_STATUS_IGNORE);
- for (int i = 0; i < count; i++) {
- if(requests[i]!=MPI_REQUEST_NULL)
- Request::unref(&requests[i]);
- }
- delete[] requests;
- Request::unref(&request);
- return MPI_SUCCESS;
+ Colls::igatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm, &request, 0);
+ return Request::wait(&request, MPI_STATUS_IGNORE);
}
-int Colls::scatterv(void *sendbuf, int *sendcounts, int *displs, MPI_Datatype sendtype, void *recvbuf, int recvcount,
+int Colls::scatterv(const void *sendbuf, const int *sendcounts, const int *displs, MPI_Datatype sendtype, void *recvbuf, int recvcount,
MPI_Datatype recvtype, int root, MPI_Comm comm)
{
MPI_Request request;
- Colls::iscatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm, &request);
- MPI_Request* requests = request->get_nbc_requests();
- int count = request->get_nbc_requests_size();
- Request::waitall(count, requests, MPI_STATUS_IGNORE);
- for (int dst = 0; dst < count; dst++) {
- if(requests[dst]!=MPI_REQUEST_NULL)
- Request::unref(&requests[dst]);
- }
- delete[] requests;
- Request::unref(&request);
- return MPI_SUCCESS;
+ Colls::iscatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm, &request, 0);
+ return Request::wait(&request, MPI_STATUS_IGNORE);
}
-int Colls::scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
+int Colls::scan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
{
int system_tag = -888;
MPI_Aint lb = 0;
Datatype::copy(sendbuf, count, datatype, recvbuf, count, datatype);
// Send/Recv buffers to/from others
- MPI_Request *requests = xbt_new(MPI_Request, size - 1);
- void **tmpbufs = xbt_new(void *, rank);
+ MPI_Request* requests = new MPI_Request[size - 1];
+ unsigned char** tmpbufs = new unsigned char*[rank];
int index = 0;
for (int other = 0; other < rank; other++) {
tmpbufs[index] = smpi_get_tmp_sendbuffer(count * dataext);
for(index = 0; index < size-1; index++) {
Request::unref(&requests[index]);
}
- xbt_free(tmpbufs);
- xbt_free(requests);
+ delete[] tmpbufs;
+ delete[] requests;
return MPI_SUCCESS;
}
-int Colls::exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
+int Colls::exscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
{
int system_tag = -888;
MPI_Aint lb = 0;
datatype->extent(&lb, &dataext);
// Send/Recv buffers to/from others
- MPI_Request *requests = xbt_new(MPI_Request, size - 1);
- void **tmpbufs = xbt_new(void *, rank);
+ MPI_Request* requests = new MPI_Request[size - 1];
+ unsigned char** tmpbufs = new unsigned char*[rank];
int index = 0;
for (int other = 0; other < rank; other++) {
tmpbufs[index] = smpi_get_tmp_sendbuffer(count * dataext);
for(index = 0; index < size-1; index++) {
Request::unref(&requests[index]);
}
- xbt_free(tmpbufs);
- xbt_free(requests);
+ delete[] tmpbufs;
+ delete[] requests;
return MPI_SUCCESS;
}
-int Colls::alltoallw(void *sendbuf, int *sendcounts, int *senddisps, MPI_Datatype* sendtypes,
- void *recvbuf, int *recvcounts, int *recvdisps, MPI_Datatype* recvtypes, MPI_Comm comm)
+int Colls::alltoallw(const void *sendbuf, const int *sendcounts, const int *senddisps, const MPI_Datatype* sendtypes,
+ void *recvbuf, const int *recvcounts, const int *recvdisps, const MPI_Datatype* recvtypes, MPI_Comm comm)
{
MPI_Request request;
- int err = Colls::ialltoallw(sendbuf, sendcounts, senddisps, sendtypes, recvbuf, recvcounts, recvdisps, recvtypes, comm, &request);
- MPI_Request* requests = request->get_nbc_requests();
- int count = request->get_nbc_requests_size();
- XBT_DEBUG("<%d> wait for %d requests", comm->rank(), count);
- Request::waitall(count, requests, MPI_STATUS_IGNORE);
- for (int i = 0; i < count; i++) {
- if(requests[i]!=MPI_REQUEST_NULL)
- Request::unref(&requests[i]);
- }
- delete[] requests;
- Request::unref(&request);
- return err;
+ Colls::ialltoallw(sendbuf, sendcounts, senddisps, sendtypes, recvbuf, recvcounts, recvdisps, recvtypes, comm, &request, 0);
+ return Request::wait(&request, MPI_STATUS_IGNORE);
}
}