Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Explicit cast when loosing precision (teshsuite/).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 9 Jul 2020 19:55:23 +0000 (21:55 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 9 Jul 2020 20:41:22 +0000 (22:41 +0200)
teshsuite/mc/dwarf-expression/dwarf-expression.cpp
teshsuite/s4u/cloud-sharing/cloud-sharing.cpp
teshsuite/s4u/concurrent_rw/concurrent_rw.cpp
teshsuite/s4u/evaluate-get-route-time/evaluate-get-route-time.cpp
teshsuite/s4u/pid/pid.cpp
teshsuite/simdag/flatifier/flatifier.cpp
teshsuite/surf/lmm_usage/lmm_usage.cpp
teshsuite/surf/maxmin_bench/maxmin_bench.cpp
teshsuite/xbt/parmap_bench/parmap_bench.cpp
teshsuite/xbt/parmap_test/parmap_test.cpp

index 32f8ecf..2810a03 100644 (file)
@@ -23,7 +23,8 @@ static std::default_random_engine rnd_engine;
 
 static simgrid::mc::RemoteSimulation* process;
 
-static uintptr_t eval_binary_operation(simgrid::dwarf::ExpressionContext const& state, int op, uintptr_t a, uintptr_t b)
+static uintptr_t eval_binary_operation(simgrid::dwarf::ExpressionContext const& state, uint8_t op, uintptr_t a,
+                                       uintptr_t b)
 {
   Dwarf_Op ops[15];
   ops[0].atom = DW_OP_const8u;
index 7604ded..fb0be79 100644 (file)
@@ -310,9 +310,9 @@ static void run_test(const std::string& chooser)
     XBT_INFO("### Put a VM on a PM, put one task to the PM and three tasks to the VM");
     vm0 = new simgrid::s4u::VirtualMachine("VM0", pm2, 2);
     run_test_process("( [ooo]2 X )2", pm2, flop_amount * 2 / 3);
-    run_test_process("( [Xoo]2 o )2", vm0, flop_amount * (2. / 3 * 2) / 3); // VM_share/3
-    run_test_process("( [oXo]2 o )2", vm0, flop_amount * (2. / 3 * 2) / 3); // VM_share/3
-    run_test_process("( [ooX]2 o )2", vm0, flop_amount * (2. / 3 * 2) / 3); // VM_share/3
+    run_test_process("( [Xoo]2 o )2", vm0, (flop_amount * 4 / 3) / 3); // VM_share/3
+    run_test_process("( [oXo]2 o )2", vm0, (flop_amount * 4 / 3) / 3); // VM_share/3
+    run_test_process("( [ooX]2 o )2", vm0, (flop_amount * 4 / 3) / 3); // VM_share/3
     simgrid::s4u::this_actor::sleep_for(2);
     test_energy_consumption(chooser,2);
     vm0->destroy();
@@ -480,9 +480,9 @@ static void run_test(const std::string& chooser)
   } else if (chooser == "( [ooo]2 ooo )4") {
     XBT_INFO("### Put a VM on a PM, and put three tasks to the PM and three tasks to the VM");
     vm0 = new simgrid::s4u::VirtualMachine("VM0", pm4, 2);
-    run_test_process("( [Xoo]2 ooo )4", vm0, flop_amount * (8. / 5) * 1 / 3); // The VM has 8/5 of the PM
-    run_test_process("( [oXo]2 ooo )4", vm0, flop_amount * (8. / 5) * 1 / 3);
-    run_test_process("( [ooX]2 ooo )4", vm0, flop_amount * (8. / 5) * 1 / 3);
+    run_test_process("( [Xoo]2 ooo )4", vm0, (flop_amount * 8 / 5) / 3); // The VM has 8/5 of the PM
+    run_test_process("( [oXo]2 ooo )4", vm0, (flop_amount * 8 / 5) / 3);
+    run_test_process("( [ooX]2 ooo )4", vm0, (flop_amount * 8 / 5) / 3);
 
     run_test_process("( [ooo]2 Xoo )4", pm4, flop_amount * 4 / 5);
     run_test_process("( [ooo]2 oXo )4", pm4, flop_amount * 4 / 5);
index 5edb401..7a69756 100644 (file)
@@ -10,7 +10,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u test");
 static void host()
 {
   simgrid::s4u::Disk* disk = simgrid::s4u::this_actor::get_host()->get_disks().front(); // Disk1
-  int id                   = simgrid::s4u::this_actor::get_pid();
+  int id                   = static_cast<int>(simgrid::s4u::this_actor::get_pid());
   XBT_INFO("process %d is writing!", id);
   disk->write(4000000);
   XBT_INFO("process %d goes to sleep for %d seconds", id, id);
index a607ed6..0367a74 100644 (file)
@@ -24,7 +24,7 @@ int main(int argc, char** argv)
   e.load_platform(argv[1]);
 
   std::vector<simgrid::s4u::Host*> hosts = e.get_all_hosts();
-  int host_count                         = e.get_host_count();
+  int host_count                         = static_cast<int>(e.get_host_count());
 
   /* Random number initialization */
   simgrid::xbt::random::set_mersenne_seed(static_cast<int>(xbt_os_time()));
index 8620544..9cf7848 100644 (file)
@@ -9,9 +9,9 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this msg example")
 
 static void sendpid()
 {
-  simgrid::s4u::Mailbox* mailbox   = simgrid::s4u::Mailbox::by_name("mailbox");
-  int pid                          = simgrid::s4u::this_actor::get_pid();
-  double comm_size                 = 100000;
+  simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("mailbox");
+  int pid                        = static_cast<int>(simgrid::s4u::this_actor::get_pid());
+  long comm_size                 = 100000;
   simgrid::s4u::this_actor::on_exit([pid](bool /*failed*/) { XBT_INFO("Process \"%d\" killed.", pid); });
 
   XBT_INFO("Sending pid of \"%d\".", pid);
index 6e18fe0..e0a01e4 100644 (file)
@@ -42,7 +42,7 @@ static void create_environment(xbt_os_timer_t parse_time, const char *platformFi
 
 static void dump_hosts()
 {
-  unsigned int totalHosts = sg_host_count();
+  unsigned int totalHosts = static_cast<unsigned int>(sg_host_count());
   sg_host_t* hosts        = sg_host_list();
   std::sort(hosts, hosts + totalHosts,
             [](const_sg_host_t a, const_sg_host_t b) { return strcmp(sg_host_get_name(a), sg_host_get_name(b)) < 0; });
@@ -110,7 +110,7 @@ static void dump_routers()
 
 static void dump_routes()
 {
-  unsigned int totalHosts = sg_host_count();
+  unsigned int totalHosts = static_cast<unsigned int>(sg_host_count());
   sg_host_t* hosts        = sg_host_list();
   std::sort(hosts, hosts + totalHosts,
             [](const_sg_host_t a, const_sg_host_t b) { return strcmp(sg_host_get_name(a), sg_host_get_name(b)) < 0; });
index a1257d3..9ecc8e5 100644 (file)
@@ -147,7 +147,7 @@ static void test3()
   /* Link constraints and variables */
   for (int i = 0; i < 15; i++)
     for (int j = 0; j < 16; j++)
-      if (A[i][j])
+      if (A[i][j] != 0.0)
         Sys->expand(tmp_cnst[i], tmp_var[j], 1.0);
 
   Sys->solve();
index e2d1d9f..6242ceb 100644 (file)
@@ -19,7 +19,7 @@
 double date;
 
 static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limit, unsigned int pw_max_limit,
-                 float rate_no_limit, int max_share, int mode)
+                 double rate_no_limit, int max_share, int mode)
 {
   simgrid::kernel::lmm::Constraint** cnst = new simgrid::kernel::lmm::Constraint*[nb_cnst];
   simgrid::kernel::lmm::Variable** var = new simgrid::kernel::lmm::Variable*[nb_var];
@@ -44,7 +44,7 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi
   for (int i = 0; i < nb_var; i++) {
     var[i] = Sys->variable_new(NULL, 1.0, -1.0, nb_elem);
     //Have a few variables with a concurrency share of two (e.g. cross-traffic in some cases)
-    int concurrency_share = 1 + simgrid::xbt::random::uniform_int(0, max_share - 1);
+    short concurrency_share = static_cast<short>(1 + simgrid::xbt::random::uniform_int(0, max_share - 1));
     var[i]->set_concurrency_share(concurrency_share);
 
     for (int j = 0; j < nb_cnst; j++)
@@ -105,9 +105,9 @@ int main(int argc, char **argv)
 {
   simgrid::s4u::Engine e(&argc, argv);
 
-  float rate_no_limit=0.2;
-  float acc_date=0;
-  float acc_date2=0;
+  double rate_no_limit = 0.2;
+  double acc_date      = 0.0;
+  double acc_date2     = 0.0;
   int testclass;
 
   if(argc<3) {
@@ -167,8 +167,8 @@ int main(int argc, char **argv)
     acc_date2+=date*date;
   }
 
-  float mean_date= acc_date/(float)testcount;
-  float stdev_date= sqrt(acc_date2/(float)testcount-mean_date*mean_date);
+  double mean_date  = acc_date / static_cast<double>(testcount);
+  double stdev_date = sqrt(acc_date2 / static_cast<double>(testcount) - mean_date * mean_date);
 
   fprintf(stderr, "%ix One shot execution time for a total of %u constraints, "
                   "%u variables with %u active constraint each, concurrency in [%i,%i] and max concurrency share %u\n",
index c57a9b1..789ee42 100644 (file)
@@ -128,7 +128,7 @@ int main(int argc, char* argv[])
   }
   timeout = atof(argv[2]);
   if (argc == 4)
-    modes = strtol(argv[2], NULL, 0);
+    modes = static_cast<unsigned>(strtoul(argv[2], NULL, 0));
 
   XBT_INFO("Parmap benchmark with %d workers (modes = %#x)...", nthreads, modes);
   XBT_INFO("%s", "");
index 30da8b5..3da1c4a 100644 (file)
@@ -75,7 +75,7 @@ static int test_parmap_extended(e_xbt_parmap_mode_t mode)
     parmap.apply(fun_get_id, data);
 
     std::sort(begin(a), end(a));
-    unsigned count = std::distance(begin(a), std::unique(begin(a), end(a)));
+    unsigned count = static_cast<unsigned>(std::distance(begin(a), std::unique(begin(a), end(a))));
     if (count != num_workers) {
       XBT_CRITICAL("only %u/%u threads did some work", count, num_workers);
       ret = 1;