X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/691d7c891da0352a6fa38507a482b287c7e086de..b9625f82f86db0674e911887addce45dca31b57f:/examples/s4u/energy-link/s4u-energy-link.cpp diff --git a/examples/s4u/energy-link/s4u-energy-link.cpp b/examples/s4u/energy-link/s4u-energy-link.cpp index e765771ca5..a44c445040 100644 --- a/examples/s4u/energy-link/s4u-energy-link.cpp +++ b/examples/s4u/energy-link/s4u-energy-link.cpp @@ -1,36 +1,34 @@ -/* Copyright (c) 2017-2019. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2017-2020. 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/plugins/energy.h" #include "xbt/log.h" +#include "xbt/random.hpp" #include -#include - /* Parameters of the random generation of the flow size */ -static const unsigned long int min_size = 1e6; -static const unsigned long int max_size = 1e9; +static const int min_size = 1e6; +static const int max_size = 1e9; XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_energyconsumption, "Messages specific for this s4u example"); static void sender(std::vector args) { xbt_assert(args.size() == 2, "The master function expects 2 arguments."); - int flow_amount = std::stoi(args.at(0)); - double comm_size = std::stod(args.at(1)); - XBT_INFO("Send %.0f bytes, in %d flows", comm_size, flow_amount); + int flow_amount = std::stoi(args.at(0)); + long comm_size = std::stol(args.at(1)); + XBT_INFO("Send %ld bytes, in %d flows", comm_size, flow_amount); simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::string("message")); /* Sleep a while before starting the example */ simgrid::s4u::this_actor::sleep_for(10); - if (flow_amount == 1) { /* - Send the task to the @ref worker */ - char* payload = bprintf("%f", comm_size); + char* payload = bprintf("%ld", comm_size); mailbox->put(payload, comm_size); } else { // Start all comms in parallel, and wait for all completions in one shot @@ -54,7 +52,7 @@ static void receiver(std::vector args) void* res = mailbox->get(); xbt_free(res); } else { - void* data[flow_amount]; + void** data= new void*[flow_amount]; // Start all comms in parallel, and wait for their completion in one shot std::vector comms; @@ -64,13 +62,13 @@ static void receiver(std::vector args) simgrid::s4u::Comm::wait_all(&comms); for (int i = 0; i < flow_amount; i++) xbt_free(data[i]); + delete[] data; } XBT_INFO("receiver done."); } int main(int argc, char* argv[]) { - simgrid::s4u::Engine e(&argc, argv); XBT_INFO("Activating the SimGrid link energy plugin"); @@ -91,18 +89,11 @@ int main(int argc, char* argv[]) argSender.push_back("1"); // Default value argReceiver.push_back("1"); } + if (argc > 3) { if (strcmp(argv[3], "random") == 0) { // We're asked to get a random size - /* Initialize the random number generator */ - std::random_device rd; - std::default_random_engine generator(rd()); - - /* Distribution on which to apply the generator */ - std::uniform_int_distribution distribution(min_size, max_size); - - char* size = bprintf("%lu", distribution(generator)); - argSender.push_back(std::string(size)); - xbt_free(size); + std::string size = std::to_string(simgrid::xbt::random::uniform_int(min_size, max_size)); + argSender.push_back(size); } else { // Not "random" ? Then it should be the size to use argSender.push_back(argv[3]); // Take the datasize from the command line }