From: Martin Quinson Date: Mon, 4 Dec 2017 07:16:00 +0000 (+0100) Subject: example improvement and cosmetics X-Git-Tag: v3.18~170 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/6bae7dbd3ade5ec61d54cdb0128054cbaa710816 example improvement and cosmetics - wait_all is now defined - sonar: avoid const_cast - sonar: Remove the whitespaces before the # character --- diff --git a/examples/s4u/energy-link/s4u-energy-link.cpp b/examples/s4u/energy-link/s4u-energy-link.cpp index e64eccf1b9..14cf055aae 100644 --- a/examples/s4u/energy-link/s4u-energy-link.cpp +++ b/examples/s4u/energy-link/s4u-energy-link.cpp @@ -27,23 +27,17 @@ static void sender(std::vector args) /* Sleep a while before starting the example */ simgrid::s4u::this_actor::sleep_for(10); - /* - Send the task to the @ref worker */ - char* payload = bprintf("%f", comm_size); if (flow_amount == 1) { + /* - Send the task to the @ref worker */ + char* payload = bprintf("%f", comm_size); mailbox->put(payload, comm_size); } else { - // Start all comms in parallel + // Start all comms in parallel, and wait for all completions in one shot std::vector comms; for (int i = 0; i < flow_amount; i++) - comms.push_back(mailbox->put_async(const_cast("message"), comm_size)); - - // And now, wait for all comms. Manually since wait_all is not part of this_actor yet - for (int i = 0; i < flow_amount; i++) { - simgrid::s4u::CommPtr comm = comms.at(i); - comm->wait(); - } - comms.clear(); + comms.push_back(mailbox->put_async(bprintf("%d", i), comm_size)); + simgrid::s4u::Comm::wait_all(&comms); } XBT_INFO("sender done."); } @@ -60,17 +54,16 @@ static void receiver(std::vector args) void* res = mailbox->get(); xbt_free(res); } else { - void* ignored; + char* data[flow_amount]; - // Start all comms in parallel + // Start all comms in parallel, and wait for their completion in one shot std::vector comms; for (int i = 0; i < flow_amount; i++) - comms.push_back(mailbox->get_async(&ignored)); + comms.push_back(mailbox->get_async(reinterpret_cast(&(data[i])))); - // And now, wait for all comms. Manually since wait_all is not part of this_actor yet + simgrid::s4u::Comm::wait_all(&comms); for (int i = 0; i < flow_amount; i++) - comms.at(i)->wait(); - comms.clear(); + xbt_free(data[i]); } XBT_INFO("receiver done."); } diff --git a/examples/s4u/energy-pstate/s4u-energy-pstate.cpp b/examples/s4u/energy-pstate/s4u-energy-pstate.cpp index 6f82f4ea2f..621da2ca01 100644 --- a/examples/s4u/energy-pstate/s4u-energy-pstate.cpp +++ b/examples/s4u/energy-pstate/s4u-energy-pstate.cpp @@ -1,10 +1,9 @@ -/* Copyright (c) 2007-2010, 2013-2015. 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. */ - #include "simgrid/s4u.hpp" +#include "simgrid/s4u.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Pstate properties test");