-/* smpi_coll.c -- various optimized routing for collectives */
+/* smpi_coll.c -- various optimized routing for collectives */
-/* Copyright (c) 2009-2015. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2009-2017. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include "private.h"
-#include "colls/colls.h"
-#include "simgrid/sg_config.h"
+#include "src/smpi/private.h"
+#include "src/smpi/smpi_coll.hpp"
+#include "src/smpi/smpi_comm.hpp"
+#include "src/smpi/smpi_datatype.hpp"
+#include "src/smpi/smpi_op.hpp"
+#include "src/smpi/smpi_request.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_coll, smpi, "Logging specific to SMPI (coll)");
-s_mpi_coll_description_t mpi_coll_gather_description[] = {
- COLL_GATHERS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
-};
-
-s_mpi_coll_description_t mpi_coll_allgather_description[] = {
- COLL_ALLGATHERS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr}
-};
-
-s_mpi_coll_description_t mpi_coll_allgatherv_description[] = { COLL_ALLGATHERVS(COLL_DESCRIPTION, COLL_COMMA),
- {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
-};
-
-s_mpi_coll_description_t mpi_coll_allreduce_description[] ={ COLL_ALLREDUCES(COLL_DESCRIPTION, COLL_COMMA),
- {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
-};
-
-s_mpi_coll_description_t mpi_coll_reduce_scatter_description[] = {COLL_REDUCE_SCATTERS(COLL_DESCRIPTION, COLL_COMMA),
- {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
-};
-
-s_mpi_coll_description_t mpi_coll_scatter_description[] ={COLL_SCATTERS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr}};
-
-s_mpi_coll_description_t mpi_coll_barrier_description[] ={COLL_BARRIERS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr}};
-
-s_mpi_coll_description_t mpi_coll_alltoall_description[] = {COLL_ALLTOALLS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr}};
-
-s_mpi_coll_description_t mpi_coll_alltoallv_description[] = {COLL_ALLTOALLVS(COLL_DESCRIPTION, COLL_COMMA),
- {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
-};
-
-s_mpi_coll_description_t mpi_coll_bcast_description[] = {COLL_BCASTS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr}};
+#define COLL_SETTER(cat, ret, args, args2)\
+int (*Colls::cat ) args;\
+void Colls::set_##cat (const char * name){\
+ int id = find_coll_description(mpi_coll_## cat ##_description,\
+ name,#cat);\
+ cat = reinterpret_cast<ret (*) args>\
+ (mpi_coll_## cat ##_description[id].coll);\
+ if (cat == nullptr)\
+ xbt_die("Collective "#cat" set to nullptr!");\
+}
-s_mpi_coll_description_t mpi_coll_reduce_description[] = {COLL_REDUCES(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
+#define SET_COLL(coll)\
+ name = xbt_cfg_get_string("smpi/"#coll);\
+ if (name==nullptr || name[0] == '\0')\
+ name = selector_name;\
+ set_##coll(name);
+namespace simgrid{
+namespace smpi{
+void (*Colls::smpi_coll_cleanup_callback)();
+
+/* these arrays must be nullptr terminated */
+s_mpi_coll_description_t Colls::mpi_coll_gather_description[] = {
+ COLL_GATHERS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
+s_mpi_coll_description_t Colls::mpi_coll_allgather_description[] = {
+ COLL_ALLGATHERS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
+s_mpi_coll_description_t Colls::mpi_coll_allgatherv_description[] = {
+ COLL_ALLGATHERVS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
+s_mpi_coll_description_t Colls::mpi_coll_allreduce_description[] ={
+ COLL_ALLREDUCES(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
+s_mpi_coll_description_t Colls::mpi_coll_reduce_scatter_description[] = {
+ COLL_REDUCE_SCATTERS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
+s_mpi_coll_description_t Colls::mpi_coll_scatter_description[] ={
+ COLL_SCATTERS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
+s_mpi_coll_description_t Colls::mpi_coll_barrier_description[] ={
+ COLL_BARRIERS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
+s_mpi_coll_description_t Colls::mpi_coll_alltoall_description[] = {
+ COLL_ALLTOALLS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
+s_mpi_coll_description_t Colls::mpi_coll_alltoallv_description[] = {
+ COLL_ALLTOALLVS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
+s_mpi_coll_description_t Colls::mpi_coll_bcast_description[] = {
+ COLL_BCASTS(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
+s_mpi_coll_description_t Colls::mpi_coll_reduce_description[] = {
+ COLL_REDUCES(COLL_DESCRIPTION, COLL_COMMA), {nullptr, nullptr, nullptr} };
/** Displays the long description of all registered models, and quit */
-void coll_help(const char *category, s_mpi_coll_description_t * table)
+void Colls::coll_help(const char *category, s_mpi_coll_description_t * table)
{
- printf("Long description of the %s models accepted by this simulator:\n", category);
+ XBT_WARN("Long description of the %s models accepted by this simulator:\n", category);
for (int i = 0; table[i].name; i++)
- printf(" %s: %s\n", table[i].name, table[i].description);
+ XBT_WARN(" %s: %s\n", table[i].name, table[i].description);
}
-int find_coll_description(s_mpi_coll_description_t * table, const char *name, const char *desc)
+int Colls::find_coll_description(s_mpi_coll_description_t * table, const char *name, const char *desc)
{
char *name_list = nullptr;
- int selector_on=0;
- if (name==nullptr || name[0] == '\0') {
- //no argument provided, use active selector's algorithm
- name=static_cast<char*>(xbt_cfg_get_string("smpi/coll-selector"));
- selector_on=1;
- }
for (int i = 0; table[i].name; i++)
- if (!strcmp(name, table[i].name)) {
+ if (not strcmp(name, table[i].name)) {
if (strcmp(table[i].name,"default"))
XBT_INFO("Switch to algorithm %s for collective %s",table[i].name,desc);
return i;
}
- if(selector_on){
- // collective seems not handled by the active selector, try with default one
- for (int i = 0; table[i].name; i++)
- if (!strcmp("default", table[i].name)) {
- return i;
- }
- }
- if (!table[0].name)
+ if (not table[0].name)
xbt_die("No collective is valid for '%s'! This is a bug.",name);
name_list = xbt_strdup(table[0].name);
for (int i = 1; table[i].name; i++) {
return -1;
}
-void (*smpi_coll_cleanup_callback)();
-namespace simgrid{
-namespace smpi{
-
-int (*Colls::gather)(void *, int, MPI_Datatype, void*, int, MPI_Datatype, int root, MPI_Comm);
-int (*Colls::allgather)(void *, int, MPI_Datatype, void*, int, MPI_Datatype, MPI_Comm);
-int (*Colls::allgatherv)(void *, int, MPI_Datatype, void*, int*, int*, MPI_Datatype, MPI_Comm);
-int (*Colls::allreduce)(void *sbuf, void *rbuf, int rcount, MPI_Datatype dtype, MPI_Op op, MPI_Comm comm);
-int (*Colls::alltoall)(void *, int, MPI_Datatype, void*, int, MPI_Datatype, MPI_Comm);
-int (*Colls::alltoallv)(void *, int*, int*, MPI_Datatype, void*, int*, int*, MPI_Datatype, MPI_Comm);
-int (*Colls::bcast)(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm com);
-int (*Colls::reduce)(void *buf, void *rbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm);
-int (*Colls::reduce_scatter)(void *sbuf, void *rbuf, int *rcounts,MPI_Datatype dtype,MPI_Op op,MPI_Comm comm);
-int (*Colls::scatter)(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,int root, MPI_Comm comm);
-int (*Colls::barrier)(MPI_Comm comm);
-
-
-#define COLL_SETTER(cat, ret, args, args2)\
-void Colls::set_##cat (const char * name){\
- int id = find_coll_description(mpi_coll_## cat ##_description,\
- name,#cat);\
- cat = reinterpret_cast<ret (*) args>\
- (mpi_coll_## cat ##_description[id].coll);\
-}
COLL_APPLY(COLL_SETTER,COLL_GATHER_SIG,"");
COLL_APPLY(COLL_SETTER,COLL_ALLGATHER_SIG,"");
if (selector_name==nullptr || selector_name[0] == '\0')
selector_name = "default";
- const char* name = xbt_cfg_get_string("smpi/gather");
- if (name==nullptr || name[0] == '\0')
- name = selector_name;
-
- set_gather(name);
-
- name = xbt_cfg_get_string("smpi/allgather");
- if (name==nullptr || name[0] == '\0')
- name = selector_name;
-
- set_allgather(name);
-
- name = xbt_cfg_get_string("smpi/allgatherv");
- if (name==nullptr || name[0] == '\0')
- name = selector_name;
-
- set_allgatherv(name);
-
- name = xbt_cfg_get_string("smpi/allreduce");
- if (name==nullptr || name[0] == '\0')
- name = selector_name;
-
- set_allreduce(name);
-
- name = xbt_cfg_get_string("smpi/alltoall");
- if (name==nullptr || name[0] == '\0')
- name = selector_name;
-
- set_alltoall(name);
-
- name = xbt_cfg_get_string("smpi/alltoallv");
- if (name==nullptr || name[0] == '\0')
- name = selector_name;
-
- set_alltoallv(name);
-
- name = xbt_cfg_get_string("smpi/reduce");
- if (name==nullptr || name[0] == '\0')
- name = selector_name;
-
- set_reduce(name);
-
- name = xbt_cfg_get_string("smpi/reduce-scatter");
- if (name==nullptr || name[0] == '\0')
- name = selector_name;
-
- set_reduce_scatter(name);
-
- name = xbt_cfg_get_string("smpi/scatter");
- if (name==nullptr || name[0] == '\0')
- name = selector_name;
-
- set_scatter(name);
-
- name = xbt_cfg_get_string("smpi/bcast");
- if (name==nullptr || name[0] == '\0')
- name = selector_name;
-
- set_bcast(name);
-
- name = xbt_cfg_get_string("smpi/barrier");
- if (name==nullptr || name[0] == '\0')
- name = selector_name;
-
- set_barrier(name);
+ const char* name;
+
+ SET_COLL(gather);
+ SET_COLL(allgather);
+ SET_COLL(allgatherv);
+ SET_COLL(allreduce);
+ SET_COLL(alltoall);
+ SET_COLL(alltoallv);
+ SET_COLL(reduce);
+ SET_COLL(reduce_scatter);
+ SET_COLL(scatter);
+ SET_COLL(bcast);
+ SET_COLL(barrier);
}
+//Implementations of the single algorith collectives
+
int Colls::gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
MPI_Datatype recvtype, int root, MPI_Comm comm)
{
// Local copy from self
Datatype::copy(sendbuf, count, datatype, recvbuf, count, datatype);
- // Send/Recv buffers to/from others;
+ // Send/Recv buffers to/from others
MPI_Request *requests = xbt_new(MPI_Request, size - 1);
void **tmpbufs = xbt_new(void *, rank);
int index = 0;
}
if(index < rank) {
// #Request is below rank: it's a irecv
- if(op!=MPI_OP_NULL) op->apply( tmpbufs[index], recvbuf, &count, datatype);
+ op->apply( tmpbufs[index], recvbuf, &count, datatype);
}
}
}else{
//non commutative case, wait in order
for (int other = 0; other < size - 1; other++) {
Request::wait(&(requests[other]), MPI_STATUS_IGNORE);
- if(index < rank) {
- if(op!=MPI_OP_NULL) op->apply( tmpbufs[other], recvbuf, &count, datatype);
+ if(index < rank && op!=MPI_OP_NULL) {
+ op->apply( tmpbufs[other], recvbuf, &count, datatype);
}
}
}
datatype->extent(&lb, &dataext);
- // Send/Recv buffers to/from others;
+ // Send/Recv buffers to/from others
MPI_Request *requests = xbt_new(MPI_Request, size - 1);
void **tmpbufs = xbt_new(void *, rank);
int index = 0;
recvbuf_is_empty=0;
} else
// #Request is below rank: it's a irecv
- if(op!=MPI_OP_NULL) op->apply( tmpbufs[index], recvbuf, &count, datatype);
+ op->apply( tmpbufs[index], recvbuf, &count, datatype);
}
}
}else{
Datatype::copy(tmpbufs[other], count, datatype, recvbuf, count, datatype);
recvbuf_is_empty = 0;
} else
- if(op!=MPI_OP_NULL) op->apply( tmpbufs[other], recvbuf, &count, datatype);
+ if(op!=MPI_OP_NULL)
+ op->apply( tmpbufs[other], recvbuf, &count, datatype);
}
}
}
}
}
-
-
-
-
-