From ab4a25d79a9621a8732588406fdbe922a458ef5b Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 3 Jun 2017 22:09:37 +0200 Subject: [PATCH] please codacy a bit --- src/simgrid/sg_config.cpp | 129 ++++++++++--------- src/smpi/smpi_datatype.cpp | 3 +- src/xbt/backtrace_linux.cpp | 3 +- src/xbt/dynar.cpp | 13 +- src/xbt/parmap.cpp | 3 +- teshsuite/surf/maxmin_bench/maxmin_bench.cpp | 3 +- teshsuite/surf/surf_usage/surf_usage.cpp | 4 +- 7 files changed, 76 insertions(+), 82 deletions(-) diff --git a/src/simgrid/sg_config.cpp b/src/simgrid/sg_config.cpp index 8aa0849048..e617c48091 100644 --- a/src/simgrid/sg_config.cpp +++ b/src/simgrid/sg_config.cpp @@ -295,84 +295,92 @@ void sg_config_init(int *argc, char **argv) char description[descsize]; /* Create the configuration support */ - if (_sg_cfg_init_status == 0) { /* Only create stuff if not already inited */ + if (_sg_cfg_init_status != 0) { /* Only create stuff if not already inited */ + XBT_WARN("Call to sg_config_init() after initialization ignored"); + return; + } - /* Plugins configuration */ - describe_model(description,descsize, surf_plugin_description, "plugin", "The plugins"); - xbt_cfg_register_string("plugin", nullptr, &_sg_cfg_cb__plugin, description); + /* Plugins configuration */ + describe_model(description, descsize, surf_plugin_description, "plugin", "The plugins"); + xbt_cfg_register_string("plugin", nullptr, &_sg_cfg_cb__plugin, description); - describe_model(description,descsize, surf_cpu_model_description, "model", "The model to use for the CPU"); - xbt_cfg_register_string("cpu/model", "Cas01", &_sg_cfg_cb__cpu_model, description); + describe_model(description, descsize, surf_cpu_model_description, "model", "The model to use for the CPU"); + xbt_cfg_register_string("cpu/model", "Cas01", &_sg_cfg_cb__cpu_model, description); - describe_model(description,descsize, surf_optimization_mode_description, "optimization mode", "The optimization modes to use for the CPU"); - xbt_cfg_register_string("cpu/optim", "Lazy", &_sg_cfg_cb__optimization_mode, description); + describe_model(description, descsize, surf_optimization_mode_description, "optimization mode", + "The optimization modes to use for the CPU"); + xbt_cfg_register_string("cpu/optim", "Lazy", &_sg_cfg_cb__optimization_mode, description); - describe_model(description,descsize, surf_storage_model_description, "model", "The model to use for the storage"); - xbt_cfg_register_string("storage/model", "default", &_sg_cfg_cb__storage_mode, description); + describe_model(description, descsize, surf_storage_model_description, "model", "The model to use for the storage"); + xbt_cfg_register_string("storage/model", "default", &_sg_cfg_cb__storage_mode, description); - describe_model(description,descsize, surf_network_model_description, "model", "The model to use for the network"); - xbt_cfg_register_string("network/model", "LV08", &_sg_cfg_cb__network_model, description); + describe_model(description, descsize, surf_network_model_description, "model", "The model to use for the network"); + xbt_cfg_register_string("network/model", "LV08", &_sg_cfg_cb__network_model, description); - describe_model(description,descsize, surf_optimization_mode_description, "optimization mode", "The optimization modes to use for the network"); - xbt_cfg_register_string("network/optim", "Lazy", &_sg_cfg_cb__optimization_mode, description); + describe_model(description, descsize, surf_optimization_mode_description, "optimization mode", + "The optimization modes to use for the network"); + xbt_cfg_register_string("network/optim", "Lazy", &_sg_cfg_cb__optimization_mode, description); - describe_model(description,descsize, surf_host_model_description, "model", "The model to use for the host"); - xbt_cfg_register_string("host/model", "default", &_sg_cfg_cb__host_model, description); + describe_model(description, descsize, surf_host_model_description, "model", "The model to use for the host"); + xbt_cfg_register_string("host/model", "default", &_sg_cfg_cb__host_model, description); - sg_tcp_gamma = 4194304.0; - simgrid::config::bindFlag(sg_tcp_gamma, { "network/TCP-gamma", "network/TCP_gamma" }, - "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; Use the last given value, which is the max window size)"); + sg_tcp_gamma = 4194304.0; + simgrid::config::bindFlag(sg_tcp_gamma, {"network/TCP-gamma", "network/TCP_gamma"}, + "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; " + "Use the last given value, which is the max window size)"); - simgrid::config::bindFlag(sg_surf_precision, "surf/precision", - "Numerical precision used when updating simulation times (in seconds)"); + simgrid::config::bindFlag(sg_surf_precision, "surf/precision", + "Numerical precision used when updating simulation times (in seconds)"); - simgrid::config::bindFlag(sg_maxmin_precision, "maxmin/precision", - "Numerical precision used when computing resource sharing (in flops/sec or bytes/sec)"); + simgrid::config::bindFlag(sg_maxmin_precision, "maxmin/precision", + "Numerical precision used when computing resource sharing (in flops/sec or bytes/sec)"); - simgrid::config::bindFlag(sg_concurrency_limit, "maxmin/concurrency-limit", - "Maximum number of concurrent variables in the maxmim system. Also limits the number of " - "processes on each host, at higher level. (default: -1 means no such limitation)"); - xbt_cfg_register_alias("maxmin/concurrency-limit", "maxmin/concurrency_limit"); + simgrid::config::bindFlag(sg_concurrency_limit, "maxmin/concurrency-limit", + "Maximum number of concurrent variables in the maxmim system. Also limits the number of " + "processes on each host, at higher level. (default: -1 means no such limitation)"); + xbt_cfg_register_alias("maxmin/concurrency-limit", "maxmin/concurrency_limit"); - /* The parameters of network models */ + /* The parameters of network models */ - // real default for "network/sender-gap" is set in network_smpi.cpp: - sg_sender_gap = NAN; - simgrid::config::bindFlag(sg_sender_gap, { "network/sender-gap", "network/sender_gap" }, - "Minimum gap between two overlapping sends"); + // real default for "network/sender-gap" is set in network_smpi.cpp: + sg_sender_gap = NAN; + simgrid::config::bindFlag(sg_sender_gap, {"network/sender-gap", "network/sender_gap"}, + "Minimum gap between two overlapping sends"); - sg_latency_factor = 1.0; - simgrid::config::bindFlag(sg_latency_factor, { "network/latency-factor", "network/latency_factor" }, - "Correction factor to apply to the provided latency (default value set by network model)"); + sg_latency_factor = 1.0; + simgrid::config::bindFlag(sg_latency_factor, {"network/latency-factor", "network/latency_factor"}, + "Correction factor to apply to the provided latency (default value set by network model)"); - sg_bandwidth_factor = 1.0; - simgrid::config::bindFlag(sg_bandwidth_factor, { "network/bandwidth-factor", "network/bandwidth_factor" }, + sg_bandwidth_factor = 1.0; + simgrid::config::bindFlag( + sg_bandwidth_factor, {"network/bandwidth-factor", "network/bandwidth_factor"}, "Correction factor to apply to the provided bandwidth (default value set by network model)"); - // real default for "network/weight-S" is set in network_*.cpp: - sg_weight_S_parameter = NAN; - simgrid::config::bindFlag(sg_weight_S_parameter, { "network/weight-S", "network/weight_S" }, + // real default for "network/weight-S" is set in network_*.cpp: + sg_weight_S_parameter = NAN; + simgrid::config::bindFlag( + sg_weight_S_parameter, {"network/weight-S", "network/weight_S"}, "Correction factor to apply to the weight of competing streams (default value set by network model)"); - /* Inclusion path */ - simgrid::config::declareFlag("path", - "Lookup path for inclusions in platform and deployment XML files", - "", - [](std::string const& path) { - if (path[0] != '\0') { - surf_path.push_back(path); - } - }); - - xbt_cfg_register_boolean("cpu/maxmin-selective-update", "no", nullptr, - "Update the constraint set propagating recursively to others constraints (off by default when optim is set to lazy)"); - xbt_cfg_register_alias("cpu/maxmin-selective-update","cpu/maxmin_selective_update"); - xbt_cfg_register_boolean("network/maxmin-selective-update", "no", nullptr, - "Update the constraint set propagating recursively to others constraints (off by default when optim is set to lazy)"); - xbt_cfg_register_alias("network/maxmin-selective-update","network/maxmin_selective_update"); - /* Replay (this part is enabled even if MC it disabled) */ - xbt_cfg_register_string("model-check/replay", nullptr, _sg_cfg_cb_model_check_replay, - "Model-check path to replay (as reported by SimGrid when a violation is reported)"); + /* Inclusion path */ + simgrid::config::declareFlag("path", "Lookup path for inclusions in platform and deployment XML files", + "", [](std::string const& path) { + if (path[0] != '\0') { + surf_path.push_back(path); + } + }); + + xbt_cfg_register_boolean("cpu/maxmin-selective-update", "no", nullptr, "Update the constraint set propagating " + "recursively to others constraints (off by " + "default when optim is set to lazy)"); + xbt_cfg_register_alias("cpu/maxmin-selective-update", "cpu/maxmin_selective_update"); + xbt_cfg_register_boolean("network/maxmin-selective-update", "no", nullptr, "Update the constraint set propagating " + "recursively to others constraints (off " + "by default when optim is set to lazy)"); + xbt_cfg_register_alias("network/maxmin-selective-update", "network/maxmin_selective_update"); + /* Replay (this part is enabled even if MC it disabled) */ + xbt_cfg_register_string("model-check/replay", nullptr, _sg_cfg_cb_model_check_replay, + "Model-check path to replay (as reported by SimGrid when a violation is reported)"); #if SIMGRID_HAVE_MC /* do model-checking-record */ @@ -568,9 +576,6 @@ void sg_config_init(int *argc, char **argv) sg_config_cmd_line(argc, argv); xbt_mallocator_initialization_is_done(SIMIX_context_is_parallel()); - } else { - XBT_WARN("Call to sg_config_init() after initialization ignored"); - } } void sg_config_finalize() diff --git a/src/smpi/smpi_datatype.cpp b/src/smpi/smpi_datatype.cpp index b5ea2341c3..4faee97a5a 100644 --- a/src/smpi/smpi_datatype.cpp +++ b/src/smpi/smpi_datatype.cpp @@ -263,7 +263,6 @@ int Datatype::unpack(void* inbuf, int insize, int* position, void* outbuf, int o int Datatype::copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype){ - int count; // FIXME Handle the case of a partial shared malloc. @@ -274,7 +273,7 @@ int Datatype::copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, if (recvcount > 0 && recvbuf != sendbuf) { sendcount *= sendtype->size(); recvcount *= recvtype->size(); - count = sendcount < recvcount ? sendcount : recvcount; + int count = sendcount < recvcount ? sendcount : recvcount; if (not(sendtype->flags() & DT_FLAG_DERIVED) && not(recvtype->flags() & DT_FLAG_DERIVED)) { if (not smpi_process()->replaying()) diff --git a/src/xbt/backtrace_linux.cpp b/src/xbt/backtrace_linux.cpp index c61c519e8b..8760a893d3 100644 --- a/src/xbt/backtrace_linux.cpp +++ b/src/xbt/backtrace_linux.cpp @@ -220,7 +220,6 @@ std::vector resolveBacktrace( char maps_buff[512]; long int offset = 0; char* p; - char* p2; int found = 0; /* let's look for the offset of this library in our addressing space */ @@ -282,7 +281,7 @@ std::vector resolveBacktrace( free(p); snprintf(line_func,3, "??"); } else { - p2 = strrchr(p, '('); + char* p2 = strrchr(p, '('); if (p2) *p2 = '\0'; p2 = strrchr(p, ' '); diff --git a/src/xbt/dynar.cpp b/src/xbt/dynar.cpp index 84ba004a4d..47300c393d 100644 --- a/src/xbt/dynar.cpp +++ b/src/xbt/dynar.cpp @@ -365,9 +365,6 @@ extern "C" void xbt_dynar_insert_at(xbt_dynar_t const dynar, const int idx, cons */ extern "C" void xbt_dynar_remove_at(xbt_dynar_t const dynar, const int idx, void* const object) { - unsigned long nb_shift; - unsigned long offset; - _sanity_check_dynar(dynar); _check_inbound_idx(dynar, idx); @@ -377,10 +374,10 @@ extern "C" void xbt_dynar_remove_at(xbt_dynar_t const dynar, const int idx, void dynar->free_f(_xbt_dynar_elm(dynar, idx)); } - nb_shift = dynar->used - 1 - idx; + unsigned long nb_shift = dynar->used - 1 - idx; if (nb_shift) { - offset = nb_shift * dynar->elmsize; + unsigned long offset = nb_shift * dynar->elmsize; memmove(_xbt_dynar_elm(dynar, idx), _xbt_dynar_elm(dynar, idx + 1), offset); } @@ -398,7 +395,6 @@ extern "C" void xbt_dynar_remove_n_at(xbt_dynar_t const dynar, const unsigned in { unsigned long nb_shift; unsigned long offset; - unsigned long cur; if (not n) return; @@ -408,7 +404,7 @@ extern "C" void xbt_dynar_remove_n_at(xbt_dynar_t const dynar, const unsigned in _check_inbound_idx(dynar, idx + n - 1); if (dynar->free_f) { - for (cur = idx; cur < idx + n; cur++) { + for (unsigned long cur = idx; cur < idx + n; cur++) { dynar->free_f(_xbt_dynar_elm(dynar, cur)); } } @@ -744,7 +740,6 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") /* Vars_decl [doxygen cruft] */ int i; unsigned int cursor; - int *iptr; xbt_test_add("==== Traverse the empty dynar"); xbt_dynar_t d = xbt_dynar_new(sizeof(int), nullptr); @@ -767,7 +762,7 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") /* 2. Traverse manually the dynar */ for (cursor = 0; cursor < NB_ELEM; cursor++) { - iptr = (int*) xbt_dynar_get_ptr(d, cursor); + int* iptr = (int*)xbt_dynar_get_ptr(d, cursor); xbt_test_assert(cursor == (unsigned int)*iptr, "The retrieved value is not the same than the injected one (%u!=%d)", cursor, *iptr); } diff --git a/src/xbt/parmap.cpp b/src/xbt/parmap.cpp index 0423149617..a0689f0c86 100644 --- a/src/xbt/parmap.cpp +++ b/src/xbt/parmap.cpp @@ -114,13 +114,12 @@ xbt_parmap_t xbt_parmap_new(unsigned int num_workers, e_xbt_parmap_mode_t mode) xbt_parmap_set_mode(parmap, mode); /* Create the pool of worker threads */ - xbt_parmap_thread_data_t data; parmap->workers[0] = nullptr; #if HAVE_PTHREAD_SETAFFINITY int core_bind = 0; #endif for (unsigned int i = 1; i < num_workers; i++) { - data = xbt_new0(s_xbt_parmap_thread_data_t, 1); + xbt_parmap_thread_data_t data = xbt_new0(s_xbt_parmap_thread_data_t, 1); data->parmap = parmap; data->worker_id = i; parmap->workers[i] = xbt_os_thread_create(nullptr, xbt_parmap_worker_main, data, nullptr); diff --git a/teshsuite/surf/maxmin_bench/maxmin_bench.cpp b/teshsuite/surf/maxmin_bench/maxmin_bench.cpp index 6dbca8c7de..e5a911a07e 100644 --- a/teshsuite/surf/maxmin_bench/maxmin_bench.cpp +++ b/teshsuite/surf/maxmin_bench/maxmin_bench.cpp @@ -41,7 +41,6 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi lmm_constraint_t cnst[nb_cnst]; lmm_variable_t var[nb_var]; int used[nb_cnst]; - int concurrency_share; lmm_system_t Sys = lmm_system_new(1); @@ -61,7 +60,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] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem); //Have a few variables with a concurrency share of two (e.g. cross-traffic in some cases) - concurrency_share=1+int_random(max_share); + int concurrency_share = 1 + int_random(max_share); lmm_variable_concurrency_share_set(var[i],concurrency_share); for (int j = 0; j < nb_cnst; j++) diff --git a/teshsuite/surf/surf_usage/surf_usage.cpp b/teshsuite/surf/surf_usage/surf_usage.cpp index 6d71570aaa..1c92988db9 100644 --- a/teshsuite/surf/surf_usage/surf_usage.cpp +++ b/teshsuite/surf/surf_usage/surf_usage.cpp @@ -31,7 +31,6 @@ static const char *string_action(simgrid::surf::Action::State state) int main(int argc, char **argv) { - double now = -1.0; surf_init(&argc, argv); /* Initialize some common structures */ xbt_cfg_set_parse("cpu/model:Cas01"); xbt_cfg_set_parse("network/model:CM02"); @@ -65,8 +64,7 @@ int main(int argc, char **argv) surf_solve(-1.0); do { simgrid::surf::ActionList *action_list = nullptr; - now = surf_get_clock(); - XBT_INFO("Next Event : %g", now); + XBT_INFO("Next Event : %g", surf_get_clock()); XBT_DEBUG("\t CPU actions"); action_list = surf_cpu_model_pm->getFailedActionSet(); -- 2.20.1