Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Explicit cast when loosing precision (C++ examples).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 9 Jul 2020 16:01:28 +0000 (18:01 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 9 Jul 2020 19:28:35 +0000 (21:28 +0200)
17 files changed:
examples/s4u/actor-yield/s4u-actor-yield.cpp
examples/s4u/app-bittorrent/s4u-peer.cpp
examples/s4u/app-bittorrent/s4u-tracker.cpp
examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp
examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp
examples/s4u/comm-ready/s4u-comm-ready.cpp
examples/s4u/comm-wait/s4u-comm-wait.cpp
examples/s4u/comm-waitall/s4u-comm-waitall.cpp
examples/s4u/comm-waitany/s4u-comm-waitany.cpp
examples/s4u/comm-waituntil/s4u-comm-waituntil.cpp
examples/s4u/dht-chord/s4u-dht-chord.cpp
examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp
examples/s4u/energy-link/s4u-energy-link.cpp
examples/s4u/mc-bugged1-liveness/s4u-mc-bugged1-liveness.cpp
examples/s4u/platform-failures/s4u-platform-failures.cpp
examples/s4u/replay-comm/s4u-replay-comm.cpp
examples/smpi/smpi_s4u_masterslave/masterslave_mailbox_smpi.cpp

index 9ad18b8..9ef0d79 100644 (file)
@@ -19,7 +19,7 @@ class yielder {
   long number_of_yields;
 
 public:
-  explicit yielder(std::vector<std::string> args) { number_of_yields = std::stod(args[1]); }
+  explicit yielder(std::vector<std::string> args) { number_of_yields = std::stol(args[1]); }
   void operator()() const
   {
     for (int i = 0; i < number_of_yields; i++)
index 65db116..d653c2a 100644 (file)
@@ -150,7 +150,7 @@ void Peer::sendRequestTo(Connection* remote_peer, unsigned int piece)
   xbt_assert(remote_peer->hasPiece(piece));
   int block_index = getFirstMissingBlockFrom(piece);
   if (block_index != -1) {
-    int block_length = std::min(BLOCKS_REQUESTED, PIECES_BLOCKS - block_index);
+    int block_length = static_cast<int>(std::min(BLOCKS_REQUESTED, PIECES_BLOCKS - block_index));
     XBT_DEBUG("Sending a REQUEST to %s for piece %u (%d,%d)", remote_peer->mailbox_->get_cname(), piece, block_index,
               block_length);
     remote_peer->mailbox_
@@ -553,7 +553,7 @@ void Peer::updateChokedPeers()
       do {
         // We choose a random peer to unchoke.
         std::unordered_map<int, Connection>::iterator chosen_peer_it = connected_peers.begin();
-        std::advance(chosen_peer_it, random.uniform_int(0, connected_peers.size() - 1));
+        std::advance(chosen_peer_it, random.uniform_int(0, static_cast<int>(connected_peers.size() - 1)));
         chosen_peer = &chosen_peer_it->second;
         if (not chosen_peer->interested || not chosen_peer->choked_upload)
           chosen_peer = nullptr;
index f9f70b8..ee4a401 100644 (file)
@@ -46,7 +46,7 @@ void Tracker::operator()()
       // Sending back peers to the requesting peer
       TrackerAnswer* ta = new TrackerAnswer(TRACKER_QUERY_INTERVAL);
       std::set<int>::iterator next_peer;
-      int nb_known_peers = known_peers.size();
+      int nb_known_peers = static_cast<int>(known_peers.size());
       int max_tries      = std::min(MAXIMUM_PEERS, nb_known_peers);
       int tried          = 0;
       while (tried < max_tries) {
index d37a880..9c83964 100644 (file)
@@ -12,9 +12,9 @@
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_masterworker, "Messages specific for this s4u example");
 
 class Master {
-  long tasks_count                 = 0;
-  double compute_cost              = 0;
-  double communicate_cost          = 0;
+  long tasks_count      = 0;
+  double compute_cost   = 0;
+  long communicate_cost = 0;
   std::vector<simgrid::s4u::Mailbox*> workers;
 
 public:
@@ -24,7 +24,7 @@ public:
 
     tasks_count      = std::stol(args[1]);
     compute_cost     = std::stod(args[2]);
-    communicate_cost = std::stod(args[3]);
+    communicate_cost = std::stol(args[3]);
     for (unsigned int i = 4; i < args.size(); i++)
       workers.push_back(simgrid::s4u::Mailbox::by_name(args[i]));
 
index 08b60c2..a348d98 100644 (file)
@@ -16,9 +16,9 @@ static void master(std::vector<std::string> args)
 {
   xbt_assert(args.size() > 4, "The master function expects at least 3 arguments");
 
-  long tasks_count          = std::stol(args[1]);
-  double compute_cost       = std::stod(args[2]);
-  double communication_cost = std::stod(args[3]);
+  long tasks_count        = std::stol(args[1]);
+  double compute_cost     = std::stod(args[2]);
+  long communication_cost = std::stol(args[3]);
   std::vector<simgrid::s4u::Mailbox*> workers;
   for (unsigned int i = 4; i < args.size(); i++)
     workers.push_back(simgrid::s4u::Mailbox::by_name(args[i]));
index 88cfbda..85867a6 100644 (file)
@@ -30,8 +30,8 @@ static void peer(int argc, char** argv)
   xbt_assert(argc == 5, "Expecting 4 parameters from the XML deployment file but got %d", argc);
   int my_id           = std::stoi(argv[1]); /* - my id */
   long messages_count = std::stol(argv[2]); /* - number of message */
-  double msg_size     = std::stol(argv[3]); /* - message size in bytes */
-  long peers_count    = std::stod(argv[4]); /* - number of peers */
+  long msg_size       = std::stol(argv[3]); /* - message size in bytes */
+  long peers_count    = std::stol(argv[4]); /* - number of peers */
 
   /* Set myself as the persistent receiver of my mailbox so that messages start flowing to me as soon as they are put
    * into it */
@@ -71,7 +71,7 @@ static void peer(int argc, char** argv)
 
   /* Retrieve all the messages other peers have been sending to me until I receive all the corresponding "Finalize"
    * messages */
-  int pending_finalize_messages = peers_count - 1;
+  long pending_finalize_messages = peers_count - 1;
   while (pending_finalize_messages > 0) {
     if (my_mbox->ready()) {
       double start                = simgrid::s4u::Engine::get_clock();
index 4e7ee1a..1664f4b 100644 (file)
@@ -22,7 +22,7 @@ static void sender(int argc, char** argv)
 {
   xbt_assert(argc == 3, "Expecting 2 parameters from the XML deployment file but got %d", argc);
   long messages_count     = std::stol(argv[1]); /* - number of messages */
-  double msg_size         = std::stod(argv[2]); /* - message size in bytes */
+  long msg_size           = std::stol(argv[2]); /* - message size in bytes */
   double sleep_start_time = 5.0;
   double sleep_test_time  = 0;
 
index 09610c3..34cb0f5 100644 (file)
@@ -22,14 +22,14 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_async_waitall, "Messages specific for this s4u
 class Sender {
   long messages_count;  /* - number of messages */
   long receivers_count; /* - number of receivers */
-  double msg_size;      /* - message size in bytes */
+  long msg_size;        /* - message size in bytes */
 
 public:
   explicit Sender(std::vector<std::string> args)
   {
     xbt_assert(args.size() == 4, "Expecting 3 parameters from the XML deployment file but got %zu", args.size());
     messages_count  = std::stol(args[1]);
-    msg_size        = std::stod(args[2]);
+    msg_size        = std::stol(args[2]);
     receivers_count = std::stol(args[3]);
   }
   void operator()() const
index dcefe97..825de57 100644 (file)
@@ -27,14 +27,14 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_waitall, "Messages specific for this s4u e
 class Sender {
   long messages_count;  /* - number of messages */
   long receivers_count; /* - number of receivers */
-  double msg_size;      /* - message size in bytes */
+  long msg_size;        /* - message size in bytes */
 
 public:
   explicit Sender(std::vector<std::string> args)
   {
     xbt_assert(args.size() == 4, "Expecting 3 parameters from the XML deployment file but got %zu", args.size());
     messages_count  = std::stol(args[1]);
-    msg_size        = std::stod(args[2]);
+    msg_size        = std::stol(args[2]);
     receivers_count = std::stol(args[3]);
   }
   void operator()() const
index cfccd31..d887e37 100644 (file)
@@ -21,7 +21,7 @@ static void sender(int argc, char** argv)
 {
   xbt_assert(argc == 4, "Expecting 3 parameters from the XML deployment file but got %d", argc);
   long messages_count  = std::stol(argv[1]); /* - number of messages */
-  double msg_size      = std::stod(argv[2]); /* - message size in bytes */
+  long msg_size        = std::stol(argv[2]); /* - message size in bytes */
   long receivers_count = std::stol(argv[3]); /* - number of receivers */
 
   std::vector<simgrid::s4u::CommPtr> pending_comms;
index c2128f1..98fec88 100644 (file)
@@ -22,12 +22,12 @@ int main(int argc, char* argv[])
   while (not strncmp(options[0], "-", 1)) {
     unsigned int length = strlen("-nb_bits=");
     if (not strncmp(options[0], "-nb_bits=", length) && strlen(options[0]) > length) {
-      nb_bits = xbt_str_parse_int(options[0] + length, "Invalid nb_bits parameter: %s");
+      nb_bits = static_cast<int>(xbt_str_parse_int(options[0] + length, "Invalid nb_bits parameter: %s"));
       XBT_DEBUG("Set nb_bits to %d", nb_bits);
     } else {
       length = strlen("-timeout=");
       if (not strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) {
-        timeout = xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s");
+        timeout = static_cast<int>(xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s"));
         XBT_DEBUG("Set timeout to %d", timeout);
       } else {
         xbt_die("Invalid chord option '%s'", options[0]);
index c38206c..1912ef6 100644 (file)
@@ -23,12 +23,12 @@ static void node(int argc, char* argv[])
   double deadline;
   xbt_assert(argc == 3 || argc == 4, "Wrong number of arguments");
   /* Node initialization */
-  unsigned int node_id = strtoul(argv[1], nullptr, 0);
+  unsigned int node_id = static_cast<unsigned int>(strtoul(argv[1], nullptr, 0));
   kademlia::Node node(node_id);
 
   if (argc == 4) {
     XBT_INFO("Hi, I'm going to join the network with id %u", node.getId());
-    unsigned int known_id = strtoul(argv[2], NULL, 0);
+    unsigned int known_id = static_cast<unsigned int>(strtoul(argv[2], NULL, 0));
     join_success          = node.join(known_id);
     deadline              = std::stod(argv[3]);
   } else {
index cd0c5fb..a44c445 100644 (file)
@@ -17,9 +17,9 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_energyconsumption, "Messages specific for t
 static void sender(std::vector<std::string> args)
 {
   xbt_assert(args.size() == 2, "The master function expects 2 arguments.");
-  int flow_amount  = std::stoi(args.at(0));
-  double comm_size = std::stod(args.at(1));
-  XBT_INFO("Send %.0f bytes, in %d flows", comm_size, flow_amount);
+  int flow_amount = std::stoi(args.at(0));
+  long comm_size  = std::stol(args.at(1));
+  XBT_INFO("Send %ld bytes, in %d flows", comm_size, flow_amount);
 
   simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::string("message"));
 
@@ -28,7 +28,7 @@ static void sender(std::vector<std::string> args)
 
   if (flow_amount == 1) {
     /* - Send the task to the @ref worker */
-    char* payload = bprintf("%f", comm_size);
+    char* payload = bprintf("%ld", comm_size);
     mailbox->put(payload, comm_size);
   } else {
     // Start all comms in parallel, and wait for all completions in one shot
index 286b06e..175d561 100644 (file)
@@ -87,7 +87,7 @@ static void coordinator()
 
 static void client(int id)
 {
-  int my_pid = simgrid::s4u::this_actor::get_pid();
+  aid_t my_pid = simgrid::s4u::this_actor::get_pid();
 
   simgrid::s4u::Mailbox* my_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id));
 
@@ -117,7 +117,7 @@ static void client(int id)
 
     simgrid::s4u::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::RELEASE, my_mailbox), 1000);
 
-    simgrid::s4u::this_actor::sleep_for(my_pid);
+    simgrid::s4u::this_actor::sleep_for(static_cast<double>(my_pid));
 
     if (id == 1) {
       cs = 0;
index b265c58..f55e2b0 100644 (file)
@@ -29,7 +29,7 @@ static void master(int argc, char* argv[])
   simgrid::s4u::Mailbox* mailbox;
   long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
   double comp_size     = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
-  double comm_size     = xbt_str_parse_double(argv[3], "Invalid communication size: %s");
+  long comm_size       = xbt_str_parse_int(argv[3], "Invalid communication size: %s");
   long workers_count   = xbt_str_parse_int(argv[4], "Invalid amount of workers: %s");
 
   XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, number_of_tasks);
index 0543bc5..1983bf0 100644 (file)
@@ -52,11 +52,11 @@ public:
 
   static void send(simgrid::xbt::ReplayAction& action)
   {
-    double size                 = std::stod(action[3]);
-    std::string* payload        = new std::string(action[3]);
-    double clock                = simgrid::s4u::Engine::get_clock();
+    long size                 = static_cast<long>(std::stod(action[3]));
+    std::string* payload      = new std::string(action[3]);
+    double clock              = simgrid::s4u::Engine::get_clock();
     simgrid::s4u::Mailbox* to = simgrid::s4u::Mailbox::by_name(simgrid::s4u::this_actor::get_name() + "_" + action[2]);
-    ACT_DEBUG("Entering Send: %s (size: %g) -- Actor %s on mailbox %s", NAME.c_str(), size,
+    ACT_DEBUG("Entering Send: %s (size: %ld) -- Actor %s on mailbox %s", NAME.c_str(), size,
               simgrid::s4u::this_actor::get_cname(), to->get_cname());
     to->put(payload, size);
     delete payload;
index a786889..6ed9f33 100644 (file)
@@ -14,9 +14,9 @@ static void master(std::vector<std::string> args)
 {
   xbt_assert(args.size() > 4, "The master function expects at least 3 arguments");
 
-  long tasks_count          = std::stol(args[1]);
-  double compute_cost       = std::stod(args[2]);
-  double communication_cost = std::stod(args[3]);
+  long tasks_count        = std::stol(args[1]);
+  double compute_cost     = std::stod(args[2]);
+  long communication_cost = std::stol(args[3]);
   std::vector<simgrid::s4u::Mailbox*> workers;
   for (unsigned int i = 4; i < args.size(); i++)
     workers.push_back(simgrid::s4u::Mailbox::by_name(args[i]));