From a1077f2304c8e738c23855e33422182f4aca6d2e Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 25 Jun 2017 15:08:03 +0200 Subject: [PATCH] please codacy --- src/smpi/smpi_global.cpp | 3 +-- src/smpi/smpi_request.cpp | 7 ++++--- src/surf/lagrange.cpp | 26 +++++++++----------------- src/surf/plugins/host_energy.cpp | 2 +- src/xbt/cunit.cpp | 2 +- src/xbt/dict.cpp | 15 +++++---------- 6 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/smpi/smpi_global.cpp b/src/smpi/smpi_global.cpp index b7a827cd73..015834fee8 100644 --- a/src/smpi/smpi_global.cpp +++ b/src/smpi/smpi_global.cpp @@ -550,8 +550,6 @@ int smpi_main(const char* executable, int argc, char *argv[]) SIMIX_create_environment(argv[1]); SIMIX_comm_set_copy_data_callback(smpi_comm_copy_buffer_callback); - static std::size_t rank = 0; - smpi_init_options(); if (smpi_privatize_global_variables == SMPI_PRIVATIZE_DLOPEN) { @@ -562,6 +560,7 @@ int smpi_main(const char* executable, int argc, char *argv[]) struct stat fdin_stat; stat(executable_copy.c_str(), &fdin_stat); off_t fdin_size = fdin_stat.st_size; + static std::size_t rank = 0; simix_global->default_function = [executable_copy, fdin_size](std::vector args) { return std::function([executable_copy, fdin_size, args] { diff --git a/src/smpi/smpi_request.cpp b/src/smpi/smpi_request.cpp index ebfc570ab5..3547243007 100644 --- a/src/smpi/smpi_request.cpp +++ b/src/smpi/smpi_request.cpp @@ -757,10 +757,10 @@ void Request::wait(MPI_Request * request, MPI_Status * status) int Request::waitany(int count, MPI_Request requests[], MPI_Status * status) { s_xbt_dynar_t comms; // Keep it on stack to save some extra mallocs - int size = 0; int index = MPI_UNDEFINED; if(count > 0) { + int size = 0; // Wait for a request to complete xbt_dynar_init(&comms, sizeof(smx_activity_t), [](void*ptr){ intrusive_ptr_release(*(simgrid::kernel::activity::ActivityImpl**)ptr); @@ -914,9 +914,10 @@ int Request::add_f() { } void Request::free_f(int id) { - char key[KEY_SIZE]; - if(id!=MPI_FORTRAN_REQUEST_NULL) + if (id != MPI_FORTRAN_REQUEST_NULL) { + char key[KEY_SIZE]; xbt_dict_remove(F2C::f2c_lookup(), get_key_id(key, id)); + } } } diff --git a/src/surf/lagrange.cpp b/src/surf/lagrange.cpp index e02b6fc27c..4ad25edeb0 100644 --- a/src/surf/lagrange.cpp +++ b/src/surf/lagrange.cpp @@ -1,5 +1,4 @@ -/* Copyright (c) 2007-2014. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -44,11 +43,9 @@ static int __check_feasible(xbt_swag_t cnst_list, xbt_swag_t var_list, int warn) lmm_constraint_t cnst = nullptr; lmm_variable_t var = nullptr; - double tmp; - xbt_swag_foreach(_cnst, cnst_list) { - cnst = static_cast(_cnst); - tmp = 0; + cnst = static_cast(_cnst); + double tmp = 0; elem_list = &(cnst->enabled_element_set); xbt_swag_foreach(_elem, elem_list) { elem = static_cast(_elem); @@ -431,30 +428,25 @@ static double dichotomy(double init, double diff(double, void *), void *var_cnst static double partial_diff_lambda(double lambda, void *param_cnst) { - int j; - void *_elem; - xbt_swag_t elem_list = nullptr; - lmm_element_t elem = nullptr; - lmm_variable_t var = nullptr; lmm_constraint_t cnst = static_cast(param_cnst); double diff = 0.0; - double sigma_i = 0.0; XBT_IN(); - elem_list = &(cnst->enabled_element_set); XBT_CDEBUG(surf_lagrange_dichotomy, "Computing diff of cnst (%p)", cnst); + xbt_swag_t elem_list = &(cnst->enabled_element_set); + void* _elem; xbt_swag_foreach(_elem, elem_list) { - elem = static_cast(_elem); - var = elem->variable; + lmm_element_t elem = static_cast(_elem); + lmm_variable_t var = elem->variable; xbt_assert(var->weight > 0); XBT_CDEBUG(surf_lagrange_dichotomy, "Computing sigma_i for var (%p)", var); // Initialize the summation variable - sigma_i = 0.0; + double sigma_i = 0.0; // Compute sigma_i - for (j = 0; j < var->cnsts_number; j++) { + for (int j = 0; j < var->cnsts_number; j++) { sigma_i += (var->cnsts[j].constraint)->lambda; } diff --git a/src/surf/plugins/host_energy.cpp b/src/surf/plugins/host_energy.cpp index f6669114ae..85d3d0c49d 100644 --- a/src/surf/plugins/host_energy.cpp +++ b/src/surf/plugins/host_energy.cpp @@ -166,10 +166,10 @@ void HostEnergy::update() { double start_time = this->last_updated; double finish_time = surf_get_clock(); - double cpu_load; double current_speed = host->speed(); if (start_time < finish_time) { + double cpu_load; // We may have start == finish if the past consumption was updated since the simcall was started // for example if 2 actors requested to update the same host's consumption in a given scheduling round. // diff --git a/src/xbt/cunit.cpp b/src/xbt/cunit.cpp index 0983062623..8008c3eace 100644 --- a/src/xbt/cunit.cpp +++ b/src/xbt/cunit.cpp @@ -250,7 +250,6 @@ static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity) xbt_test_test_t test; xbt_test_log_t log; - unsigned int it_unit; unsigned int it_test; if (suite == nullptr) @@ -276,6 +275,7 @@ static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity) if (suite->enabled) { /* iterate through all tests */ + unsigned int it_unit; xbt_dynar_foreach(suite->units, it_unit, unit) { /* init unit case counters */ unit->nb_tests = 0; diff --git a/src/xbt/dict.cpp b/src/xbt/dict.cpp index f5759cf390..ccc2d35568 100644 --- a/src/xbt/dict.cpp +++ b/src/xbt/dict.cpp @@ -72,20 +72,15 @@ xbt_dict_t xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn) */ void xbt_dict_free(xbt_dict_t * dict) { - xbt_dictelm_t current; - xbt_dictelm_t previous; - int table_size; - xbt_dictelm_t *table; - - // if ( *dict ) xbt_dict_dump_sizes(*dict); - if (dict != nullptr && *dict != nullptr) { - table_size = (*dict)->table_size; - table = (*dict)->table; + int table_size = (*dict)->table_size; + xbt_dictelm_t* table = (*dict)->table; /* Warning: the size of the table is 'table_size+1'... * This is because table_size is used as a binary mask in xbt_dict_rehash */ for (int i = 0; (*dict)->count && i <= table_size; i++) { - current = table[i]; + xbt_dictelm_t current = table[i]; + xbt_dictelm_t previous; + while (current != nullptr) { previous = current; current = current->next; -- 2.20.1