Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use std::sort instead of qsort in C++ files (easy part).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 28 Jul 2017 08:07:59 +0000 (10:07 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 28 Jul 2017 12:52:38 +0000 (14:52 +0200)
src/smpi/mpi/smpi_comm.cpp
teshsuite/simdag/flatifier/flatifier.cpp

index ee0747f..ed178f0 100644 (file)
@@ -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 <climits>
-
-#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 <algorithm>
+#include <climits>
 
 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<const int *>(a);
-  const int *db = static_cast<const int *>(b);
-
-  return static_cast<int>(*da > *db) - static_cast<int>(*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);
 
index 75a363c..bd04422 100644 (file)
 
 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("  <host id=\"%s\" speed=\"%.0f\"", hosts[i]->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];