Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further snake_case s4u::Engine
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 22 Apr 2018 20:51:40 +0000 (22:51 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 23 Apr 2018 12:23:40 +0000 (14:23 +0200)
13 files changed:
examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp
examples/s4u/actor-yield/s4u-actor-yield.cpp
examples/s4u/app-bittorrent/s4u-bittorrent.cpp
examples/s4u/app-masterworker/s4u-app-masterworker.cpp
examples/s4u/async-wait/s4u-async-wait.cpp
examples/s4u/async-waitall/s4u-async-waitall.cpp
examples/s4u/async-waitany/s4u-async-waitany.cpp
examples/s4u/dht-chord/s4u-dht-chord.cpp
examples/s4u/replay-comm/s4u-replay-comm.cpp
examples/s4u/replay-storage/s4u-replay-storage.cpp
include/simgrid/s4u/Engine.hpp
include/simgrid/s4u/Mailbox.hpp
teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp

index 16b693c..19668e4 100644 (file)
@@ -39,9 +39,9 @@ int main(int argc, char* argv[])
                        "\tExample: %s msg_platform.xml msg_deployment.xml\n",
              argv[0], argv[0]);
 
                        "\tExample: %s msg_platform.xml msg_deployment.xml\n",
              argv[0], argv[0]);
 
-  e.load_platform(argv[1]); /* Load the platform description */
-  e.registerFunction<sleeper>("sleeper");
-  e.load_deployment(argv[2]); /* - Deploy the sleeper processes with explicit start/kill times */
+  e.load_platform(argv[1]); /* Load the platform description */
+  e.register_actor<sleeper>("sleeper");
+  e.load_deployment(argv[2]); /*  Deploy the sleeper processes with explicit start/kill times */
 
   e.run(); /* - Run the simulation */
 
 
   e.run(); /* - Run the simulation */
 
index 8fc130c..bd80f70 100644 (file)
@@ -36,8 +36,8 @@ int main(int argc, char* argv[])
                        "\tExample: %s platform.xml deployment.xml\n",
              argv[0], argv[0]);
 
                        "\tExample: %s platform.xml deployment.xml\n",
              argv[0], argv[0]);
 
-  e.load_platform(argv[1]); /* - Load the platform description */
-  e.register_function<yielder>("yielder");
+  e.load_platform(argv[1]);             /* Load the platform description */
+  e.register_actor<yielder>("yielder"); /* Register the class representing the actors */
 
   e.load_deployment(argv[2]);
 
 
   e.load_deployment(argv[2]);
 
index 66bcd81..2ef35e1 100644 (file)
@@ -19,14 +19,14 @@ int main(int argc, char* argv[])
 
   e.load_platform(argv[1]);
 
 
   e.load_platform(argv[1]);
 
+  /* Install our extension on all existing hosts */
   HostBittorrent::EXTENSION_ID = simgrid::s4u::Host::extension_create<HostBittorrent>();
   HostBittorrent::EXTENSION_ID = simgrid::s4u::Host::extension_create<HostBittorrent>();
-
   std::vector<simgrid::s4u::Host*> list = simgrid::s4u::Engine::getInstance()->get_all_hosts();
   for (auto const& host : list)
     host->extension_set(new HostBittorrent(host));
 
   std::vector<simgrid::s4u::Host*> list = simgrid::s4u::Engine::getInstance()->get_all_hosts();
   for (auto const& host : list)
     host->extension_set(new HostBittorrent(host));
 
-  e.register_function<Tracker>("tracker");
-  e.register_function<Peer>("peer");
+  e.register_actor<Tracker>("tracker");
+  e.register_actor<Peer>("peer");
   e.load_deployment(argv[2]);
 
   e.run();
   e.load_deployment(argv[2]);
 
   e.run();
index 47420c8..643f6d4 100644 (file)
@@ -89,10 +89,10 @@ int main(int argc, char* argv[])
                        "\tExample: %s msg_platform.xml msg_deployment.xml\n",
              argv[0], argv[0]);
 
                        "\tExample: %s msg_platform.xml msg_deployment.xml\n",
              argv[0], argv[0]);
 
-  e.load_platform(argv[1]); /** - Load the platform description */
-  e.register_function<Master>("master");
-  e.register_function<Worker>("worker"); /** - Register the function to be executed by the processes */
-  e.load_deployment(argv[2]);            /** - Deploy the application */
+  e.load_platform(argv[1]);           /* Load the platform description */
+  e.register_actor<Master>("master"); /* Register the class representing the actors */
+  e.register_actor<Worker>("worker");
+  e.load_deployment(argv[2]); /* Deploy the application */
 
   e.run(); /** - Run the simulation */
 
 
   e.run(); /** - Run the simulation */
 
index c8a344c..b2f5a11 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_wait, "Messages specific for this s4u example");
 
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_wait, "Messages specific for this s4u example");
 
-class Sender {
-  long messages_count;  /* - number of tasks */
-  long receivers_count; /* - number of receivers */
-  double msg_size;      /* - communication cost in bytes */
-
-public:
-  explicit Sender(std::vector<std::string> args)
-  {
-    xbt_assert(args.size() == 4, "Expecting 3 parameters from the XML deployment file but got %zu", args.size());
-    messages_count  = std::stol(args[1]);
-    msg_size        = std::stod(args[2]);
-    receivers_count = std::stol(args[3]);
+static int sender(int argc, char** argv)
+{
+  xbt_assert(argc == 4, "Expecting 3 parameters from the XML deployment file but got %d", argc);
+  long messages_count  = std::stol(argv[1]); /* - number of tasks */
+  double msg_size      = std::stol(argv[2]); /* - communication cost in bytes */
+  long receivers_count = std::stod(argv[3]); /* - number of receivers */
+
+  std::vector<simgrid::s4u::CommPtr> pending_comms;
+
+  /* Start dispatching all messages to receivers, in a round robin fashion */
+  for (int i = 0; i < messages_count; i++) {
+
+    std::string mboxName          = std::string("receiver-") + std::to_string(i % receivers_count);
+    simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName);
+    std::string msgName           = std::string("Message ") + std::to_string(i);
+    std::string* payload          = new std::string(msgName); // copy the data we send:
+    // 'msgName' is not a stable storage location
+    XBT_INFO("Send '%s' to '%s'", msgName.c_str(), mboxName.c_str());
+    /* Create a communication representing the ongoing communication */
+    simgrid::s4u::CommPtr comm = mbox->put_async(payload, msg_size);
+    /* Add this comm to the vector of all known comms */
+    pending_comms.push_back(comm);
   }
   }
-  void operator()()
-  {
-    std::vector<simgrid::s4u::CommPtr> pending_comms;
-
-    /* Start dispatching all messages to receivers, in a round robin fashion */
-    for (int i = 0; i < messages_count; i++) {
-
-      std::string mboxName          = std::string("receiver-") + std::to_string(i % receivers_count);
-      simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName);
-      std::string msgName = std::string("Message ") + std::to_string(i);
-      std::string* payload          = new std::string(msgName); // copy the data we send:
-                                                                // 'msgName' is not a stable storage location
-      XBT_INFO("Send '%s' to '%s'", msgName.c_str(), mboxName.c_str());
-      /* Create a communication representing the ongoing communication */
-      simgrid::s4u::CommPtr comm = mbox->put_async(payload, msg_size);
-      /* Add this comm to the vector of all known comms */
-      pending_comms.push_back(comm);
-    }
-
-    /* Start sending messages to let the workers know that they should stop */
-    for (int i = 0; i < receivers_count; i++) {
-      std::string mboxName          = std::string("receiver-") + std::to_string(i % receivers_count);
-      simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName);
-      std::string* payload          = new std::string("finalize"); // Make a copy of the data we will send
-
-      simgrid::s4u::CommPtr comm = mbox->put_async(payload, 0);
-      pending_comms.push_back(comm);
-      XBT_INFO("Send 'finalize' to 'receiver-%ld'", i % receivers_count);
-    }
-    XBT_INFO("Done dispatching all messages");
-
-    /* Now that all message exchanges were initiated, wait for their completion, in order of creation. */
-    while (not pending_comms.empty()) {
-      simgrid::s4u::CommPtr comm = pending_comms.back();
-      comm->wait();             // we could provide a timeout as a parameter
-      pending_comms.pop_back(); // remove it from the list
-    }
-
-    XBT_INFO("Goodbye now!");
+
+  /* Start sending messages to let the workers know that they should stop */
+  for (int i = 0; i < receivers_count; i++) {
+    std::string mboxName          = std::string("receiver-") + std::to_string(i % receivers_count);
+    simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName);
+    std::string* payload          = new std::string("finalize"); // Make a copy of the data we will send
+
+    simgrid::s4u::CommPtr comm = mbox->put_async(payload, 0);
+    pending_comms.push_back(comm);
+    XBT_INFO("Send 'finalize' to 'receiver-%ld'", i % receivers_count);
   }
   }
-};
+  XBT_INFO("Done dispatching all messages");
 
 
-/* Receiver actor expects 1 argument: its ID */
-class Receiver {
-  simgrid::s4u::MailboxPtr mbox;
-
-public:
-  explicit Receiver(std::vector<std::string> args)
-  {
-    xbt_assert(args.size() == 2, "Expecting one parameter from the XML deployment file but got %zu", args.size());
-    std::string mboxName = std::string("receiver-") + args[1];
-    mbox                 = simgrid::s4u::Mailbox::byName(mboxName);
+  /* Now that all message exchanges were initiated, wait for their completion, in order of creation. */
+  while (not pending_comms.empty()) {
+    simgrid::s4u::CommPtr comm = pending_comms.back();
+    comm->wait();             // we could provide a timeout as a parameter
+    pending_comms.pop_back(); // remove it from the list
   }
 
   }
 
-  void operator()()
-  {
-    XBT_INFO("Wait for my first message");
-    for (bool cont = true; cont;) {
-      std::string* received = static_cast<std::string*>(mbox->get());
-      XBT_INFO("I got a '%s'.", received->c_str());
-      cont = (*received != "finalize"); // If it's a finalize message, we're done
-      // Receiving the message was all we were supposed to do
-      delete received;
-    }
+  XBT_INFO("Goodbye now!");
+  return 0;
+}
+
+/* Receiver actor expects 1 argument: its ID */
+static int receiver(int argc, char** argv)
+{
+  xbt_assert(argc == 2, "Expecting one parameter from the XML deployment file but got %d", argc);
+  simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(std::string("receiver-") + argv[1]);
+
+  XBT_INFO("Wait for my first message");
+  for (bool cont = true; cont;) {
+    std::string* received = static_cast<std::string*>(mbox->get());
+    XBT_INFO("I got a '%s'.", received->c_str());
+    if (*received == "finalize")
+      cont = false; // If it's a finalize message, we're done.
+    delete received;
   }
   }
-};
+  return 0;
+}
 
 int main(int argc, char *argv[])
 {
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
   simgrid::s4u::Engine e(&argc, argv);
 
 int main(int argc, char *argv[])
 {
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
   simgrid::s4u::Engine e(&argc, argv);
-  e.registerFunction<Sender>("sender");
-  e.registerFunction<Receiver>("receiver");
+  e.register_function("sender", &sender);
+  e.register_function("receiver", &receiver);
 
   e.load_platform(argv[1]);
   e.load_deployment(argv[2]);
 
   e.load_platform(argv[1]);
   e.load_deployment(argv[2]);
index 4d2c49c..a6762bc 100644 (file)
@@ -99,8 +99,8 @@ int main(int argc, char *argv[])
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
   simgrid::s4u::Engine e(&argc, argv);
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
   simgrid::s4u::Engine e(&argc, argv);
-  e.registerFunction<Sender>("sender");
-  e.registerFunction<Receiver>("receiver");
+  e.register_actor<Sender>("sender");
+  e.register_actor<Receiver>("receiver");
 
   e.load_platform(argv[1]);
   e.load_deployment(argv[2]);
 
   e.load_platform(argv[1]);
   e.load_deployment(argv[2]);
index 79d0ebf..32b53e3 100644 (file)
@@ -115,8 +115,8 @@ int main(int argc, char *argv[])
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
   simgrid::s4u::Engine e(&argc, argv);
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
   simgrid::s4u::Engine e(&argc, argv);
-  e.register_function<Sender>("sender");
-  e.register_function<Receiver>("receiver");
+  e.register_actor<Sender>("sender");
+  e.register_actor<Receiver>("receiver");
 
   e.load_platform(argv[1]);
   e.load_deployment(argv[2]);
 
   e.load_platform(argv[1]);
   e.load_deployment(argv[2]);
index 1b26134..4376b7b 100644 (file)
@@ -64,9 +64,9 @@ int main(int argc, char* argv[])
 
   e.load_platform(options[0]);
 
 
   e.load_platform(options[0]);
 
-  chord_init();
+  chord_init(); // FIXME: inline me
 
 
-  e.register_function<Node>("node");
+  e.register_actor<Node>("node");
   e.load_deployment(options[1]);
 
   e.run();
   e.load_deployment(options[1]);
 
   e.run();
index 8605a10..1340ea9 100644 (file)
@@ -97,8 +97,8 @@ int main(int argc, char* argv[])
 
   e.load_platform(argv[1]);
   e.register_default(&simgrid::xbt::replay_runner);
 
   e.load_platform(argv[1]);
   e.register_default(&simgrid::xbt::replay_runner);
-  e.registerFunction<Replayer>("p0");
-  e.registerFunction<Replayer>("p1");
+  e.register_actor<Replayer>("p0");
+  e.register_actor<Replayer>("p1");
   e.load_deployment(argv[2]);
 
   /*   Action registration */
   e.load_deployment(argv[2]);
 
   /*   Action registration */
index f1a76f2..d793ea1 100644 (file)
@@ -113,7 +113,7 @@ int main(int argc, char* argv[])
 
   e.load_platform(argv[1]);
   e.register_default(&simgrid::xbt::replay_runner);
 
   e.load_platform(argv[1]);
   e.register_default(&simgrid::xbt::replay_runner);
-  e.registerFunction<Replayer>("p0");
+  e.register_actor<Replayer>("p0");
   e.load_deployment(argv[2]);
 
   /*   Action registration */
   e.load_deployment(argv[2]);
 
   /*   Action registration */
index 52224c1..44eab9d 100644 (file)
@@ -42,6 +42,8 @@ public:
 
   /** Registers the main function of an actor that will be launched from the deployment file */
   void register_function(const char* name, int (*code)(int, char**));
 
   /** Registers the main function of an actor that will be launched from the deployment file */
   void register_function(const char* name, int (*code)(int, char**));
+  // FIXME: provide a register_function(std::string, void (*code)(int, char**)) and deprecate the int returning one
+  // FIXME: provide a register_function(std::string, std::vector<std::string>)
 
   /** Registers a function as the default main function of actors
    *
 
   /** Registers a function as the default main function of actors
    *
@@ -50,6 +52,23 @@ public:
    */
   void register_default(int (*code)(int, char**));
 
    */
   void register_default(int (*code)(int, char**));
 
+  template <class F> void register_actor(const char* name)
+  {
+    simgrid::simix::register_function(name, [](std::vector<std::string> args) {
+      return simgrid::simix::ActorCode([args] {
+        F code(std::move(args));
+        code();
+      });
+    });
+  }
+
+  template <class F> void register_actor(const char* name, F code)
+  {
+    simgrid::simix::register_function(name, [code](std::vector<std::string> args) {
+      return simgrid::simix::ActorCode([code, args] { code(std::move(args)); });
+    });
+  }
+
   /** @brief Load a deployment file and launch the actors that it contains */
   void load_deployment(const char* deploy);
 
   /** @brief Load a deployment file and launch the actors that it contains */
   void load_deployment(const char* deploy);
 
@@ -100,23 +119,6 @@ public:
   void netpointRegister(simgrid::kernel::routing::NetPoint * card);
   void netpointUnregister(simgrid::kernel::routing::NetPoint * card);
 
   void netpointRegister(simgrid::kernel::routing::NetPoint * card);
   void netpointUnregister(simgrid::kernel::routing::NetPoint * card);
 
-  template <class F> void register_actor(const char* name)
-  {
-    simgrid::simix::register_function(name, [](std::vector<std::string> args) {
-      return simgrid::simix::ActorCode([args] {
-        F code(std::move(args));
-        code();
-      });
-    });
-  }
-
-  template <class F> void register_actor(const char* name, F code)
-  {
-    simgrid::simix::register_function(name, [code](std::vector<std::string> args) {
-      return simgrid::simix::ActorCode([code, args] { code(std::move(args)); });
-    });
-  }
-
   /** Returns whether SimGrid was initialized yet -- mostly for internal use */
   static bool isInitialized();
 
   /** Returns whether SimGrid was initialized yet -- mostly for internal use */
   static bool isInitialized();
 
@@ -142,6 +144,17 @@ public:
   {
     register_default(code);
   }
   {
     register_default(code);
   }
+  template <class F>
+  XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_actor()") void registerFunction(const char* name)
+  {
+    register_actor<F>(name);
+  }
+  template <class F>
+  XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_actor()") void registerFunction(const char* name, F code)
+  {
+    register_actor<F>(name, code);
+  }
+
   XBT_ATTRIB_DEPRECATED_v323("Please use Engine::load_deployment()") void loadDeployment(const char* deploy)
   {
     load_deployment(deploy);
   XBT_ATTRIB_DEPRECATED_v323("Please use Engine::load_deployment()") void loadDeployment(const char* deploy)
   {
     load_deployment(deploy);
index 34326a7..c7438ef 100644 (file)
@@ -176,7 +176,7 @@ public:
   CommPtr get_async(void** data);
 
   /** Blocking data reception */
   CommPtr get_async(void** data);
 
   /** Blocking data reception */
-  void* get();
+  void* get(); // FIXME: make a typed template version
   /** Blocking data reception with timeout */
   void* get(double timeout);
 };
   /** Blocking data reception with timeout */
   void* get(double timeout);
 };
index c953820..ab82939 100644 (file)
@@ -182,7 +182,7 @@ int main(int argc, char* argv[])
   }
   xbt_assert(argSend.front().size() == argRecv.front().size(), "Sender and receiver spec must be of the same size");
 
   }
   xbt_assert(argSend.front().size() == argRecv.front().size(), "Sender and receiver spec must be of the same size");
 
-  std::vector<simgrid::s4u::Host*> hosts = e.getAllHosts();
+  std::vector<simgrid::s4u::Host*> hosts = e.get_all_hosts();
 
   simgrid::s4u::Actor::create("sender", hosts[0], sender, argSend);
   simgrid::s4u::Actor::create("recver", hosts[1], receiver, argRecv);
 
   simgrid::s4u::Actor::create("sender", hosts[0], sender, argSend);
   simgrid::s4u::Actor::create("recver", hosts[1], receiver, argRecv);