Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / examples / s4u / comm-dependent / s4u-comm-dependent.cpp
index e0a93ce06171ffdd4b5d5fedb7c7158cfa960be5..bcf7bdae8dc95baa33a4f12bd62e7943133890d9 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2021. 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. */
@@ -9,8 +9,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_dependent, "Messages specific for this s4u
 
 static void sender(simgrid::s4u::Mailbox* mailbox)
 {
-  double* computation_amount = new double();
-  *computation_amount        = simgrid::s4u::this_actor::get_host()->get_speed();
+  auto* computation_amount   = new double(simgrid::s4u::this_actor::get_host()->get_speed());
   simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(2 * (*computation_amount));
   simgrid::s4u::CommPtr comm = mailbox->put_init(computation_amount, 7e6);
 
@@ -22,16 +21,18 @@ static void sender(simgrid::s4u::Mailbox* mailbox)
 
 static void receiver(simgrid::s4u::Mailbox* mailbox)
 {
-  double received;
+  double* received           = nullptr;
   double computation_amount  = simgrid::s4u::this_actor::get_host()->get_speed();
   simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(2 * computation_amount);
-  simgrid::s4u::CommPtr comm = mailbox->get_init()->set_dst_data((void**)&received);
+  simgrid::s4u::CommPtr comm = mailbox->get_init()->set_dst_data((void**)&received, sizeof(double));
 
   comm->set_name("comm from sender")->add_successor(exec)->start();
   exec->set_name("exec on receiver")->vetoable_start();
 
   comm->wait();
   exec->wait();
+  XBT_INFO("Received: %.0f flops were computed on sender", *received);
+  delete received;
 }
 
 int main(int argc, char* argv[])