From ae1d123508cf7ef1d7932ce0cecbd8945c062cfd Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 28 Jul 2017 10:07:59 +0200 Subject: [PATCH] Use std::sort instead of qsort in C++ files (easy part). --- src/smpi/mpi/smpi_comm.cpp | 20 ++++++-------------- teshsuite/simdag/flatifier/flatifier.cpp | 16 ++++------------ 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index ee0747f8d6..ed178f0802 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -3,19 +3,19 @@ /* 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 "simgrid/s4u/Host.hpp" -#include - -#include "src/simix/smx_private.h" +#include "smpi_comm.hpp" #include "private.h" #include "private.hpp" -#include "smpi_comm.hpp" +#include "simgrid/s4u/Host.hpp" #include "smpi_coll.hpp" #include "smpi_datatype.hpp" #include "smpi_process.hpp" #include "smpi_request.hpp" #include "smpi_status.hpp" #include "smpi_win.hpp" +#include "src/simix/smx_private.h" +#include +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_comm, smpi, "Logging specific to SMPI (comm)"); @@ -305,14 +305,6 @@ void Comm::unref(Comm* comm){ } } -static int compare_ints (const void *a, const void *b) -{ - const int *da = static_cast(a); - const int *db = static_cast(b); - - return static_cast(*da > *db) - static_cast(*da < *db); -} - void Comm::init_smp(){ int leader = -1; @@ -395,7 +387,7 @@ void Comm::init_smp(){ leader_group_size++; } } - qsort(leader_list, leader_group_size, sizeof(int),compare_ints); + std::sort(leader_list, leader_list + leader_group_size); MPI_Group leaders_group = new Group(leader_group_size); diff --git a/teshsuite/simdag/flatifier/flatifier.cpp b/teshsuite/simdag/flatifier/flatifier.cpp index 75a363c523..bd04422b6d 100644 --- a/teshsuite/simdag/flatifier/flatifier.cpp +++ b/teshsuite/simdag/flatifier/flatifier.cpp @@ -17,16 +17,6 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(flatifier, "Logging specific to this platform parsing tool"); -static int name_compare_hosts(const void *n1, const void *n2) -{ - return std::strcmp(sg_host_get_name(*(sg_host_t *) n1), sg_host_get_name(*(sg_host_t *) n2)); -} - -static int name_compare_links(const void *n1, const void *n2) -{ - return std::strcmp(sg_link_name(*(SD_link_t *) n1),sg_link_name(*(SD_link_t *) n2)); -} - static bool parse_cmdline(int* timings, char** platformFile, int argc, char** argv) { bool parse_ok = true; @@ -73,7 +63,8 @@ static void dump_platform() // Hosts unsigned int totalHosts = sg_host_count(); sg_host_t* hosts = sg_host_list(); - std::qsort((void*)hosts, totalHosts, sizeof(sg_host_t), name_compare_hosts); + std::sort(hosts, hosts + totalHosts, + [](sg_host_t a, sg_host_t b) { return strcmp(sg_host_get_name(a), sg_host_get_name(b)) < 0; }); for (unsigned int i = 0; i < totalHosts; i++) { std::printf(" getCname(), sg_host_speed(hosts[i])); @@ -108,7 +99,8 @@ static void dump_platform() unsigned int totalLinks = sg_link_count(); simgrid::s4u::Link** links = sg_link_list(); - std::qsort((void*)links, totalLinks, sizeof(SD_link_t), name_compare_links); + std::sort(links, links + totalLinks, + [](simgrid::s4u::Link* a, simgrid::s4u::Link* b) { return strcmp(sg_link_name(a), sg_link_name(b)) < 0; }); for (unsigned int i = 0; i < totalLinks; i++) { simgrid::s4u::Link* link = links[i]; -- 2.20.1