X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6bae7dbd3ade5ec61d54cdb0128054cbaa710816..84402e8e2ee2a2d0bef25fdceb0a263ed8b471f6:/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 14cf055aae..eb7d36ad71 100644 --- a/examples/s4u/energy-link/s4u-energy-link.cpp +++ b/examples/s4u/energy-link/s4u-energy-link.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2017. 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. */ @@ -22,12 +22,11 @@ static void sender(std::vector args) double comm_size = std::stod(args.at(1)); XBT_INFO("Send %.0f bytes, in %d flows", comm_size, flow_amount); - simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(std::string("message")); + 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); @@ -48,56 +47,38 @@ static void receiver(std::vector args) XBT_INFO("Receiving %d flows ...", flow_amount); - simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(std::string("message")); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::string("message")); if (flow_amount == 1) { void* res = mailbox->get(); xbt_free(res); } else { - char* 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; for (int i = 0; i < flow_amount; i++) - comms.push_back(mailbox->get_async(reinterpret_cast(&(data[i])))); + comms.push_back(mailbox->get_async(&data[i])); 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); - /* Check if we got --NS3 on the command line, and activate ecofen if so */ - bool NS3 = false; - for (int i = 0; i < argc; i++) { - if (strcmp(argv[i], "--NS3") == 0) - NS3 = true; - if (NS3) // Found the --NS3 parameter previously; shift the rest of the line - argv[i] = argv[i + 1]; - } - if (NS3) { - xbt_die("No Ecofen in this build"); - // XBT_INFO("Activating the Ecofen energy plugin"); - // ns3_link_energy_plugin_init(); - // xbt_cfg_set_parse("network/model:NS3"); - // argc -= 1; // We removed it from the parameters - } else { - XBT_INFO("Activating the SimGrid link energy plugin"); - sg_link_energy_plugin_init(); - } + XBT_INFO("Activating the SimGrid link energy plugin"); + sg_link_energy_plugin_init(); - xbt_assert(argc > 1, "\nUsage: %s platform_file [flowCount [datasize]] [--NS3]\n" - "\tExample: %s s4uplatform.xml \n" - "\tIf you add NS3 as last parameter, this will try to activate the ecofen plugin.\n" - "\tWithout it, it will use the SimGrid link energy plugin.\n", + xbt_assert(argc > 1, "\nUsage: %s platform_file [flowCount [datasize]]\n" + "\tExample: %s s4uplatform.xml \n", argv[0], argv[0]); - e.loadPlatform(argv[1]); + e.load_platform(argv[1]); /* prepare to launch the actors */ std::vector argSender; @@ -109,6 +90,7 @@ 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 */ @@ -127,8 +109,8 @@ int main(int argc, char* argv[]) } else { // No parameter at all? Then use the default value argSender.push_back("25000"); } - simgrid::s4u::Actor::createActor("sender", simgrid::s4u::Host::by_name("MyHost1"), sender, argSender); - simgrid::s4u::Actor::createActor("receiver", simgrid::s4u::Host::by_name("MyHost2"), receiver, argReceiver); + simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("MyHost1"), sender, argSender); + simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("MyHost2"), receiver, argReceiver); /* And now, launch the simulation */ e.run();