Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into S4U
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 16 Aug 2015 16:33:32 +0000 (18:33 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 16 Aug 2015 16:33:32 +0000 (18:33 +0200)
23 files changed:
.gitignore
examples/s4u/CMakeLists.txt [new file with mode: 0644]
examples/s4u/README [new file with mode: 0644]
examples/s4u/dumb/CMakeLists.txt [new file with mode: 0644]
examples/s4u/dumb/s4u_test.cpp [new file with mode: 0644]
examples/s4u/dumb/s4u_test.tesh [new file with mode: 0644]
include/simgrid/s4u.h [new file with mode: 0644]
include/simgrid/s4u/actor.hpp [new file with mode: 0644]
include/simgrid/s4u/async.hpp [new file with mode: 0644]
include/simgrid/s4u/comm.hpp [new file with mode: 0644]
include/simgrid/s4u/engine.hpp [new file with mode: 0644]
include/simgrid/s4u/host.hpp [new file with mode: 0644]
include/simgrid/s4u/mailbox.hpp [new file with mode: 0644]
src/s4u/s4u_actor.cpp [new file with mode: 0644]
src/s4u/s4u_async.cpp [new file with mode: 0644]
src/s4u/s4u_comm.cpp [new file with mode: 0644]
src/s4u/s4u_engine.cpp [new file with mode: 0644]
src/s4u/s4u_host.cpp [new file with mode: 0644]
src/s4u/s4u_mailbox.cpp [new file with mode: 0644]
tools/cmake/AddTests.cmake
tools/cmake/DefinePackages.cmake
tools/cmake/Distrib.cmake
tools/cmake/MakeExe.cmake

index 458db25..4b208aa 100644 (file)
@@ -181,6 +181,7 @@ examples/msg/masterslave/masterslave_console
 examples/msg/irc_isend/peer
 examples/msg/irc_isend/toto.txt
 examples/msg/ns3/ns3
+examples/s4u/dumb/s4u_test
 examples/simdag/sd_avail
 examples/simdag/ex_sd_seq_access
 examples/simdag/sd_seq_access
diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1400a02
--- /dev/null
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 2.6)
+
+set(tesh_files
+  ${tesh_files}
+  PARENT_SCOPE
+  )
+set(xml_files
+  ${xml_files}
+  PARENT_SCOPE
+  )
+set(examples_src
+  ${examples_src}
+  PARENT_SCOPE
+  )
+set(bin_files
+  ${bin_files}
+  PARENT_SCOPE
+  )
+set(txt_files
+  ${txt_files}
+  ${CMAKE_CURRENT_SOURCE_DIR}/README
+  PARENT_SCOPE
+  )
diff --git a/examples/s4u/README b/examples/s4u/README
new file mode 100644 (file)
index 0000000..0b54715
--- /dev/null
@@ -0,0 +1,7 @@
+S4U (Simgrid for you) is the next interface of SimGrid, expected to be
+released with SimGrid 4.0.
+
+Even if it's in a very preliminary state so far, you are welcome to
+try it an report any interface glitches that you see. Be however
+warned that the interface will be modified until its final release.
+You will have to adapt your code on the way.
\ No newline at end of file
diff --git a/examples/s4u/dumb/CMakeLists.txt b/examples/s4u/dumb/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0f105ca
--- /dev/null
@@ -0,0 +1,30 @@
+cmake_minimum_required(VERSION 2.6)
+
+set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}")
+add_executable(s4u_test s4u_test.cpp)
+
+### Add definitions for compile
+target_link_libraries(s4u_test simgrid)
+
+set(tesh_files
+  ${tesh_files}
+  ${CMAKE_CURRENT_SOURCE_DIR}/s4u_test.tesh
+  PARENT_SCOPE
+  )
+set(xml_files
+  ${xml_files}
+  PARENT_SCOPE
+  )
+set(examples_src
+  ${examples_src}
+  ${CMAKE_CURRENT_SOURCE_DIR}/s4u_test.cpp
+  PARENT_SCOPE
+  )
+set(bin_files
+  ${bin_files}
+  PARENT_SCOPE
+  )
+set(txt_files
+  ${txt_files}
+  PARENT_SCOPE
+  )
diff --git a/examples/s4u/dumb/s4u_test.cpp b/examples/s4u/dumb/s4u_test.cpp
new file mode 100644 (file)
index 0000000..6087684
--- /dev/null
@@ -0,0 +1,51 @@
+/* Copyright (c) 2006-2015. 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/s4u.h"
+
+using namespace simgrid;
+using namespace s4u;
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
+
+class Worker : Actor {
+public:
+       Worker(const char*procname, Host *host,int argc, char **argv)
+                       : s4u::Actor(procname,host,argc,argv){}
+
+       int main(int argc, char **argv) {
+               XBT_INFO("Hello s4u, I'm ready to serve");
+
+               char *msg = recvstr(*Mailbox::byName("worker"));
+               XBT_INFO("I received '%s'",msg);
+               XBT_INFO("I'm done. See you.");
+               return 1;
+       }
+};
+
+class Master : Actor {
+public:
+       Master(const char*procname, Host *host,int argc, char **argv)
+                       : Actor(procname,host,argc,argv){}
+
+       int main(int argc, char **argv) {
+               XBT_INFO("Hello s4u, I have something to send");
+               sendstr(*Mailbox::byName("worker"),"GaBuZoMeu");
+
+               XBT_INFO("I'm done. See you.");
+               return 1;
+       }
+};
+
+
+int main(int argc, char **argv) {
+       Engine *e = new Engine(&argc,argv);
+       e->loadPlatform("../../platforms/two_hosts_platform.xml");
+
+       new Worker("worker", Host::byName("host0"), 0, NULL);
+       new Master("master", Host::byName("host1"), 0, NULL);
+       e->run();
+       return 0;
+}
diff --git a/examples/s4u/dumb/s4u_test.tesh b/examples/s4u/dumb/s4u_test.tesh
new file mode 100644 (file)
index 0000000..ae282fb
--- /dev/null
@@ -0,0 +1,8 @@
+#! ./tesh
+
+$ $SG_TEST_EXENV ./s4u_test
+> [host0:worker:(0) 0.000000] [s4u_test/INFO] Hello s4u, I'm ready to serve
+> [host1:master:(0) 0.000000] [s4u_test/INFO] Hello s4u, I have something to send
+> [host0:worker:(0) 0.001301] [s4u_test/INFO] I received 'GaBuZoMeu'
+> [host0:worker:(0) 0.001301] [s4u_test/INFO] I'm done. See you.
+> [host1:master:(0) 0.001301] [s4u_test/INFO] I'm done. See you.
diff --git a/include/simgrid/s4u.h b/include/simgrid/s4u.h
new file mode 100644 (file)
index 0000000..3d3d966
--- /dev/null
@@ -0,0 +1,14 @@
+/* Copyright (c) 2004-2015. 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. */
+
+#ifndef SIMGRID_S4U_S4U_H
+#define SIMGRID_S4U_S4U_H
+
+#include "s4u/actor.hpp"
+#include "s4u/mailbox.hpp"
+#include "s4u/engine.hpp"
+#include "s4u/host.hpp"
+
+#endif /* SIMGRID_S4U_S4U_H */
diff --git a/include/simgrid/s4u/actor.hpp b/include/simgrid/s4u/actor.hpp
new file mode 100644 (file)
index 0000000..5e4bfba
--- /dev/null
@@ -0,0 +1,140 @@
+/* Copyright (c) 2006-2015. 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. */
+
+#ifndef SIMGRID_S4U_ACTOR_HPP
+#define SIMGRID_S4U_ACTOR_HPP
+
+#include "simgrid/simix.h"
+
+namespace simgrid {
+namespace s4u {
+
+class Comm;
+class Host;
+class Mailbox;
+
+/** @brief Simulation Agent
+ *
+ * An actor may be defined as a code executing in a location (host).
+ *
+ * All actors should be started from the XML deployment file (using the @link{s4u::Engine::loadDeployment()}),
+ * even if you can also start new actors directly.
+ * Separating the deployment in the XML from the logic in the code is a good habit as it makes your simulation easier
+ * to adapt to new settings.
+ *
+ * The code that you define for a given actor should be placed in the main method that is virtual.
+ * For example, a Worker actor should be declared as follows:
+ *
+ * \verbatim
+ * #include "s4u/actor.hpp"
+ *
+ * class Worker : simgrid::s4u::Actor {
+ *
+ *       int main(int argc, char **argv) {
+ *             printf("Hello s4u");
+ *       }
+ * };
+ * \endverbatim
+ *
+ */
+class Actor {
+       friend Comm;
+public:
+       Actor(const char*name, s4u::Host *host, int argc, char **argv);
+       Actor(const char*name, s4u::Host *host, int argc, char **argv, double killTime);
+       virtual ~Actor() {}
+
+       /** The main method of your agent */
+       virtual int main(int argc, char **argv)=0;
+
+       /** The Actor that is currently running */
+       static Actor *current();
+       /** Retrieves the actor that have the given PID (or NULL if not existing) */
+       static Actor *byPid(int pid);
+
+       /** Retrieves the name of that actor */
+       const char*getName();
+       /** Retrieves the host on which that actor is running */
+       s4u::Host *getHost();
+       /** Retrieves the PID of that actor */
+       int getPid();
+
+       /** If set to true, the actor will automatically restart when its host reboots */
+       void setAutoRestart(bool autorestart);
+       /** Sets the time at which that actor should be killed */
+       void setKillTime(double time);
+       /** Retrieves the time at which that actor will be killed (or -1 if not set) */
+       double getKillTime();
+
+       /** Ask kindly to all actors to die. Only the issuer will survive. */
+       static void killAll();
+       /** Ask the actor to die.
+        *
+        * It will only notice your request when doing a simcall next time (a communication or similar).
+        * SimGrid sometimes have issues when you kill actors that are currently communicating and such. We are working on it to fix the issues.
+        */
+       void kill();
+
+       /** Block the actor sleeping for that amount of seconds (may throws hostFailure) */
+       void sleep(double duration);
+
+       /** Block the actor, computing the given amount of flops */
+       void execute(double flop);
+
+       /** Block the actor until it gets a message from the given mailbox */
+       //void* recv(const char *mailbox);
+
+       /** Block the actor until it gets a string message (to be freed after use) from the given mailbox */
+       char *recvstr(Mailbox &chan);
+
+       /** Block the actor until it delivers a string message (that will be copied) to the given mailbox */
+       void sendstr(Mailbox &chan, const char*msg);
+
+       /** Creates (but don't start) an async send action */
+       Comm &send_init(Mailbox &chan);
+
+protected:
+       smx_process_t getInferior() {return p_smx_process;}
+private:
+       smx_process_t p_smx_process;
+};
+}} // namespace simgrid::s4u
+
+#endif /* SIMGRID_S4U_ACTOR_HPP */
+
+#if 0
+
+public abstract class Actor implements Runnable {
+       /** Suspends the process. See {@link #resume()} to resume it afterward */
+       public native void suspend();
+       /** Resume a process that was suspended by {@link #suspend()}. */
+       public native void resume();    
+       /** Tests if a process is suspended. */
+       public native boolean isSuspended();
+       
+       /**
+        * Returns the value of a given process property. 
+        */
+       public native String getProperty(String name);
+
+
+       /**
+        * Migrates a process to another host.
+        *
+        * @param host                  The host where to migrate the process.
+        *
+        */
+       public native void migrate(Host host);  
+
+       public native void exit();    
+       /**
+        * This static method returns the current amount of processes running
+        *
+        * @return                      The count of the running processes
+        */ 
+       public native static int getCount();
+
+}
+#endif
diff --git a/include/simgrid/s4u/async.hpp b/include/simgrid/s4u/async.hpp
new file mode 100644 (file)
index 0000000..6d76288
--- /dev/null
@@ -0,0 +1,74 @@
+/* Copyright (c) 2006-2015. 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. */
+
+#ifndef SIMGRID_S4U_ASYNC_HPP
+#define SIMGRID_S4U_ASYNC_HPP
+
+namespace simgrid {
+namespace s4u {
+
+/* Forward declaration */
+class Comm;
+
+typedef enum {
+       inited, started, finished
+} e_s4u_async_state_t;
+
+/** @brief Asynchronous Actions
+ *
+ * This class is the ancestor of every asynchronous actions, that is, of actions that do take time in the simulated world.
+ */
+class Async {
+       friend Comm;
+protected:
+       Async();
+       virtual ~Async();
+       
+private:
+       smx_synchro_t p_inferior = NULL;
+
+private:
+       e_s4u_async_state_t p_state = inited;
+public:
+       /** Starts a previously created async.
+        *
+        * This function is optional: you can call wait() even if you didn't call start()
+        */
+       virtual void start()=0;
+       /** Tests whether the given async is terminated yet */
+       //virtual bool test()=0;
+       /** Blocks until the async is terminated */
+       virtual void wait()=0;
+       /** Blocks until the async is terminated, or until the timeout is elapsed
+        *  Raises: timeout exception.*/
+       virtual void wait(double timeout)=0;
+       /** Cancel that async */
+       //virtual void cancel();
+       /** Retrieve the current state of the async */
+       e_s4u_async_state_t getState() {return p_state;}
+
+private:
+       double p_remains = 0;
+public:
+       /** Get the remaining amount of work that this Async entails. When it's 0, it's done. */
+       double getRemains();
+       /** Set the [remaining] amount of work that this Async will entail
+        *
+        * It is forbidden to change the amount of work once the Async is started */
+       void setRemains(double remains);
+
+private:
+       void *p_userData = NULL;
+public:
+       /** Put some user data onto the Async */
+       void setUserData(void *data) {p_userData=data;}
+       /** Retrieve the user data of the Async */
+       void *getUserData() { return p_userData; }
+}; // class
+
+}}; // Namespace simgrid::s4u
+
+#endif /* SIMGRID_S4U_ASYNC_HPP */
diff --git a/include/simgrid/s4u/comm.hpp b/include/simgrid/s4u/comm.hpp
new file mode 100644 (file)
index 0000000..c2d3a59
--- /dev/null
@@ -0,0 +1,84 @@
+/* Copyright (c) 2006-2015. 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. */
+
+#ifndef SIMGRID_S4U_COMM_HPP
+#define SIMGRID_S4U_COMM_HPP
+
+#include "simgrid/s4u/async.hpp"
+#include "simgrid/s4u/mailbox.hpp"
+
+namespace simgrid {
+namespace s4u {
+
+class Mailbox;
+
+/** @brief Communication async
+ *
+ * Represents all asynchronous communications, that you can test or wait onto.
+ */
+class Comm : public Async {
+       Comm() : Async() {}
+public:
+       virtual ~Comm();
+
+public:
+       /** Creates (but don't start) an async send to the mailbox #dest */
+       static Comm &send_init(Actor *sender, Mailbox &dest);
+       /** Creates and start an async send to the mailbox #dest */
+       static Comm &send_async(s4u::Actor *sender, Mailbox &dest, void *data, int simulatedByteAmount);
+    /** Creates (but don't start) an async recv onto the mailbox #from */
+       static Comm &recv_init(Mailbox &from);
+       /** Creates and start an async recv to the mailbox #from */
+       //static Comm &recv_async(Mailbox &from, void *data);
+
+       void start() override;
+       void wait() override;
+       void wait(double timeout) override;
+
+private:
+       double p_rate=-1;
+public:
+       /** Sets the maximal communication rate (in byte/sec). Must be done before start */
+       void setRate(double rate);
+
+private:
+       void *p_dstBuff = NULL;
+       size_t p_dstBuffSize = 0;
+       void *p_srcBuff = NULL;
+       size_t p_srcBuffSize = sizeof(void*);
+public:
+       /** Specify the data to send */
+       void setSrcData(void * buff);
+       /** Specify the size of the data to send */
+       void setSrcDataSize(size_t size);
+       /** Specify the data to send and its size */
+       void setSrcData(void * buff, size_t size);
+
+       /** Specify where to receive the data */
+       void setDstData(void ** buff);
+       /** Specify the buffer in which the data should be received */
+       void setDstData(void ** buff, size_t size);
+       /** Retrieve the size of the received data */
+       size_t getDstDataSize();
+
+
+private: /* FIXME: expose these elements in the API */
+       int p_detached = 0;
+    int (*p_matchFunction)(void *, void *, smx_synchro_t) = NULL;
+    void (*p_cleanFunction)(void *) = NULL;
+    void (*p_copyDataFunction)(smx_synchro_t, void*, size_t) = NULL;
+
+
+
+
+private:
+       Actor *p_sender = NULL;
+       Mailbox *p_mailbox = NULL;
+};
+
+}} // namespace simgrid::s4u
+
+#endif /* SIMGRID_S4U_COMM_HPP */
diff --git a/include/simgrid/s4u/engine.hpp b/include/simgrid/s4u/engine.hpp
new file mode 100644 (file)
index 0000000..96ef4dc
--- /dev/null
@@ -0,0 +1,49 @@
+/* Copyright (c) 2006-2015. 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. */
+
+#ifndef SIMGRID_S4U_ENGINE_HPP
+#define SIMGRID_S4U_ENGINE_HPP
+
+namespace simgrid {
+namespace s4u {
+/** @brief Simulation engine
+ *
+ * This class is an interface to the simulation engine.
+ */
+class Engine {
+public:
+       /** Constructor, taking the command line parameters of your main function */
+       Engine(int *argc, char **argv);
+
+       /** @brief Load a platform file describing the environment
+        *
+        * The environment is either a XML file following the simgrid.dtd formalism, or a lua file.
+        * Some examples can be found in the directory examples/platforms.
+        */
+       void loadPlatform(const char *platf);
+
+       /** 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 a function as the default main function of actors
+        *
+        * It will be used as fallback when the function requested from the deployment file was not registered.
+        * It is used for trace-based simulations (see examples/msg/actions).
+        */
+       void register_default(int (*code)(int,char**));
+
+       /** @brief Load a deployment file and launch the actors that it contains */
+       void loadDeployment(const char *deploy);
+
+       /** @brief Run the simulation */
+       void run();
+
+       /** @brief Retrieve the simulation time */
+       static double getClock();
+       
+};
+}} // namespace simgrid::sgo
+
+#endif /* SIMGRID_S4U_ENGINE_HPP */
diff --git a/include/simgrid/s4u/host.hpp b/include/simgrid/s4u/host.hpp
new file mode 100644 (file)
index 0000000..6998b87
--- /dev/null
@@ -0,0 +1,164 @@
+/* Copyright (c) 2006-2015. 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. */
+
+#ifndef SIMGRID_S4U_HOST_HPP
+#define SIMGRID_S4U_HOST_HPP
+
+#include <boost/unordered_map.hpp>
+
+#include "simgrid/simix.h"
+
+namespace simgrid {
+namespace s4u {
+
+class Actor;
+
+/** @brief Simulated machine that can host some actors
+ *
+ * It represents some physical resource with computing and networking capabilities.
+ *
+ * All hosts are automatically created during the call of the method
+ * @link{simgrid::s4u::Engine::loadPlatform()}.
+ * You cannot create a host yourself.
+ *
+ * You can retrieve a particular host using @link{simgrid::s4u::Host.byName()},
+ * and actors can retrieve the host on which they run using @link{simgrid::s4u::Host.current()}.
+ */
+class Host {
+private:
+       Host(const char *name);
+public:
+       /** Retrieves an host from its name. */
+       static s4u::Host *byName(std::string name);
+       /** Retrieves the host on which the current actor is running */
+       static s4u::Host *current();
+
+       const char* getName();
+
+       /** Turns that host on if it was previously off
+        *
+        * All actors on that host which were marked autorestart will be restarted automatically.
+        * This call does nothing if the host is already on.
+        */
+       void turnOn();
+       /** Turns that host off. All actors are forcefully stopped. */
+       void turnOff();
+       /** Returns if that host is currently up and running */
+       bool isOn();
+
+
+       /** Allows to store user data on that host */
+       void setData(void *data) {p_userdata = data;}
+       /** Retrieves the previously stored data */
+       void* getData() {return p_userdata;}
+
+protected:
+       friend Actor;
+       sg_host_t getInferior() {return p_sghost;}
+private:
+       void*p_userdata=NULL;
+       sg_host_t p_sghost;
+       static boost::unordered_map<std::string, s4u::Host *> *hosts;
+};
+
+}} // namespace simgrid::s4u
+
+#endif /* SIMGRID_S4U_HOST_HPP */
+
+#if 0
+/* Bindings to the MSG hosts */
+
+/* Copyright (c) 2006-2014. 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. */
+
+package org.simgrid.msg;
+
+import org.simgrid.msg.Storage;
+
+/*
+Host jacquelin;
+
+try { 
+       jacquelin = Host.getByName("Jacquelin");
+} catch(HostNotFoundException e) {
+       System.err.println(e.toString());
+}
+...
+\endverbatim
+ *
+ */ 
+public class Host {
+       /**
+        * This static method returns all of the hosts of the installed platform.
+        *
+        * @return                      An array containing all the hosts installed.
+        *
+        */ 
+       public native static Host[] all();
+
+       /** 
+        * This static method sets a mailbox to receive in asynchronous mode.
+        * 
+        * All messages sent to this mailbox will be transferred to 
+        * the receiver without waiting for the receive call. 
+        * The receive call will still be necessary to use the received data.
+        * If there is a need to receive some messages asynchronously, and some not, 
+        * two different mailboxes should be used.
+        *
+        * @param mailboxName The name of the mailbox
+        */
+       public static native void setAsyncMailbox(String mailboxName);
+
+       /**
+        * This method returns the number of tasks currently running on a host.
+        * The external load (comming from an availability trace) is not taken in account.
+        *
+        * @return                      The number of tasks currently running on a host.
+        */ 
+       public native int getLoad();
+
+       /**
+        * This method returns the speed of the processor of a host,
+        * regardless of the current load of the machine.
+        *
+        * @return                      The speed of the processor of the host in flops.
+        *
+        */ 
+       public native double getSpeed();
+
+       /**
+        * This method returns the number of core of a host.
+        *
+        * @return                      The speed of the processor of the host in flops.
+        *
+        */ 
+       public native double getCoreNumber();
+
+       /**
+        * Returns the value of a given host property (set from the platform file).
+        */
+       public native String getProperty(String name);
+
+       /**
+        * Change the value of a given host property. 
+        */
+       public native void setProperty(String name, String value);
+
+       /** This methods returns the list of mount point names on an host
+        * @return An array containing all mounted storages on the host
+        */
+       public native Storage[] getMountedStorage();
+
+       /** This methods returns the list of storages attached to an host
+        * @return An array containing all storages (name) attached to the host
+        */
+       public native String[] getAttachedStorage();
+
+
+} 
+#endif
diff --git a/include/simgrid/s4u/mailbox.hpp b/include/simgrid/s4u/mailbox.hpp
new file mode 100644 (file)
index 0000000..d98da45
--- /dev/null
@@ -0,0 +1,47 @@
+/* Copyright (c) 2006-2015. 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. */
+
+#ifndef SIMGRID_S4U_MAILBOX_HPP
+#define SIMGRID_S4U_MAILBOX_HPP
+
+#include <boost/unordered_map.hpp>
+
+#include "actor.hpp"
+
+namespace simgrid {
+namespace s4u {
+
+class Comm;
+
+/** @brief Mailboxes
+ *
+ * Rendez-vous point for network communications, similar to URLs on which you could post and retrieve data.
+ * They are not network locations: you can post and retrieve on a given mailbox from anywhere on the network.
+ * You can access any mailbox without any latency. The network delay are only related to the location of the
+ * sender and receiver.
+ */
+class Mailbox {
+       friend Comm;
+
+private:
+       Mailbox(const char*name, smx_rdv_t inferior);
+public:
+       ~Mailbox();
+       
+protected:
+       smx_rdv_t getInferior() { return p_inferior; }
+
+public:
+       /** Retrieve the mailbox associated to the given string */
+       static Mailbox *byName(const char *name);
+
+private:
+       std::string p_name;
+       smx_rdv_t p_inferior;
+       static boost::unordered_map<std::string, Mailbox *> *channels;
+};
+}} // namespace simgrid::s4u
+
+#endif /* SIMGRID_S4U_MAILBOX_HPP */
diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp
new file mode 100644 (file)
index 0000000..74264b5
--- /dev/null
@@ -0,0 +1,103 @@
+/* Copyright (c) 2006-2014. 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 "xbt/log.h"
+#include "msg/msg_private.h"
+#include "msg/msg_mailbox.h"
+
+#include "simgrid/s4u/actor.hpp"
+#include "simgrid/s4u/comm.hpp"
+#include "simgrid/s4u/host.hpp"
+#include "simgrid/s4u/mailbox.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor,"S4U actors");
+
+/* C main function of a actor, running this->main */
+static int s4u_actor_runner(int argc, char **argv) {
+
+       smx_process_t smx_proc = SIMIX_process_self();
+       simgrid::s4u::Actor *actor = (simgrid::s4u::Actor*) SIMIX_process_self_get_data(smx_proc);
+       int res = actor->main(argc,argv);
+       return res;
+}
+
+
+
+using namespace simgrid;
+
+s4u::Actor::Actor(const char *name, s4u::Host *host, int argc, char **argv)
+    : s4u::Actor::Actor(name,host, argc,argv, -1) {
+}
+s4u::Actor::Actor(const char *name, s4u::Host *host, int argc, char **argv, double killTime) {
+       p_smx_process = simcall_process_create(name, s4u_actor_runner, this, host->getName(), killTime, argc, argv, NULL/*properties*/,0);
+
+       xbt_assert(p_smx_process,"Cannot create the actor");
+//     TRACE_msg_process_create(procname, simcall_process_get_PID(p_smx_process), host->getInferior());
+//     simcall_process_on_exit(p_smx_process,(int_f_pvoid_pvoid_t)TRACE_msg_process_kill,p_smx_process);
+}
+
+s4u::Actor *s4u::Actor::current() {
+       smx_process_t smx_proc = SIMIX_process_self();
+       return (simgrid::s4u::Actor*) SIMIX_process_self_get_data(smx_proc);
+}
+s4u::Actor *s4u::Actor::byPid(int pid) {
+       return (simgrid::s4u::Actor*) SIMIX_process_self_get_data(SIMIX_process_from_PID(pid));
+}
+
+void s4u::Actor::setAutoRestart(bool autorestart) {
+       simcall_process_auto_restart_set(p_smx_process,autorestart);
+}
+
+s4u::Host *s4u::Actor::getHost() {
+       return s4u::Host::byName(sg_host_name(simcall_process_get_host(p_smx_process)));
+}
+const char* s4u::Actor::getName() {
+       return simcall_process_get_name(p_smx_process);
+}
+int s4u::Actor::getPid(){
+       return simcall_process_get_PID(p_smx_process);
+}
+
+void s4u::Actor::setKillTime(double time) {
+       simcall_process_set_kill_time(p_smx_process,time);
+}
+double s4u::Actor::getKillTime() {
+       return simcall_process_get_kill_time(p_smx_process);
+}
+void s4u::Actor::killAll() {
+       simcall_process_killall(1);
+}
+void s4u::Actor::kill() {
+       simcall_process_kill(p_smx_process);
+}
+
+void s4u::Actor::sleep(double duration) {
+       simcall_process_sleep(duration);
+}
+
+void s4u::Actor::execute(double flops) {
+       simcall_process_execute(NULL,flops,1.0/*priority*/,0./*bound*/, 0L/*affinity*/);
+}
+
+char *s4u::Actor::recvstr(Mailbox &chan) {
+       void *res=NULL;
+
+       Comm c = Comm::recv_init(chan);
+       c.setDstData(&res,sizeof(res));
+       c.wait();
+
+    return (char*)res;
+}
+void s4u::Actor::sendstr(Mailbox &chan, const char*msg) {
+       Comm c = Comm::send_init(this,chan);
+       c.setRemains(strlen(msg));
+       c.setSrcData(xbt_strdup(msg),sizeof(char*));
+       c.wait();
+}
+
+s4u::Comm &s4u::Actor::send_init(Mailbox &chan) {
+       return s4u::Comm::send_init(this, chan);
+}
diff --git a/src/s4u/s4u_async.cpp b/src/s4u/s4u_async.cpp
new file mode 100644 (file)
index 0000000..7088472
--- /dev/null
@@ -0,0 +1,28 @@
+/* Copyright (c) 2006-2015. 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 "xbt/log.h"
+#include "msg/msg_private.h"
+#include "msg/msg_mailbox.h"
+
+#include "simgrid/s4u/async.hpp"
+
+XBT_LOG_EXTERNAL_CATEGORY(s4u);
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_async,s4u,"S4U asynchronous actions");
+using namespace simgrid;
+
+s4u::Async::Async() {
+
+}
+s4u::Async::~Async() {
+
+}
+
+void s4u::Async::setRemains(double remains) {
+       xbt_assert(p_state == inited, "Cannot change the remaining amount of work once the Async is started");
+       p_remains = remains;
+}
+
diff --git a/src/s4u/s4u_comm.cpp b/src/s4u/s4u_comm.cpp
new file mode 100644 (file)
index 0000000..44f526e
--- /dev/null
@@ -0,0 +1,142 @@
+/* Copyright (c) 2006-2015. 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 "xbt/log.h"
+#include "msg/msg_private.h"
+#include "msg/msg_mailbox.h"
+
+#include "simgrid/s4u/comm.hpp"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_comm,s4u_async,"S4U asynchronous communications");
+using namespace simgrid;
+
+s4u::Comm::~Comm() {
+
+}
+
+s4u::Comm &s4u::Comm::send_init(s4u::Actor *sender, s4u::Mailbox &chan) {
+       s4u::Comm *res = new s4u::Comm();
+       res->p_sender = sender;
+       res->p_mailbox = &chan;
+
+       return *res;
+}
+s4u::Comm &s4u::Comm::recv_init(s4u::Mailbox &chan) {
+       s4u::Comm *res = new s4u::Comm();
+       res->p_mailbox = &chan;
+
+       return *res;
+}
+
+void s4u::Comm::setRate(double rate) {
+       xbt_assert(p_state==inited);
+       p_rate = rate;
+}
+
+void s4u::Comm::setSrcData(void * buff) {
+       xbt_assert(p_state==inited);
+       xbt_assert(p_dstBuff == NULL, "Cannot set the src and dst buffers at the same time");
+       p_srcBuff = buff;
+}
+void s4u::Comm::setSrcDataSize(size_t size){
+       xbt_assert(p_state==inited);
+       p_srcBuffSize = size;
+}
+void s4u::Comm::setSrcData(void * buff, size_t size) {
+       xbt_assert(p_state==inited);
+
+       xbt_assert(p_dstBuff == NULL, "Cannot set the src and dst buffers at the same time");
+       p_srcBuff = buff;
+       p_srcBuffSize = size;
+}
+void s4u::Comm::setDstData(void ** buff) {
+       xbt_assert(p_state==inited);
+       xbt_assert(p_srcBuff == NULL, "Cannot set the src and dst buffers at the same time");
+       p_dstBuff = buff;
+}
+size_t s4u::Comm::getDstDataSize(){
+       xbt_assert(p_state==finished);
+       return p_dstBuffSize;
+}
+void s4u::Comm::setDstData(void ** buff, size_t size) {
+       xbt_assert(p_state==inited);
+
+       xbt_assert(p_srcBuff == NULL, "Cannot set the src and dst buffers at the same time");
+       p_dstBuff = buff;
+       p_dstBuffSize = size;
+}
+
+void s4u::Comm::start() {
+       xbt_assert(p_state == inited);
+
+       if (p_srcBuff != NULL) { // Sender side
+               p_inferior = simcall_comm_isend(p_sender->getInferior(), p_mailbox->getInferior(), p_remains, p_rate,
+                               p_srcBuff, p_srcBuffSize,
+                               p_matchFunction, p_cleanFunction, p_copyDataFunction,
+                               p_userData, p_detached);
+       } else if (p_dstBuff != NULL) { // Receiver side
+               p_inferior = simcall_comm_irecv(p_mailbox->getInferior(), p_dstBuff, &p_dstBuffSize,
+                               p_matchFunction, p_copyDataFunction,
+                               p_userData, p_rate);
+
+       } else {
+               xbt_die("Cannot start a communication before specifying whether we are the sender or the receiver");
+       }
+       p_state = started;
+}
+void s4u::Comm::wait() {
+       xbt_assert(p_state == started || p_state == inited);
+
+       if (p_state == started)
+               simcall_comm_wait(p_inferior, -1/*timeout*/);
+       else {// p_state == inited. Save a simcall and do directly a blocking send/recv
+               if (p_srcBuff != NULL) {
+                       simcall_comm_send(p_sender->getInferior(), p_mailbox->getInferior(), p_remains, p_rate,
+                                       p_srcBuff, p_srcBuffSize,
+                                       p_matchFunction, p_copyDataFunction,
+                                       p_userData, -1 /*timeout*/);
+               } else {
+                       simcall_comm_recv(p_mailbox->getInferior(), p_dstBuff, &p_dstBuffSize,
+                                       p_matchFunction, p_copyDataFunction,
+                                       p_userData, -1/*timeout*/, p_rate);
+               }
+       }
+       p_state = finished;
+}
+void s4u::Comm::wait(double timeout) {
+       xbt_assert(p_state == started || p_state == inited);
+
+       if (p_state == started) {
+               simcall_comm_wait(p_inferior, timeout);
+               p_state = finished;
+               return;
+       }
+
+       // It's not started yet. Do it in one simcall
+       if (p_srcBuff != NULL) {
+               simcall_comm_send(p_sender->getInferior(), p_mailbox->getInferior(), p_remains, p_rate,
+                               p_srcBuff, p_srcBuffSize,
+                               p_matchFunction, p_copyDataFunction,
+                               p_userData, timeout);
+       } else { // Receiver
+               simcall_comm_recv(p_mailbox->getInferior(), p_dstBuff, &p_dstBuffSize,
+                               p_matchFunction, p_copyDataFunction,
+                               p_userData, timeout, p_rate);
+       }
+       p_state = finished;
+}
+
+s4u::Comm &s4u::Comm::send_async(s4u::Actor *sender, Mailbox &dest, void *data, int simulatedSize) {
+       s4u::Comm &res = s4u::Comm::send_init(sender, dest);
+
+       res.setRemains(simulatedSize);
+       res.p_srcBuff = data;
+       res.p_srcBuffSize = sizeof(void*);
+
+       res.start();
+       return res;
+}
+
diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp
new file mode 100644 (file)
index 0000000..dc22416
--- /dev/null
@@ -0,0 +1,43 @@
+/* s4u::Engine Simulation Engine and global functions. */
+
+/* Copyright (c) 2006-2015. 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/simix.h"
+#include "mc/mc.h"
+#include "simgrid/s4u/engine.hpp"
+
+XBT_LOG_NEW_CATEGORY(s4u,"Log channels of the S4U (Simgrid for you) interface");
+using namespace simgrid;
+
+double s4u::Engine::getClock() {
+       return SIMIX_get_clock();
+}
+
+s4u::Engine::Engine(int *argc, char **argv) {
+       SIMIX_global_init(argc, argv);
+}
+
+void s4u::Engine::loadPlatform(const char *platf) {
+       SIMIX_create_environment(platf);
+}
+
+void s4u::Engine::register_function(const char*name, int (*code)(int,char**)) {
+       SIMIX_function_register(name,code);
+}
+void s4u::Engine::register_default(int (*code)(int,char**)) {
+       SIMIX_function_register_default(code);
+}
+void s4u::Engine::loadDeployment(const char *deploy) {
+       SIMIX_launch_application(deploy);
+}
+
+void s4u::Engine::run() {
+       if (MC_is_active()) {
+               MC_run();
+       } else {
+               SIMIX_run();
+       }
+}
diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp
new file mode 100644 (file)
index 0000000..c9204c3
--- /dev/null
@@ -0,0 +1,56 @@
+/* Copyright (c) 2006-2014. 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 "xbt/log.h"
+#include "msg/msg_private.h"
+#include "simix/smx_process_private.h"
+
+#include "simgrid/s4u/host.hpp"
+
+using namespace simgrid;
+
+boost::unordered_map<std::string, simgrid::s4u::Host*> *simgrid::s4u::Host::hosts
+               = new boost::unordered_map<std::string, simgrid::s4u::Host*>();
+
+s4u::Host::Host(const char*name) {
+       p_sghost = sg_host_by_name(name);
+       if (p_sghost==NULL)
+               xbt_die("No such host: %s",name); //FIXME: raise an exception
+}
+
+s4u::Host *s4u::Host::byName(std::string name) {
+       s4u::Host * res = NULL;
+       try {
+               res = hosts->at(name);
+       } catch (std::out_of_range& e) {}
+
+       if (res==NULL) {
+               res = new s4u::Host(name.c_str());
+               hosts->insert({name,res});
+       }
+       return res;
+}
+s4u::Host *s4u::Host::current(){
+       smx_process_t smx_proc = SIMIX_process_self();
+       if (smx_proc == NULL)
+               xbt_die("Cannot call Host::current() from the maestro context");
+
+       return s4u::Host::byName(SIMIX_host_get_name(SIMIX_process_get_host(smx_proc)));
+}
+
+const char* s4u::Host::getName() {
+       return sg_host_name(p_sghost);
+}
+
+void s4u::Host::turnOn() {
+       simcall_host_on(p_sghost);
+}
+void s4u::Host::turnOff() {
+       simcall_host_off(p_sghost);
+}
+bool s4u::Host::isOn() {
+       return simcall_host_get_state(p_sghost);
+}
diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_mailbox.cpp
new file mode 100644 (file)
index 0000000..4c83d69
--- /dev/null
@@ -0,0 +1,34 @@
+/* Copyright (c) 2006-2015. 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 "xbt/log.h"
+#include "msg/msg_private.h"
+#include "msg/msg_mailbox.h"
+
+#include "simgrid/s4u/mailbox.hpp"
+
+XBT_LOG_EXTERNAL_CATEGORY(s4u);
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_channel,s4u,"S4U Communication Mailboxes");
+
+
+using namespace simgrid;
+
+boost::unordered_map <std::string, s4u::Mailbox *> *s4u::Mailbox::channels = new boost::unordered_map<std::string, s4u::Mailbox*> ();
+
+
+s4u::Mailbox::Mailbox(const char*name, smx_rdv_t inferior) {
+       p_inferior = inferior;
+       channels->insert({name, this});
+}
+s4u::Mailbox *s4u::Mailbox::byName(const char*name) {
+       s4u::Mailbox * res;
+       try {
+               res = channels->at(name);
+       } catch (std::out_of_range& e) {
+               res = new Mailbox(name,simcall_rdv_create(name));
+       }
+       return res;
+}
index e433f10..7ff5f3d 100644 (file)
@@ -279,6 +279,8 @@ IF(NOT enable_memcheck)
   ADD_TEST(msg-icomms-waitany                      ${CMAKE_BINARY_DIR}/examples/msg/icomms/peer3 ${CMAKE_HOME_DIRECTORY}/examples/platforms/small_platform.xml ${CMAKE_HOME_DIRECTORY}/examples/msg/icomms/deployment_peer05.xml)
   # END TESH TESTS
 
+  ### S4U ###
+  ADD_TESH_FACTORIES(s4u-dumb "thread;ucontext;raw;boost" --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/dumb s4u_test.tesh)
 
   ### SIMDAG ###
   # BEGIN TESH TESTS
index fa90c08..fdff550 100644 (file)
@@ -378,6 +378,15 @@ else()
       src/simix/smx_context_boost.cpp)
 endif()
 
+set(S4U_SRC
+  src/s4u/s4u_actor.cpp
+  src/s4u/s4u_async.cpp
+  src/s4u/s4u_comm.cpp
+  src/s4u/s4u_engine.cpp  
+  src/s4u/s4u_host.cpp  
+  src/s4u/s4u_mailbox.cpp
+)
+
 set(SIMGRID_SRC
   src/simgrid/sg_config.c
   src/simgrid/host.cpp
@@ -683,6 +692,13 @@ set(headers_to_install
   include/simgrid/simix.h
   include/simgrid/host.h
   include/simgrid/link.h
+  include/simgrid/s4u/actor.hpp
+  include/simgrid/s4u/async.hpp
+  include/simgrid/s4u/comm.hpp
+  include/simgrid/s4u/engine.hpp  
+  include/simgrid/s4u/host.hpp  
+  include/simgrid/s4u/mailbox.hpp  
+  include/simgrid/s4u.h
   include/smpi/mpi.h
   include/smpi/smpi.h
   include/smpi/smpi_cocci.h
@@ -766,6 +782,7 @@ endif()
 ### Simgrid Lib sources
 set(simgrid_sources
   ${BINDINGS_SRC}
+  ${S4U_SRC}
   ${MSG_SRC}
   ${SIMDAG_SRC}
   ${SIMGRID_SRC}
@@ -1036,6 +1053,8 @@ set(EXAMPLES_CMAKEFILES_TXT
   examples/msg/suspend/CMakeLists.txt
   examples/msg/token_ring/CMakeLists.txt
   examples/msg/tracing/CMakeLists.txt
+  examples/s4u/CMakeLists.txt
+  examples/s4u/dumb/CMakeLists.txt
   examples/scala/CMakeLists.txt
   examples/scala/master_slave_bypass/CMakeLists.txt
   examples/scala/master_slave_kill/CMakeLists.txt
index 29ab476..9e96457 100644 (file)
@@ -206,6 +206,7 @@ set(source_to_pack
   ${MC_SRC}
   ${MC_SIMGRID_MC_SRC}
   ${MSG_SRC}
+  ${S4U_SRC}
   ${NS3_SRC}
   ${RNGSTREAM_SRC}
   ${SIMDAG_SRC}
index c04c5bc..b50ae4f 100644 (file)
@@ -58,6 +58,9 @@ add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/suspend)
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring)
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/tracing)
 
+add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/s4u)
+add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/s4u/dumb)
+
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala)
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_bypass)
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_kill)