]> AND Public Git Repository - simgrid.git/blobdiff - examples/s4u/energy-link/s4u-energy-link.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'depencencies' of https://framagit.org/simgrid/simgrid into depencencies
[simgrid.git] / examples / s4u / energy-link / s4u-energy-link.cpp
index a927e1f1b9a81fcf3bcf1be2d598fcd80493b32d..eb7d36ad71d52c592c4fd878b85dc54539d975e5 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2017-2018. 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<std::string> 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::by_name(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,13 +47,13 @@ static void receiver(std::vector<std::string> args)
 
   XBT_INFO("Receiving %d flows ...", flow_amount);
 
-  simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name(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 {
-    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<simgrid::s4u::CommPtr> comms;
@@ -64,13 +63,13 @@ static void receiver(std::vector<std::string> 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,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 */