From c4081e3a628c6ab697d7958f3f22bdf788c0c13c Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 14 Jun 2017 08:57:05 +0200 Subject: [PATCH 1/1] please both sonar and codacy --- contrib/benchmarking_code_block/inject.h | 259 +++++++++--------- examples/simdag/scheduling/sd_scheduling.c | 8 +- include/simgrid/s4u/File.hpp | 2 - include/xbt/exception.hpp | 3 +- include/xbt/string.hpp | 9 +- src/mc/AddressSpace.hpp | 4 +- src/mc/LocationList.hpp | 8 +- src/mc/VisitedState.hpp | 2 +- src/mc/checker/Checker.hpp | 2 +- .../CommunicationDeterminismChecker.hpp | 2 +- src/mc/checker/LivenessChecker.hpp | 2 +- src/smpi/smpi_topo.hpp | 2 +- 12 files changed, 140 insertions(+), 163 deletions(-) diff --git a/contrib/benchmarking_code_block/inject.h b/contrib/benchmarking_code_block/inject.h index 57e2c8291b..c171b0925c 100644 --- a/contrib/benchmarking_code_block/inject.h +++ b/contrib/benchmarking_code_block/inject.h @@ -30,12 +30,12 @@ * 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__ diff --git a/examples/simdag/scheduling/sd_scheduling.c b/examples/simdag/scheduling/sd_scheduling.c index 870583652f..bb53f2b888 100644 --- a/examples/simdag/scheduling/sd_scheduling.c +++ b/examples/simdag/scheduling/sd_scheduling.c @@ -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; diff --git a/include/simgrid/s4u/File.hpp b/include/simgrid/s4u/File.hpp index 885509e520..278081f2db 100644 --- a/include/simgrid/s4u/File.hpp +++ b/include/simgrid/s4u/File.hpp @@ -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. diff --git a/include/xbt/exception.hpp b/include/xbt/exception.hpp index 511f47a3ac..6e801981d2 100644 --- a/include/xbt/exception.hpp +++ b/include/xbt/exception.hpp @@ -43,8 +43,7 @@ typedef std::vector 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; diff --git a/include/xbt/string.hpp b/include/xbt/string.hpp index 9343ce600d..f37e189074 100644 --- a/include/xbt/string.hpp +++ b/include/xbt/string.hpp @@ -89,7 +89,7 @@ public: } } string() : string (const_cast(&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(&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(); } diff --git a/src/mc/AddressSpace.hpp b/src/mc/AddressSpace.hpp index 050650c0c9..c4985e286f 100644 --- a/src/mc/AddressSpace.hpp +++ b/src/mc/AddressSpace.hpp @@ -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 diff --git a/src/mc/LocationList.hpp b/src/mc/LocationList.hpp index da1af221ce..01b695d21c 100644 --- a/src/mc/LocationList.hpp +++ b/src/mc/LocationList.hpp @@ -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; } diff --git a/src/mc/VisitedState.hpp b/src/mc/VisitedState.hpp index 3ac5e7b15f..3665060744 100644 --- a/src/mc/VisitedState.hpp +++ b/src/mc/VisitedState.hpp @@ -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(); }; diff --git a/src/mc/checker/Checker.hpp b/src/mc/checker/Checker.hpp index 3b7079f7b3..ce27ab2f43 100644 --- a/src/mc/checker/Checker.hpp +++ b/src/mc/checker/Checker.hpp @@ -34,7 +34,7 @@ namespace mc { class Checker { Session* session_; public: - Checker(Session& session); + explicit Checker(Session& session); // No copy: Checker(Checker const&) = delete; diff --git a/src/mc/checker/CommunicationDeterminismChecker.hpp b/src/mc/checker/CommunicationDeterminismChecker.hpp index f14abb171b..aa07b43554 100644 --- a/src/mc/checker/CommunicationDeterminismChecker.hpp +++ b/src/mc/checker/CommunicationDeterminismChecker.hpp @@ -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; diff --git a/src/mc/checker/LivenessChecker.hpp b/src/mc/checker/LivenessChecker.hpp index f57a1ff7d2..2722fc5a37 100644 --- a/src/mc/checker/LivenessChecker.hpp +++ b/src/mc/checker/LivenessChecker.hpp @@ -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; diff --git a/src/smpi/smpi_topo.hpp b/src/smpi/smpi_topo.hpp index 9e419cf1dc..dc04e4451d 100644 --- a/src/smpi/smpi_topo.hpp +++ b/src/smpi/smpi_topo.hpp @@ -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) ; -- 2.20.1