A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[sonar] Use std::function.
[simgrid.git]
/
src
/
smpi
/
colls
/
smpi_coll.cpp
diff --git
a/src/smpi/colls/smpi_coll.cpp
b/src/smpi/colls/smpi_coll.cpp
index
e167de8
..
f50418b
100644
(file)
--- a/
src/smpi/colls/smpi_coll.cpp
+++ b/
src/smpi/colls/smpi_coll.cpp
@@
-1,6
+1,6
@@
/* smpi_coll.c -- various optimized routing for collectives */
/* smpi_coll.c -- various optimized routing for collectives */
-/* Copyright (c) 2009-201
8
. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2009-201
9
. 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. */
/* 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. */
@@
-17,7
+17,7
@@
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_coll, smpi, "Logging specific to SMPI (coll
#define COLL_SETTER(cat, ret, args, args2) \
int(*Colls::cat) args; \
#define COLL_SETTER(cat, ret, args, args2) \
int(*Colls::cat) args; \
- void Colls::set_##cat(
std::string name)
\
+ void Colls::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(mpi_coll_##cat##_description, name, #cat); \
cat = reinterpret_cast<ret(*) args>(mpi_coll_##cat##_description[id].coll); \
@@
-32,49
+32,49
@@
void (*Colls::smpi_coll_cleanup_callback)();
/* these arrays must be nullptr terminated */
s_mpi_coll_description_t Colls::mpi_coll_gather_description[] = {
/* 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} };
+ COLL_GATHERS(COLL_DESCRIPTION, COLL_COMMA), {
"", ""
, nullptr} };
s_mpi_coll_description_t Colls::mpi_coll_allgather_description[] = {
s_mpi_coll_description_t Colls::mpi_coll_allgather_description[] = {
- COLL_ALLGATHERS(COLL_DESCRIPTION, COLL_COMMA), {
nullptr, nullptr
, nullptr} };
+ COLL_ALLGATHERS(COLL_DESCRIPTION, COLL_COMMA), {
"", ""
, nullptr} };
s_mpi_coll_description_t Colls::mpi_coll_allgatherv_description[] = {
s_mpi_coll_description_t Colls::mpi_coll_allgatherv_description[] = {
- COLL_ALLGATHERVS(COLL_DESCRIPTION, COLL_COMMA), {
nullptr, nullptr
, nullptr} };
+ COLL_ALLGATHERVS(COLL_DESCRIPTION, COLL_COMMA), {
"", ""
, nullptr} };
s_mpi_coll_description_t Colls::mpi_coll_allreduce_description[] ={
s_mpi_coll_description_t Colls::mpi_coll_allreduce_description[] ={
- COLL_ALLREDUCES(COLL_DESCRIPTION, COLL_COMMA), {
nullptr, nullptr
, nullptr} };
+ COLL_ALLREDUCES(COLL_DESCRIPTION, COLL_COMMA), {
"", ""
, nullptr} };
s_mpi_coll_description_t Colls::mpi_coll_reduce_scatter_description[] = {
s_mpi_coll_description_t Colls::mpi_coll_reduce_scatter_description[] = {
- COLL_REDUCE_SCATTERS(COLL_DESCRIPTION, COLL_COMMA), {
nullptr, nullptr
, nullptr} };
+ COLL_REDUCE_SCATTERS(COLL_DESCRIPTION, COLL_COMMA), {
"", ""
, nullptr} };
s_mpi_coll_description_t Colls::mpi_coll_scatter_description[] ={
s_mpi_coll_description_t Colls::mpi_coll_scatter_description[] ={
- COLL_SCATTERS(COLL_DESCRIPTION, COLL_COMMA), {
nullptr, nullptr
, nullptr} };
+ COLL_SCATTERS(COLL_DESCRIPTION, COLL_COMMA), {
"", ""
, nullptr} };
s_mpi_coll_description_t Colls::mpi_coll_barrier_description[] ={
s_mpi_coll_description_t Colls::mpi_coll_barrier_description[] ={
- COLL_BARRIERS(COLL_DESCRIPTION, COLL_COMMA), {
nullptr, nullptr
, nullptr} };
+ COLL_BARRIERS(COLL_DESCRIPTION, COLL_COMMA), {
"", ""
, nullptr} };
s_mpi_coll_description_t Colls::mpi_coll_alltoall_description[] = {
s_mpi_coll_description_t Colls::mpi_coll_alltoall_description[] = {
- COLL_ALLTOALLS(COLL_DESCRIPTION, COLL_COMMA), {
nullptr, nullptr
, nullptr} };
+ COLL_ALLTOALLS(COLL_DESCRIPTION, COLL_COMMA), {
"", ""
, nullptr} };
s_mpi_coll_description_t Colls::mpi_coll_alltoallv_description[] = {
s_mpi_coll_description_t Colls::mpi_coll_alltoallv_description[] = {
- COLL_ALLTOALLVS(COLL_DESCRIPTION, COLL_COMMA), {
nullptr, nullptr
, nullptr} };
+ COLL_ALLTOALLVS(COLL_DESCRIPTION, COLL_COMMA), {
"", ""
, nullptr} };
s_mpi_coll_description_t Colls::mpi_coll_bcast_description[] = {
s_mpi_coll_description_t Colls::mpi_coll_bcast_description[] = {
- COLL_BCASTS(COLL_DESCRIPTION, COLL_COMMA), {
nullptr, nullptr
, nullptr} };
+ COLL_BCASTS(COLL_DESCRIPTION, COLL_COMMA), {
"", ""
, nullptr} };
s_mpi_coll_description_t Colls::mpi_coll_reduce_description[] = {
s_mpi_coll_description_t Colls::mpi_coll_reduce_description[] = {
- COLL_REDUCES(COLL_DESCRIPTION, COLL_COMMA), {
nullptr, nullptr
, nullptr} };
+ COLL_REDUCES(COLL_DESCRIPTION, COLL_COMMA), {
"", ""
, nullptr} };
/** Displays the long description of all registered models, and quit */
void Colls::coll_help(const char *category, s_mpi_coll_description_t * table)
{
XBT_WARN("Long description of the %s models accepted by this simulator:\n", category);
/** Displays the long description of all registered models, and quit */
void Colls::coll_help(const char *category, s_mpi_coll_description_t * table)
{
XBT_WARN("Long description of the %s models accepted by this simulator:\n", category);
- for (int i = 0;
table[i].name
; i++)
- XBT_WARN(" %s: %s\n", table[i].name
, table[i].description
);
+ for (int i = 0;
not table[i].name.empty()
; i++)
+ XBT_WARN(" %s: %s\n", table[i].name
.c_str(), table[i].description.c_str()
);
}
}
-int Colls::find_coll_description(s_mpi_coll_description_t* table,
std::string
name, const char* desc)
+int Colls::find_coll_description(s_mpi_coll_description_t* table,
const std::string&
name, const char* desc)
{
{
- for (int i = 0;
table[i].name
; i++)
+ for (int i = 0;
not table[i].name.empty()
; i++)
if (name == table[i].name) {
if (name == table[i].name) {
- if (
strcmp(table[i].name,"default")
)
- XBT_INFO("Switch to algorithm %s for collective %s",table[i].name,desc);
+ if (
table[i].name != "default"
)
+ XBT_INFO("Switch to algorithm %s for collective %s",table[i].name
.c_str()
,desc);
return i;
}
return i;
}
- if (
not table[0].name
)
+ if (
table[0].name.empty()
)
xbt_die("No collective is valid for '%s'! This is a bug.", name.c_str());
xbt_die("No collective is valid for '%s'! This is a bug.", name.c_str());
- std::string name_list =
std::string(table[0].name)
;
- for (int i = 1;
table[i].name
; i++)
+ std::string name_list =
table[0].name
;
+ for (int i = 1;
not table[i].name.empty()
; i++)
name_list = name_list + ", " + table[i].name;
xbt_die("Collective '%s' is invalid! Valid collectives are: %s.", name.c_str(), name_list.c_str());
name_list = name_list + ", " + table[i].name;
xbt_die("Collective '%s' is invalid! Valid collectives are: %s.", name.c_str(), name_list.c_str());
@@
-98,7
+98,7
@@
void Colls::set_collectives(){
if (selector_name.empty())
selector_name = "default";
if (selector_name.empty())
selector_name = "default";
- std::
map<std::string, std::function<void(std::string)>> setter_callbacks
= {
+ std::
pair<std::string, std::function<void(std::string)>> setter_callbacks[]
= {
{"gather", &Colls::set_gather}, {"allgather", &Colls::set_allgather},
{"allgatherv", &Colls::set_allgatherv}, {"allreduce", &Colls::set_allreduce},
{"alltoall", &Colls::set_alltoall}, {"alltoallv", &Colls::set_alltoallv},
{"gather", &Colls::set_gather}, {"allgather", &Colls::set_allgather},
{"allgatherv", &Colls::set_allgatherv}, {"allreduce", &Colls::set_allreduce},
{"alltoall", &Colls::set_alltoall}, {"alltoallv", &Colls::set_alltoallv},
@@
-106,26
+106,13
@@
void Colls::set_collectives(){
{"scatter", &Colls::set_scatter}, {"bcast", &Colls::set_bcast},
{"barrier", &Colls::set_barrier}};
{"scatter", &Colls::set_scatter}, {"bcast", &Colls::set_bcast},
{"barrier", &Colls::set_barrier}};
- // This only prevents code duplication
- std::function<void(std::string)> setup = [selector_name, &setter_callbacks](std::string coll) {
- std::string name = simgrid::config::get_value<std::string>(("smpi/" + coll).c_str());
+ for (auto& elem : setter_callbacks) {
+ std::string name = simgrid::config::get_value<std::string>(("smpi/" + elem.first).c_str());
if (name.empty())
name = selector_name;
if (name.empty())
name = selector_name;
- setter_callbacks[coll](name);
- };
-
- setup("gather");
- setup("allgather");
- setup("allgatherv");
- setup("allreduce");
- setup("alltoall");
- setup("alltoallv");
- setup("reduce");
- setup("reduce_scatter");
- setup("scatter");
- setup("bcast");
- setup("barrier");
+ (elem.second)(name);
+ }
}
}