From ed26e84f533a3dc510abdc384aee02506ab9798b Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 22 Mar 2017 11:28:54 +0100 Subject: [PATCH] fix example (bummer) chase smells --- examples/msg/dht-pastry/dht-pastry.c | 10 +-- .../s4u/actor-create/s4u_actor-create.tesh | 14 ++--- examples/smpi/trace/trace.c | 61 ++++++++++--------- src/msg/msg_process.cpp | 3 +- src/simix/ActorImpl.cpp | 13 ++-- src/simix/simcalls.py | 8 +-- src/simix/smx_host_private.h | 1 - src/smpi/smpi_win.cpp | 5 +- src/surf/plugins/host_energy.cpp | 20 +++--- src/surf/plugins/host_load.cpp | 11 ++-- 10 files changed, 75 insertions(+), 71 deletions(-) diff --git a/examples/msg/dht-pastry/dht-pastry.c b/examples/msg/dht-pastry/dht-pastry.c index a66a9b1b67..12d13daf11 100644 --- a/examples/msg/dht-pastry/dht-pastry.c +++ b/examples/msg/dht-pastry/dht-pastry.c @@ -41,14 +41,16 @@ typedef struct s_node { int ready; msg_comm_t comm_receive; // current communication to receive xbt_dynar_t pending_tasks; -} s_node_t, *node_t; +} s_node_t; +typedef s_node_t* node_t; typedef struct s_state { int id; int namespace_set[NAMESPACE_SIZE]; int neighborhood_set[NEIGHBORHOOD_SIZE]; int routing_table[LEVELS_COUNT][LEVEL_SIZE]; -} s_state_t, *state_t; +} s_state_t; +typedef s_state_t* state_t; /** Types of tasks exchanged between nodes. */ typedef enum { @@ -67,9 +69,9 @@ typedef struct s_task_data { //const char* issuer_host_name; // used for logging int steps; state_t state; -} s_task_data_t, *task_data_t; +} s_task_data_t; +typedef s_task_data_t* task_data_t; -static void get_mailbox(int node_id, char* mailbox); static int domain(unsigned int a, unsigned int level); static int shl(int a, int b); static int closest_in_namespace_set(node_t node, int dest); diff --git a/examples/s4u/actor-create/s4u_actor-create.tesh b/examples/s4u/actor-create/s4u_actor-create.tesh index e481ba23b1..f436e01192 100644 --- a/examples/s4u/actor-create/s4u_actor-create.tesh +++ b/examples/s4u/actor-create/s4u_actor-create.tesh @@ -1,10 +1,10 @@ #! ./tesh $ $SG_TEST_EXENV ${bindir:=.}/s4u_actor-create -> [Tremblay:sender1:(0) 0.000000] [s4u_launching_test/INFO] Hello s4u, I have something to send -> [Jupiter:sender2:(0) 0.000000] [s4u_launching_test/INFO] Hello s4u, I have something to send -> [Fafard:receiver:(0) 0.000000] [s4u_launching_test/INFO] Hello s4u, I'm ready to get any message you'd want on mb42 -> [Tremblay:sender1:(0) 0.025709] [s4u_launching_test/INFO] I'm done. See you. -> [Jupiter:sender2:(0) 0.070434] [s4u_launching_test/INFO] I'm done. See you. -> [Fafard:receiver:(0) 0.070434] [s4u_launching_test/INFO] I received 'GaBuZoMeu' and 'GloubiBoulga' -> [Fafard:receiver:(0) 0.070434] [s4u_launching_test/INFO] I'm done. See you. +> [Tremblay:sender1:(0) 0.000000] [s4u_actor_create/INFO] Hello s4u, I have something to send +> [Jupiter:sender2:(0) 0.000000] [s4u_actor_create/INFO] Hello s4u, I have something to send +> [Fafard:receiver:(0) 0.000000] [s4u_actor_create/INFO] Hello s4u, I'm ready to get any message you'd want on mb42 +> [Tremblay:sender1:(0) 0.025709] [s4u_actor_create/INFO] I'm done. See you. +> [Jupiter:sender2:(0) 0.070434] [s4u_actor_create/INFO] I'm done. See you. +> [Fafard:receiver:(0) 0.070434] [s4u_actor_create/INFO] I received 'GaBuZoMeu' and 'GloubiBoulga' +> [Fafard:receiver:(0) 0.070434] [s4u_actor_create/INFO] I'm done. See you. diff --git a/examples/smpi/trace/trace.c b/examples/smpi/trace/trace.c index 786b9e2da7..d995984fad 100644 --- a/examples/smpi/trace/trace.c +++ b/examples/smpi/trace/trace.c @@ -12,7 +12,8 @@ int main(int argc, char *argv[]) { - int rank, numprocs, i; + int rank; + int numprocs; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); @@ -58,51 +59,51 @@ int main(int argc, char *argv[]) /** Test C */ TRACE_smpi_set_category("C"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Isend(r, DATATOSENT, MPI_INT, 1, tag, MPI_COMM_WORLD, &req[i]); } - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Wait(&req[i], &sta[i]); } MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("D"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Isend(r, DATATOSENT, MPI_INT, 1, tag, MPI_COMM_WORLD, &req[i]); } - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { int completed; MPI_Waitany(N, req, &completed, sta); } MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("E"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Send(r, DATATOSENT, MPI_INT, 1, tag, MPI_COMM_WORLD); } MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("F"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Send(r, DATATOSENT, MPI_INT, 1, tag, MPI_COMM_WORLD); } MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("G"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Isend(r, DATATOSENT, MPI_INT, 1, tag, MPI_COMM_WORLD, &req[i]); } MPI_Waitall(N, req, sta); MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("H"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Send(r, DATATOSENT, MPI_INT, 1, tag, MPI_COMM_WORLD); } MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("I"); - for (i = 0; i < 2 * N; i++) { + for (int i = 0; i < 2 * N; i++) { if (i < N) { MPI_Send(r, DATATOSENT, MPI_INT, 2, tag, MPI_COMM_WORLD); } else { @@ -110,7 +111,7 @@ int main(int argc, char *argv[]) } } MPI_Barrier(MPI_COMM_WORLD); - for (i = 0; i < 2 * N; i++) { + for (int i = 0; i < 2 * N; i++) { if (i < N) { MPI_Irecv(r, DATATOSENT, MPI_INT, 1, tag, MPI_COMM_WORLD, &req[i]); } else { @@ -121,14 +122,14 @@ int main(int argc, char *argv[]) MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("J"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Isend(r, DATATOSENT, MPI_INT, 1, tag, MPI_COMM_WORLD, &req[i]); } - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { int flag; MPI_Test(&req[i], &flag, &sta[i]); } - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Wait(&req[i], &sta[i]); } free(r); @@ -152,71 +153,71 @@ int main(int argc, char *argv[]) MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("C"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Recv(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD, &sta[i]); } MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("D"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Recv(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD, &sta[i]); } MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("E"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Irecv(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD, &req[i]); } - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Wait(&req[i], &sta[i]); } MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("F"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Irecv(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD, &req[i]); } - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { int completed; MPI_Waitany(N, req, &completed, sta); } MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("G"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Recv(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD, &sta[i]); } MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("H"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Irecv(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD, &req[i]); } MPI_Waitall(N, req, sta); MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("I"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Irecv(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD, &req[i]); } MPI_Waitall(N, req, sta); MPI_Barrier(MPI_COMM_WORLD); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Isend(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD, &req[i]); } MPI_Waitall(N, req, sta); MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("J"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Irecv(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD, &req[i]); } - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { int flag; MPI_Test(&req[i], &flag, &sta[i]); } - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Wait(&req[i], &sta[i]); } free(r); @@ -237,16 +238,16 @@ int main(int argc, char *argv[]) MPI_Barrier(MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); TRACE_smpi_set_category("I"); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Irecv(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD, &req[i]); } - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { int completed; MPI_Waitany(N, req, &completed, sta); } MPI_Barrier(MPI_COMM_WORLD); - for (i = 0; i < N; i++) { + for (int i = 0; i < N; i++) { MPI_Send(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD); } MPI_Barrier(MPI_COMM_WORLD); diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index 7943aebeac..d0b03bf30f 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -121,7 +121,8 @@ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_fun { std::function function; if (code) - function = simgrid::xbt::wrapMain(code, argc, const_cast(argv)); + function = simgrid::xbt::wrapMain(code, argc, static_cast(argv)); + msg_process_t res = MSG_process_create_from_stdfunc(name, std::move(function), data, host, properties); for (int i = 0; i != argc; ++i) xbt_free(argv[i]); diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index bcce486833..df96ad7120 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -146,16 +146,16 @@ void SIMIX_process_cleanup(smx_actor_t process) /** * Garbage collection * - * Should be called some time to time to free the memory allocated for processes - * that have finished (or killed). + * Should be called some time to time to free the memory allocated for processes that have finished (or killed). */ void SIMIX_process_empty_trash() { - smx_actor_t process = nullptr; + smx_actor_t process = static_cast(xbt_swag_extract(simix_global->process_to_destroy)); - while ((process = (smx_actor_t) xbt_swag_extract(simix_global->process_to_destroy))) { + while (process) { XBT_DEBUG("Getting rid of %p",process); intrusive_ptr_release(process); + process = static_cast(xbt_swag_extract(simix_global->process_to_destroy)); } } @@ -603,12 +603,13 @@ void SIMIX_process_resume(smx_actor_t process) { XBT_IN("process = %p", process); - if(process->context->iwannadie) { + if (process->context->iwannadie) { XBT_VERB("Ignoring request to suspend a process that is currently dying."); return; } - if(!process->suspended) return; + if (!process->suspended) + return; process->suspended = 0; /* resume the synchronization that was blocking the resumed process. */ diff --git a/src/simix/simcalls.py b/src/simix/simcalls.py index 70b1bb34c1..c6854e56a9 100755 --- a/src/simix/simcalls.py +++ b/src/simix/simcalls.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2014-2016. The SimGrid Team. All rights reserved. +# Copyright (c) 2014-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. @@ -233,9 +233,9 @@ def header(name): def handle(fd, func, simcalls, guarded_simcalls): - def nonempty(e): return e != '' - fd.write( - '\n'.join(filter(nonempty, (func(simcall) for simcall in simcalls)))) + def nonempty(e): + return e != '' + fd.write('\n'.join(filter(nonempty, func(simcall) for simcall in simcalls))) for guard, list in guarded_simcalls.items(): fd.write('\n#if %s\n' % (guard)) diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 7b85ee2e1b..3db24e865f 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -37,7 +37,6 @@ namespace simgrid { }; } } -typedef simgrid::simix::Host s_smx_host_priv_t; SG_BEGIN_DECL() XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, diff --git a/src/smpi/smpi_win.cpp b/src/smpi/smpi_win.cpp index f5e573dfb8..080f51916a 100644 --- a/src/smpi/smpi_win.cpp +++ b/src/smpi/smpi_win.cpp @@ -408,8 +408,9 @@ int Win::complete(){ int Win::wait(){ //naive, blocking implementation. XBT_DEBUG("Entering MPI_Win_Wait"); - int i=0,j=0; - int size = group_->size(); + int i = 0; + int j = 0; + int size = group_->size(); MPI_Request* reqs = xbt_new0(MPI_Request, size); while(j!=size){ diff --git a/src/surf/plugins/host_energy.cpp b/src/surf/plugins/host_energy.cpp index 8d701b7493..d64ed6f12a 100644 --- a/src/surf/plugins/host_energy.cpp +++ b/src/surf/plugins/host_energy.cpp @@ -282,19 +282,19 @@ static void onActionStateChange(simgrid::surf::CpuAction* action, simgrid::surf: { for (simgrid::surf::Cpu* cpu : action->cpus()) { simgrid::s4u::Host* host = cpu->getHost(); - if (host == nullptr) - continue; + if (host != nullptr) { - // If it's a VM, take the corresponding PM - simgrid::s4u::VirtualMachine* vm = dynamic_cast(host); - if (vm) // If it's a VM, take the corresponding PM - host = vm->pimpl_vm_->getPm(); + // If it's a VM, take the corresponding PM + simgrid::s4u::VirtualMachine* vm = dynamic_cast(host); + if (vm) // If it's a VM, take the corresponding PM + host = vm->pimpl_vm_->getPm(); - // Get the host_energy extension for the relevant host - HostEnergy* host_energy = host->extension(); + // Get the host_energy extension for the relevant host + HostEnergy* host_energy = host->extension(); - if (host_energy->last_updated < surf_get_clock()) - host_energy->update(); + if (host_energy->last_updated < surf_get_clock()) + host_energy->update(); + } } } diff --git a/src/surf/plugins/host_load.cpp b/src/surf/plugins/host_load.cpp index 54761f1501..5225633b55 100644 --- a/src/surf/plugins/host_load.cpp +++ b/src/surf/plugins/host_load.cpp @@ -118,12 +118,11 @@ static void onActionStateChange(simgrid::surf::CpuAction* action, simgrid::surf: for (simgrid::surf::Cpu* cpu : action->cpus()) { simgrid::s4u::Host* host = cpu->getHost(); - if (host == nullptr) - continue; - - // Get the host_load extension for the relevant host - HostLoad* host_load = host->extension(); - host_load->update(); + if (host != nullptr) { + // Get the host_load extension for the relevant host + HostLoad* host_load = host->extension(); + host_load->update(); + } } } -- 2.20.1