From 98a4fb37cf38be98161ec6fc43ed0733eaefcbee Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sun, 20 Oct 2019 21:04:05 +0200 Subject: [PATCH] Reduce scope for variables. --- examples/deprecated/simdag/scheduling/sd_scheduling.c | 2 +- src/mc/checker/CommunicationDeterminismChecker.cpp | 3 +-- src/smpi/bindings/smpi_pmpi_request.cpp | 5 ++--- src/smpi/internals/smpi_bench.cpp | 10 +++++----- src/smpi/internals/smpi_replay.cpp | 5 ++--- src/smpi/mpi/smpi_group.cpp | 3 +-- src/smpi/mpi/smpi_request.cpp | 3 +-- src/surf/surf_c_bindings.cpp | 3 +-- 8 files changed, 14 insertions(+), 20 deletions(-) diff --git a/examples/deprecated/simdag/scheduling/sd_scheduling.c b/examples/deprecated/simdag/scheduling/sd_scheduling.c index 17972b6512..c7cd717c58 100644 --- a/examples/deprecated/simdag/scheduling/sd_scheduling.c +++ b/examples/deprecated/simdag/scheduling/sd_scheduling.c @@ -72,7 +72,6 @@ static double finish_on_at(SD_task_t task, sg_host_t host) 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; @@ -82,6 +81,7 @@ static double finish_on_at(SD_task_t task, sg_host_t host) if (SD_task_get_kind(parent) == SD_TASK_COMM_E2E) { sg_host_t * parent_host= SD_task_get_workstation_list(parent); /* Estimate the redistribution time from this parent */ + double redist_time; if (SD_task_get_amount(parent) <= 1e-6){ redist_time= 0; } else { diff --git a/src/mc/checker/CommunicationDeterminismChecker.cpp b/src/mc/checker/CommunicationDeterminismChecker.cpp index 1302502d8b..bc2e6421b5 100644 --- a/src/mc/checker/CommunicationDeterminismChecker.cpp +++ b/src/mc/checker/CommunicationDeterminismChecker.cpp @@ -119,9 +119,8 @@ namespace mc { void CommunicationDeterminismChecker::deterministic_comm_pattern(int process, simgrid::mc::PatternCommunication* comm, int backtracking) { - simgrid::mc::PatternCommunicationList& list = initial_communications_pattern[process]; - if (not backtracking) { + simgrid::mc::PatternCommunicationList& list = initial_communications_pattern[process]; e_mc_comm_pattern_difference_t diff = compare_comm_pattern(list.list[list.index_comm].get(), comm); if (diff != NONE_DIFF) { diff --git a/src/smpi/bindings/smpi_pmpi_request.cpp b/src/smpi/bindings/smpi_pmpi_request.cpp index 7d1f2b0ef6..f64dbabda6 100644 --- a/src/smpi/bindings/smpi_pmpi_request.cpp +++ b/src/smpi/bindings/smpi_pmpi_request.cpp @@ -145,10 +145,9 @@ int PMPI_Startall(int count, MPI_Request * requests) if(retval != MPI_ERR_REQUEST) { int my_proc_id = simgrid::s4u::this_actor::get_pid(); TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Startall")); - MPI_Request req = MPI_REQUEST_NULL; if (not TRACE_smpi_view_internals()) for (int i = 0; i < count; i++) { - req = requests[i]; + MPI_Request req = requests[i]; if (req->flags() & MPI_REQ_SEND) TRACE_smpi_send(my_proc_id, my_proc_id, getPid(req->comm(), req->dst()), req->tag(), req->size()); } @@ -157,7 +156,7 @@ int PMPI_Startall(int count, MPI_Request * requests) if (not TRACE_smpi_view_internals()) for (int i = 0; i < count; i++) { - req = requests[i]; + MPI_Request req = requests[i]; if (req->flags() & MPI_REQ_RECV) TRACE_smpi_recv(getPid(req->comm(), req->src()), my_proc_id, req->tag()); } diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index a38dd6e0ac..6380f77897 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -352,12 +352,12 @@ void smpi_sample_1(int global, const char *file, int line, int iters, double thr 0, // count true // benching (if we have no data, we need at least one) }); - LocalData& data = insert.first->second; if (insert.second) { XBT_DEBUG("XXXXX First time ever on benched nest %s.", loc.c_str()); xbt_assert(threshold > 0 || iters > 0, "You should provide either a positive amount of iterations to bench, or a positive maximal stderr (or both)"); } else { + LocalData& data = insert.first->second; if (data.iters != iters || data.threshold != threshold) { XBT_ERROR("Asked to bench block %s with different settings %d, %f is not %d, %f. " "How did you manage to give two numbers at the same line??", @@ -449,12 +449,12 @@ int smpi_sample_exit(int global, const char *file, int line, int iter_count){ auto sample = samples.find(loc); if (sample == samples.end()) xbt_die("Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); - LocalData& data = sample->second; if (smpi_process()->sampling()){//end of loop, but still sampling needed - smpi_process()->set_sampling(0); - smpi_execute(data.mean*iter_count); - smpi_bench_begin(); + LocalData& data = sample->second; + smpi_process()->set_sampling(0); + smpi_execute(data.mean * iter_count); + smpi_bench_begin(); } } return 0; diff --git a/src/smpi/internals/smpi_replay.cpp b/src/smpi/internals/smpi_replay.cpp index 93114a32d3..2af987f919 100644 --- a/src/smpi/internals/smpi_replay.cpp +++ b/src/smpi/internals/smpi_replay.cpp @@ -273,13 +273,12 @@ void GatherVArgParser::parse(simgrid::xbt::ReplayAction& action, const std::stri if (action.size() > 5 + comm_size) datatype2 = simgrid::smpi::Datatype::decode(action[5 + comm_size]); } else { - int datatype_index = 0; int disp_index = 0; /* The 3 comes from "0 gather ", which must always be present. * The + comm_size is the recvcounts array, which must also be present */ if (action.size() > 3 + comm_size + comm_size) { /* datatype + disp are specified */ - datatype_index = 3 + comm_size; + int datatype_index = 3 + comm_size; disp_index = datatype_index + 1; datatype1 = simgrid::smpi::Datatype::decode(action[datatype_index]); datatype2 = simgrid::smpi::Datatype::decode(action[datatype_index]); @@ -287,7 +286,7 @@ void GatherVArgParser::parse(simgrid::xbt::ReplayAction& action, const std::stri 3 + comm_size + 2) { /* disps specified; datatype is not specified; use the default one */ disp_index = 3 + comm_size; } else if (action.size() > 3 + comm_size) { /* only datatype, no disp specified */ - datatype_index = 3 + comm_size; + int datatype_index = 3 + comm_size; datatype1 = simgrid::smpi::Datatype::decode(action[datatype_index]); datatype2 = simgrid::smpi::Datatype::decode(action[datatype_index]); } diff --git a/src/smpi/mpi/smpi_group.cpp b/src/smpi/mpi/smpi_group.cpp index cbd973a064..fb70b84d08 100644 --- a/src/smpi/mpi/smpi_group.cpp +++ b/src/smpi/mpi/smpi_group.cpp @@ -106,7 +106,6 @@ int Group::compare(MPI_Group group2) int Group::incl(int n, const int* ranks, MPI_Group* newgroup) { - int i=0; if (n == 0) { *newgroup = MPI_GROUP_EMPTY; } else if (n == size_) { @@ -115,7 +114,7 @@ int Group::incl(int n, const int* ranks, MPI_Group* newgroup) this->ref(); } else { *newgroup = new Group(n); - for (i = 0; i < n; i++) { + for (int i = 0; i < n; i++) { s4u::Actor* actor = this->actor(ranks[i]); // ranks[] was passed as a param! (*newgroup)->set_mapping(actor, i); } diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index 2a70952dab..0ec24c8ef3 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -722,11 +722,10 @@ int Request::testall(int count, MPI_Request requests[], int* outflag, MPI_Status MPI_Status *pstat = status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat; int flag; int error = 0; - int ret=MPI_SUCCESS; *outflag = 1; for(int i=0; iflags_ & MPI_REQ_PREPARED)) { - ret = test(&requests[i], pstat, &flag); + int ret = test(&requests[i], pstat, &flag); if (flag){ flag=0; requests[i]=MPI_REQUEST_NULL; diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 588764b3d0..f111cc23ce 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -46,7 +46,6 @@ void surf_presolve() double surf_solve(double max_date) { double time_delta = -1.0; /* duration */ - double model_next_action_end = -1.0; double value = -1.0; simgrid::kernel::resource::Resource* resource = nullptr; simgrid::kernel::profile::Event* event = nullptr; @@ -96,7 +95,7 @@ double surf_solve(double max_date) XBT_DEBUG("Run the NS3 network at most %fs", time_delta); // run until min or next flow - model_next_action_end = surf_network_model->next_occurring_event(time_delta); + double model_next_action_end = surf_network_model->next_occurring_event(time_delta); XBT_DEBUG("Min for network : %f", model_next_action_end); if (model_next_action_end >= 0.0) -- 2.20.1