Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please both sonar and codacy
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 14 Jun 2017 06:57:05 +0000 (08:57 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 14 Jun 2017 06:57:05 +0000 (08:57 +0200)
12 files changed:
contrib/benchmarking_code_block/inject.h
examples/simdag/scheduling/sd_scheduling.c
include/simgrid/s4u/File.hpp
include/xbt/exception.hpp
include/xbt/string.hpp
src/mc/AddressSpace.hpp
src/mc/LocationList.hpp
src/mc/VisitedState.hpp
src/mc/checker/Checker.hpp
src/mc/checker/CommunicationDeterminismChecker.hpp
src/mc/checker/LivenessChecker.hpp
src/smpi/smpi_topo.hpp

index 57e2c82..c171b09 100644 (file)
  * Histogram entry for each measured block
  * Each entry is guarded inside xbt dictionary which is read from the file */
 typedef struct xbt_hist {
-       int n;
-       int counts;
-       double mean;
-       double *breaks;
-       double *percentage;
-       char* block_id;
+  int n;
+  int counts;
+  double mean;
+  double* breaks;
+  double* percentage;
+  char* block_id;
 } xbt_hist_t;
 
 extern RngStream get_randgen(void);
@@ -54,159 +54,144 @@ static inline double xbt_hist_time(char *key);
 /* Initializing xbt dictionary for SMPI version, reading xbt_hist_t entries line by line */
 static inline void xbt_inject_init(char *inputfile)
 {
-       xbt_dict_t mydict = get_dict();
-       FILE* fpInput = fopen(inputfile, "r");
-       if (fpInput == NULL)
-               printf("Error while opening the inputfile");
-       fseek(fpInput, 0, 0);
-
-       char line[200];
-       char *key;
-       int i;
-       xbt_hist_t* data;
-
-       if (fgets(line, 200, fpInput) == NULL)
-               printf("Error input file is empty!");//Skipping first row
-       while (fgets(line, 200, fpInput) != NULL)
-       {
-               key = strtok(line, "\t");
-
-               data = xbt_dict_get_or_null(mydict, key);
-               if (data)
-                       printf("Error, data with that block_id already exists!");
-
-               data = (xbt_hist_t *) xbt_new(xbt_hist_t, 1);
-
-               data->block_id = key;
-               data->counts = atoi(strtok(NULL, "\t"));
-               data->mean = atof(strtok(NULL, "\t"));
-               data->n = atoi(strtok(NULL, "\t"));
-
-               data->breaks = (double*) malloc(sizeof(double) * data->n);
-               data->percentage = (double*) malloc(sizeof(double) * (data->n - 1));
-               for (i = 0; i < data->n; i++)
-                       data->breaks[i] = atof(strtok(NULL, "\t"));
-               for (i = 0; i < (data->n - 1); i++)
-                       data->percentage[i] = atof(strtok(NULL, "\t"));
-
-               xbt_dict_set(mydict, key, data, NULL);
-       }
+  xbt_dict_t mydict = get_dict();
+  FILE* fpInput     = fopen(inputfile, "r");
+  if (fpInput == NULL)
+    printf("Error while opening the inputfile");
+  fseek(fpInput, 0, 0);
+
+  char line[200];
+  char* key;
+
+  if (fgets(line, 200, fpInput) == NULL)
+    printf("Error input file is empty!"); // Skipping first row
+  while (fgets(line, 200, fpInput) != NULL) {
+    key = strtok(line, "\t");
+
+    xbt_hist_t* data = xbt_dict_get_or_null(mydict, key);
+    if (data)
+      printf("Error, data with that block_id already exists!");
+
+    data = (xbt_hist_t*)xbt_new(xbt_hist_t, 1);
+
+    data->block_id = key;
+    data->counts   = atoi(strtok(NULL, "\t"));
+    data->mean     = atof(strtok(NULL, "\t"));
+    data->n        = atoi(strtok(NULL, "\t"));
+
+    data->breaks     = (double*)malloc(sizeof(double) * data->n);
+    data->percentage = (double*)malloc(sizeof(double) * (data->n - 1));
+    for (int i        = 0; i < data->n; i++)
+      data->breaks[i] = atof(strtok(NULL, "\t"));
+    for (int i            = 0; i < (data->n - 1); i++)
+      data->percentage[i] = atof(strtok(NULL, "\t"));
+
+    xbt_dict_set(mydict, key, data, NULL);
+  }
+  fclose(fInput);
 }
 
 /* Initializing xbt dictionary for StarPU version, reading xbt_hist_t entries line by line */
 static inline void inject_init_starpu(char *inputfile, xbt_dict_t *dict, RngStream *rng)
 {
-       *dict = xbt_dict_new_homogeneous(free);
-       *rng = RngStream_CreateStream("Randgen1");
-       unsigned long seed[] = {134, 233445, 865, 2634, 424242, 876541};
-       RngStream_SetSeed(*rng, seed);
-
-       xbt_dict_t mydict = *dict;
-       mydict = *dict;
-       FILE* fpInput = fopen(inputfile, "r");
-       if (fpInput == NULL)
-       {
-               printf("Error while opening the inputfile");
-               return;
-       }
-
-       fseek(fpInput, 0, 0);
-
-       char line[MAX_LINE_INJ];
-       char *key;
-       int i;
-       xbt_hist_t* data;
-
-       if (fgets(line, MAX_LINE_INJ, fpInput) == NULL)
-       {
-               printf("Error input file is empty!");//Skipping first row
-               return;
-       }
-
-
-       while (fgets(line, MAX_LINE_INJ, fpInput) != NULL)
-       {
-               key = strtok(line, "\t");
-
-               data = xbt_dict_get_or_null(mydict, key);
-               if (data)
-                       printf("Error, data with that block_id already exists!");
-
-               data = (xbt_hist_t *) xbt_new(xbt_hist_t, 1);
-               data->block_id = key;
-               data->counts = atoi(strtok(NULL, "\t"));
-               data->mean = atof(strtok(NULL, "\t"));
-               data->n = atoi(strtok(NULL, "\t"));
-               data->breaks = (double*) malloc(sizeof(double) * data->n);
-               data->percentage = (double*) malloc(sizeof(double) * (data->n - 1));
-
-               for (i = 0; i < data->n; i++)
-                       data->breaks[i] = atof(strtok(NULL, "\t"));
-                       for (i = 0; i < (data->n - 1); i++)
-                       {
-                               data->percentage[i] = atof(strtok(NULL, "\t"));
-                       }
-
-               xbt_dict_set(mydict, key, data, NULL);
-       }
+  *dict                = xbt_dict_new_homogeneous(free);
+  *rng                 = RngStream_CreateStream("Randgen1");
+  unsigned long seed[] = {134, 233445, 865, 2634, 424242, 876541};
+  RngStream_SetSeed(*rng, seed);
+
+  xbt_dict_t mydict = *dict;
+  FILE* fpInput     = fopen(inputfile, "r");
+  if (fpInput == NULL) {
+    printf("Error while opening the inputfile");
+    return;
+  }
+
+  fseek(fpInput, 0, 0);
+
+  char line[MAX_LINE_INJ];
+  char* key;
+
+  if (fgets(line, MAX_LINE_INJ, fpInput) == NULL) {
+    printf("Error input file is empty!"); // Skipping first row
+    return;
+  }
+
+  while (fgets(line, MAX_LINE_INJ, fpInput) != NULL) {
+    key = strtok(line, "\t");
+
+    xbt_hist_t* data = xbt_dict_get_or_null(mydict, key);
+    if (data)
+      printf("Error, data with that block_id already exists!");
+
+    data             = (xbt_hist_t*)xbt_new(xbt_hist_t, 1);
+    data->block_id   = key;
+    data->counts     = atoi(strtok(NULL, "\t"));
+    data->mean       = atof(strtok(NULL, "\t"));
+    data->n          = atoi(strtok(NULL, "\t"));
+    data->breaks     = (double*)malloc(sizeof(double) * data->n);
+    data->percentage = (double*)malloc(sizeof(double) * (data->n - 1));
+
+    for (int i        = 0; i < data->n; i++)
+      data->breaks[i] = atof(strtok(NULL, "\t"));
+    for (int i = 0; i < (data->n - 1); i++) {
+      data->percentage[i] = atof(strtok(NULL, "\t"));
+    }
+
+    xbt_dict_set(mydict, key, data, NULL);
+  }
+  fclose(fInput);
 }
 
 /* Injecting time */
 static inline double xbt_inject_time(char *key)
 {
-       return xbt_hist_time(key);
-       //return xbt_mean_time(key);
+  return xbt_hist_time(key);
+  // return xbt_mean_time(key);
 }
 
 /* Injecting mean value */
 static inline double xbt_mean_time(char *key)
 {
-       xbt_dict_t mydict = get_dict();
-       xbt_hist_t* data = xbt_dict_get_or_null(mydict, key);
+  xbt_dict_t mydict = get_dict();
+  xbt_hist_t* data  = xbt_dict_get_or_null(mydict, key);
 
-       if (!data)
-       {
-         printf("Warning: element with specified key does not exist (%s)\n",key);
-         return 0;
-       }
+  if (!data) {
+    printf("Warning: element with specified key does not exist (%s)\n", key);
+    return 0;
+  }
 
-       return data->mean;
+  return data->mean;
 }
 
 /* Injecting random value from the histogram */
 static inline double xbt_hist_time(char *key)
 {
-       int i, k = 0;
-       double left = 0, right = 1;
-       double timer = 0;
-       RngStream rng_stream;
-       double r, r2;
-
-       xbt_dict_t mydict = get_dict();
-       xbt_hist_t* data = xbt_dict_get_or_null(mydict, key);
-
-       if (!data)
-               {
-                 printf("Warning: element with specified key does not exist (%s)\n",key);
-                 return 0;
-               }
-
-       /* Choosing random interval of the histogram */
-       rng_stream = get_randgen();
-       r = RngStream_RandU01(rng_stream);
-       for (i = 0; i < (data->n - 1); i++)
-       {
-               left += (i == 0) ? 0 : data->percentage[i - 1];
-               right += data->percentage[i];
-               if (left < r && r <= right)
-                       k = i;
-       }
-
-       /* Choosing random value inside the interval of the histogram */
-       r2 = RngStream_RandU01(rng_stream);
-       timer = data->breaks[k] + r2 * (data->breaks[k + 1] - data->breaks[k]);
-
-       return timer;
+  xbt_dict_t mydict = get_dict();
+  xbt_hist_t* data  = xbt_dict_get_or_null(mydict, key);
+
+  if (!data) {
+    printf("Warning: element with specified key does not exist (%s)\n", key);
+    return 0;
+  }
+
+  /* Choosing random interval of the histogram */
+  RngStream rng_stream = get_randgen();
+  double r             = RngStream_RandU01(rng_stream);
+  int k                = 0;
+  double left          = 0;
+  double right         = 1;
+  for (int i = 0; i < (data->n - 1); i++) {
+    left += (i == 0) ? 0 : data->percentage[i - 1];
+    right += data->percentage[i];
+    if (left < r && r <= right)
+      k = i;
+  }
+
+  /* Choosing random value inside the interval of the histogram */
+  double r2    = RngStream_RandU01(rng_stream);
+  double timer = data->breaks[k] + r2 * (data->breaks[k + 1] - data->breaks[k]);
+
+  return timer;
 }
 
 #endif // __INJECT_H__
index 8705836..bb53f2b 100644 (file)
@@ -65,14 +65,14 @@ static xbt_dynar_t get_ready_tasks(xbt_dynar_t dax)
 static double finish_on_at(SD_task_t task, sg_host_t host)
 {
   double result;
-  unsigned int i;
-  double data_available = 0.;
-  double redist_time = 0;
-  double last_data_available;
 
   xbt_dynar_t parents = SD_task_get_parents(task);
 
   if (!xbt_dynar_is_empty(parents)) {
+    unsigned int i;
+    double data_available = 0.;
+    double redist_time    = 0;
+    double last_data_available;
     /* compute last_data_available */
     SD_task_t parent;
     last_data_available = -1.0;
index 885509e..278081f 100644 (file)
@@ -14,8 +14,6 @@
 namespace simgrid {
 namespace s4u {
 
-class Storage;
-
 /** @brief A simulated file
  *
  * Used to simulate the time it takes to access to a file, but does not really store any information.
index 511f47a..6e80198 100644 (file)
@@ -43,8 +43,7 @@ typedef std::vector<xbt_backtrace_location_t> Backtrace;
 class ThrowPoint {
  public:
   ThrowPoint() = default;
-  ThrowPoint(const char* file, int line, const char* function) :
-    file(file), line(line), function(function) {}
+  explicit ThrowPoint(const char* file, int line, const char* function) : file(file), line(line), function(function) {}
   const char* file = nullptr;
   int line = 0;
   const char* function = nullptr;
index 9343ce6..f37e189 100644 (file)
@@ -89,7 +89,7 @@ public:
     }
   }
   string() : string (const_cast<char*>(&NUL), 0) {}
-  string(const char* s) : string(s, strlen(s)) {}
+  explicit string(const char* s) : string(s, strlen(s)) {}
   string(string const& s) : string(s.c_str(), s.size()) {}
   string(string&& s)
   {
@@ -98,7 +98,7 @@ public:
     s.string_data::len = 0;
     s.string_data::data = const_cast<char*>(&NUL);
   }
-  string(std::string const& s) : string(s.c_str(), s.size()) {}
+  explicit string(std::string const& s) : string(s.c_str(), s.size()) {}
 
   // Assign
   void assign(const char* s, size_t size)
@@ -165,10 +165,7 @@ public:
     return data()[i];
   }
   // Conversion
-  operator std::string() const
-  {
-    return std::string(this->c_str(), this->size());
-  }
+  explicit operator std::string() const { return std::string(this->c_str(), this->size()); }
 
   // Iterators
   iterator begin()               { return data(); }
index 050650c..c4985e2 100644 (file)
@@ -50,7 +50,7 @@ class ReadOptions {
 public:
   constexpr ReadOptions() : value_(0) {}
 
-  constexpr operator bool() const { return value_ != 0; }
+  explicit constexpr operator bool() const { return value_ != 0; }
   constexpr bool operator!() const { return value_ == 0; }
 
   constexpr ReadOptions operator|(ReadOptions const& that) const
@@ -111,7 +111,7 @@ class AddressSpace {
 private:
   Process* process_;
 public:
-  AddressSpace(Process* process) : process_(process) {}
+  explicit AddressSpace(Process* process) : process_(process) {}
   virtual ~AddressSpace() = default;
 
   /** The process of this addres space
index da1af22..01b695d 100644 (file)
@@ -38,8 +38,7 @@ public:
   LocationListEntry(DwarfExpression expression, range_type range)
     : expression_(std::move(expression)), range_(range)
   {}
-  LocationListEntry(DwarfExpression expression)
-    : expression_(std::move(expression)), range_({0, UINT64_MAX})
+  explicit LocationListEntry(DwarfExpression expression) : expression_(std::move(expression)), range_({0, UINT64_MAX})
   {}
 
   DwarfExpression& expression()
@@ -67,9 +66,8 @@ private:
   void* memory_;
   int register_id_;
 public:
-  Location(void* x) :memory_(x) {}
-  Location(int register_id) :
-    memory_(nullptr), register_id_(register_id) {}
+  explicit Location(void* x) : memory_(x) {}
+  explicit Location(int register_id) : memory_(nullptr), register_id_(register_id) {}
   // Type of location:
   bool in_register() const { return memory_ == nullptr; }
   bool in_memory()   const { return memory_ != nullptr; }
index 3ac5e7b..3665060 100644 (file)
@@ -24,7 +24,7 @@ struct XBT_PRIVATE VisitedState {
   int num          = 0; // unique id of that state in the storage of all stored IDs
   int original_num = 0; // num field of the VisitedState to which I was declared equal to (used for dot_output)
 
-  VisitedState(unsigned long state_number);
+  explicit VisitedState(unsigned long state_number);
   ~VisitedState();
 };
 
index 3b7079f..ce27ab2 100644 (file)
@@ -34,7 +34,7 @@ namespace mc {
 class Checker {
   Session* session_;
 public:
-  Checker(Session& session);
+  explicit Checker(Session& session);
 
   // No copy:
   Checker(Checker const&) = delete;
index f14abb1..aa07b43 100644 (file)
@@ -22,7 +22,7 @@ namespace mc {
 
 class XBT_PRIVATE CommunicationDeterminismChecker : public Checker {
 public:
-  CommunicationDeterminismChecker(Session& session);
+  explicit CommunicationDeterminismChecker(Session& session);
   ~CommunicationDeterminismChecker();
   void run() override;
   RecordTrace getRecordTrace() override;
index f57a1ff..2722fc5 100644 (file)
@@ -37,7 +37,7 @@ struct XBT_PRIVATE Pair {
   int depth = 0;
   bool exploration_started = false;
 
-  Pair(unsigned long expanded_pairs);
+  explicit Pair(unsigned long expanded_pairs);
   ~Pair() = default;
 
   Pair(Pair const&) = delete;
index 9e419cf..dc04e44 100644 (file)
@@ -37,7 +37,7 @@ class Topo_Cart: public Topo {
     int *periodic_;
     int *position_;
   public:
-    Topo_Cart(int ndims);
+    explicit Topo_Cart(int ndims);
     ~Topo_Cart();
     Topo_Cart(MPI_Comm comm_old, int ndims, int dims[], int periods[], int reorder, MPI_Comm *comm_cart);
     Topo_Cart* sub(const int remain_dims[], MPI_Comm *newcomm) ;