Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'S4U'
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 13 Oct 2015 22:06:18 +0000 (00:06 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 13 Oct 2015 22:06:18 +0000 (00:06 +0200)
32 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]
examples/s4u/io/.gitignore [new file with mode: 0644]
examples/s4u/io/CMakeLists.txt [new file with mode: 0644]
examples/s4u/io/s4u_io_test.cpp [new file with mode: 0644]
examples/s4u/io/s4u_io_test.tesh [new file with mode: 0644]
include/simgrid/msg.h
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/file.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]
include/simgrid/s4u/storage.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_file.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]
src/s4u/s4u_storage.cpp [new file with mode: 0644]
tools/cmake/DefinePackages.cmake
tools/cmake/Distrib.cmake
tools/cmake/MakeExe.cmake
tools/cmake/Tests.cmake

index 6dff2de..6e70b85 100644 (file)
@@ -182,6 +182,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..cae2b42
--- /dev/null
@@ -0,0 +1,26 @@
+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
+  )
+
+add_subdirectory(dumb)
+add_subdirectory(io)
\ No newline at end of file
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..678d16f
--- /dev/null
@@ -0,0 +1,52 @@
+/* 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 = (char*)recv(*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) {
+               const char *msg = "GaBuZoMeu";
+               XBT_INFO("Hello s4u, I have something to send");
+               send(*Mailbox::byName("worker"), xbt_strdup(msg), strlen(msg));
+
+               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/examples/s4u/io/.gitignore b/examples/s4u/io/.gitignore
new file mode 100644 (file)
index 0000000..fa4d495
--- /dev/null
@@ -0,0 +1 @@
+s4u_io_test
diff --git a/examples/s4u/io/CMakeLists.txt b/examples/s4u/io/CMakeLists.txt
new file mode 100644 (file)
index 0000000..efc26cd
--- /dev/null
@@ -0,0 +1,21 @@
+set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}")
+add_executable(s4u_io_test ${CMAKE_CURRENT_SOURCE_DIR}/s4u_io_test.cpp)
+target_link_libraries(s4u_io_test simgrid)
+
+set(tesh_files
+  ${tesh_files}
+  ${CMAKE_CURRENT_SOURCE_DIR}/s4u_io.tesh
+  PARENT_SCOPE)
+set(xml_files
+  ${xml_files}
+  PARENT_SCOPE)
+set(examples_src
+  ${examples_src}
+  ${CMAKE_CURRENT_SOURCE_DIR}/s4u_io_test.cpp
+  PARENT_SCOPE)
+set(bin_files
+  ${bin_files}
+  PARENT_SCOPE)
+set(txt_files
+  ${txt_files}
+  PARENT_SCOPE)
diff --git a/examples/s4u/io/s4u_io_test.cpp b/examples/s4u/io/s4u_io_test.cpp
new file mode 100644 (file)
index 0000000..87a06bf
--- /dev/null
@@ -0,0 +1,114 @@
+/* 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 <vector>
+
+#include "simgrid/s4u.h"
+
+using namespace simgrid;
+using namespace s4u;
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
+
+class myHost : Actor {
+public:
+       myHost(const char*procname, Host *host,int argc, char **argv)
+: s4u::Actor(procname,host,argc,argv){}
+
+       void show_info(boost::unordered_map <std::string, Storage &> &mounts) {
+               XBT_INFO("Storage info on %s:", Host::current()->name());
+
+               for (const auto&kv : mounts) {
+                       const char* mountpoint = kv.first.c_str();
+                       Storage &storage = kv.second;
+
+                       // Retrieve disk's information
+                       sg_size_t free_size = storage.size_free();
+                       sg_size_t used_size = storage.size_used();
+                       sg_size_t size = storage.size();
+
+                       XBT_INFO("    %s (%s) Used: %llu; Free: %llu; Total: %llu.",
+                                       storage.name(), mountpoint, used_size, free_size, size);
+               }
+       }
+
+       int main(int argc, char **argv) {
+               boost::unordered_map <std::string, Storage &> &mounts = Host::current()->mountedStorages();
+
+               show_info(mounts);
+
+               // Open an non-existing file to create it
+               const char *filename = "/home/tmp/data.txt";
+               File *file = new File(filename, NULL);
+               sg_size_t write, read, file_size;
+
+               write = file->write(200000);  // Write 200,000 bytes
+               XBT_INFO("Create a %llu bytes file named '%s' on /sd1", write, filename);
+
+               // check that sizes have changed
+               show_info(mounts);
+
+               // Now retrieve the size of created file and read it completely
+               file_size = file->size();
+               file->seek(0);
+               read = file->read(file_size);
+               XBT_INFO("Read %llu bytes on %s", read, filename);
+
+               // Now write 100,000 bytes in tmp/data.txt
+               write = file->write(100000);  // Write 100,000 bytes
+               XBT_INFO("Write %llu bytes on %s", write, filename);
+
+               Storage &storage = Storage::byName("Disk4");
+
+               // Now rename file from ./tmp/data.txt to ./tmp/simgrid.readme
+               const char *newpath = "/home/tmp/simgrid.readme";
+               XBT_INFO("Move '%s' to '%s'", file->path(), newpath);
+               file->move(newpath);
+
+               // Test attaching some user data to the file
+               file->set_userdata(xbt_strdup("777"));
+               XBT_INFO("User data attached to the file: %s", (char*)file->userdata());
+
+               // Close the file
+               delete file;
+
+               // Now attach some user data to disk1
+               XBT_INFO("Get/set data for storage element: %s",storage.name());
+               XBT_INFO("    Uninitialized storage data: '%s'", (char*)storage.userdata());
+
+               storage.set_userdata(xbt_strdup("Some user data"));
+               XBT_INFO("    Set and get data: '%s'", (char*)storage.userdata());
+
+               /*
+                 // Dump disks contents
+                 XBT_INFO("*** Dump content of %s ***",Host::current()->name());
+                 xbt_dict_t contents = NULL;
+                 contents = MSG_host_get_storage_content(MSG_host_self()); // contents is a dict of dicts
+                 xbt_dict_cursor_t curs, curs2 = NULL;
+                 char* mountname;
+                 xbt_dict_t content;
+                 char* path;
+                 sg_size_t *size;
+                 xbt_dict_foreach(contents, curs, mountname, content){
+                   XBT_INFO("Print the content of mount point: %s",mountname);
+                   xbt_dict_foreach(content,curs2,path,size){
+                      XBT_INFO("%s size: %llu bytes", path,*((sg_size_t*)size));
+                   }
+                 xbt_dict_free(&content);
+                 }
+                 xbt_dict_free(&contents);
+                */
+               return 0;
+       }
+};
+
+int main(int argc, char **argv) {
+       Engine *e = new Engine(&argc,argv);
+       e->loadPlatform("../../platforms/storage/storage.xml");
+
+       new myHost("host", Host::byName("denise"), 0, NULL);
+       e->run();
+       return 0;
+}
diff --git a/examples/s4u/io/s4u_io_test.tesh b/examples/s4u/io/s4u_io_test.tesh
new file mode 100644 (file)
index 0000000..38d673c
--- /dev/null
@@ -0,0 +1,17 @@
+#! ./tesh
+
+$ $SG_TEST_EXENV ./s4u_io_test
+> [denise:host:(0) 0.000000] [s4u_test/INFO] Storage info on denise:
+> [denise:host:(0) 0.000000] [s4u_test/INFO]     Disk4 (/home) Used: 13221994; Free: 536857690006; Total: 536870912000.
+> [denise:host:(0) 0.000000] [s4u_test/INFO]     Disk2 (c:) Used: 2391537133; Free: 534479374867; Total: 536870912000.
+> [denise:host:(0) 0.003333] [s4u_test/INFO] Create a 200000 bytes file named '/home/tmp/data.txt' on /sd1
+> [denise:host:(0) 0.003333] [s4u_test/INFO] Storage info on denise:
+> [denise:host:(0) 0.003333] [s4u_test/INFO]     Disk4 (/home) Used: 13421994; Free: 536857490006; Total: 536870912000.
+> [denise:host:(0) 0.003333] [s4u_test/INFO]     Disk2 (c:) Used: 2391537133; Free: 534479374867; Total: 536870912000.
+> [denise:host:(0) 0.004333] [s4u_test/INFO] Read 200000 bytes on /home/tmp/data.txt
+> [denise:host:(0) 0.006000] [s4u_test/INFO] Write 100000 bytes on /home/tmp/data.txt
+> [denise:host:(0) 0.006000] [s4u_test/INFO] Move '/home/tmp/data.txt' to '/home/tmp/simgrid.readme'
+> [denise:host:(0) 0.006000] [s4u_test/INFO] User data attached to the file: 777
+> [denise:host:(0) 0.006000] [s4u_test/INFO] Get/set data for storage element: Disk4
+> [denise:host:(0) 0.006000] [s4u_test/INFO]     Uninitialized storage data: '(null)'
+> [denise:host:(0) 0.006000] [s4u_test/INFO]     Set and get data: 'Some user data'
index b0f56b5..bd4a8d8 100644 (file)
@@ -266,7 +266,7 @@ XBT_PUBLIC(msg_error_t) MSG_file_seek(msg_file_t fd, sg_offset_t offset, int ori
 XBT_PUBLIC(sg_size_t) MSG_file_tell (msg_file_t fd);
 XBT_PUBLIC(void) __MSG_file_get_info(msg_file_t fd);
 XBT_PUBLIC(void) __MSG_file_priv_free(msg_file_priv_t priv);
-XBT_PUBLIC(const char *) MSG_file_get_name(msg_file_t storage);
+XBT_PUBLIC(const char *) MSG_file_get_name(msg_file_t file);
 XBT_PUBLIC(msg_error_t) MSG_file_move(msg_file_t fd, const char* fullpath);
 XBT_PUBLIC(msg_error_t) MSG_file_rcopy(msg_file_t fd, msg_host_t host, const char* fullpath);
 XBT_PUBLIC(msg_error_t) MSG_file_rmove(msg_file_t fd, msg_host_t host, const char* fullpath);
diff --git a/include/simgrid/s4u.h b/include/simgrid/s4u.h
new file mode 100644 (file)
index 0000000..e58b845
--- /dev/null
@@ -0,0 +1,20 @@
+/* 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"
+
+#include "s4u/async.hpp"
+#include "s4u/comm.hpp"
+
+#include "s4u/storage.hpp"
+#include "s4u/file.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..b8463e6
--- /dev/null
@@ -0,0 +1,141 @@
+/* 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;
+       Actor(smx_process_t smx_proc);
+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);
+
+       /** 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 */
+       e_smx_state_t execute(double flop);
+
+       /** Block the actor until it gets a message from the given mailbox.
+        *
+        * See \ref Comm for the full communication API (including non blocking communications).
+        */
+       void *recv(Mailbox &chan);
+
+       /** Block the actor until it delivers a message of the given simulated size to the given mailbox
+        *
+        * See \ref Comm for the full communication API (including non blocking communications).
+       */
+       void send(Mailbox &chan, void*payload, size_t simulatedSize);
+
+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..838d800
--- /dev/null
@@ -0,0 +1,80 @@
+/* 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
+
+#include <stdlib.h>
+#include <xbt/misc.h>
+
+SG_BEGIN_DECL();
+typedef enum {
+       inited, started, finished
+} e_s4u_async_state_t;
+SG_END_DECL();
+
+namespace simgrid {
+namespace s4u {
+
+/* Forward declaration */
+class Comm;
+
+
+/** @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:
+       struct s_smx_synchro *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..94b74cb
--- /dev/null
@@ -0,0 +1,82 @@
+/* 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(s4u::Actor *receiver, Mailbox &from);
+       /** Creates and start an async recv to the mailbox #from */
+       static Comm &recv_async(s4u::Actor *receiver, 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;
+       Actor *p_receiver = 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/file.hpp b/include/simgrid/s4u/file.hpp
new file mode 100644 (file)
index 0000000..28512e7
--- /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_FILE_HPP
+#define SIMGRID_S4U_FILE_HPP
+
+#include <boost/unordered_map.hpp>
+#include <vector>
+
+#include "simgrid/simix.h"
+
+namespace simgrid {
+namespace s4u {
+
+class Actor;
+class Storage;
+
+/** @brief A simulated file
+ *
+ * Used to simulate the time it takes to access to a file, but does not really store any information.
+ *
+ * They are located on @link{simgrid::s4u::Storage}, that are accessed from a given @link{simgrid::s4u::Host} through mountpoints.
+ * For now, you cannot change the mountpoints programatically, and must declare them from your platform file.
+ */
+class File {
+public:
+       File(const char *fullpath, void* userdata);
+       ~File();
+private:
+       smx_file_t p_inferior;
+       const char *p_path;
+
+public:
+       /** Retrieves the path to the file */
+       const char *path() { return p_path;}
+public:
+       /** Simulates a read action. Returns the size of data actually read
+        *
+        *  FIXME: reading from a remotely mounted disk is not implemented yet. Any storage is considered as local, and no network communication ever occur.
+        */
+       sg_size_t read(sg_size_t size);
+       /** Simulates a write action. Returns the size of data actually written.
+        *
+        *  FIXME: reading from a remotely mounted disk is not implemented yet. Any storage is considered as local, and no network communication ever occur.
+        */
+       sg_size_t write(sg_size_t size);
+
+       /** Allows to store user data on that host */
+       void set_userdata(void *data) {p_userdata = data;}
+       /** Retrieves the previously stored data */
+       void* userdata() {return p_userdata;}
+private:
+       void *p_userdata=NULL;
+
+public:
+       /** Retrieve the datasize */
+       sg_size_t size();
+
+       /** Sets the file head to the given position. */
+       void seek(sg_size_t pos);
+       /** Retrieves the current file position */
+       sg_size_t tell();
+
+       /** Rename a file
+        *
+        * WARNING: It is forbidden to move the file to another mount point */
+       void move(const char*fullpath);
+
+       /** Remove a file from disk */
+       void unlink();
+
+       /* FIXME: add these to the S4U API:
+       XBT_PUBLIC(const char *) MSG_file_get_name(msg_file_t file);
+       XBT_PUBLIC(msg_error_t) MSG_file_rcopy(msg_file_t fd, msg_host_t host, const char* fullpath);
+       XBT_PUBLIC(msg_error_t) MSG_file_rmove(msg_file_t fd, msg_host_t host, const char* fullpath);
+       */
+
+};
+
+}} // namespace simgrid::s4u
+
+#endif /* SIMGRID_S4U_HOST_HPP */
diff --git a/include/simgrid/s4u/host.hpp b/include/simgrid/s4u/host.hpp
new file mode 100644 (file)
index 0000000..74b826b
--- /dev/null
@@ -0,0 +1,175 @@
+/* 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 <vector>
+
+#include "simgrid/simix.h"
+
+namespace simgrid {
+namespace s4u {
+
+class Actor;
+class Storage;
+class File;
+
+/** @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 {
+       friend Actor;
+       friend File;
+private:
+       Host(const char *name);
+protected:
+       ~Host();
+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* name();
+
+       /** 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 set_userdata(void *data) {p_userdata = data;}
+       /** Retrieves the previously stored data */
+       void* userdata() {return p_userdata;}
+
+       /** Get an associative list [mount point]->[Storage] off all local mount points.
+        *
+        *      This is defined in the platform file, and cannot be modified programatically (yet).
+        *
+        *      Do not change the returned value in any way.
+        */
+       boost::unordered_map<std::string, Storage&> &mountedStorages();
+private:
+       boost::unordered_map<std::string, Storage&> *mounts = NULL; // caching
+
+protected:
+       sg_host_t inferior() {return p_inferior;}
+private:
+       void*p_userdata=NULL;
+       sg_host_t p_inferior;
+       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 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..77390cf
--- /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_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:
+       /** Get the name of that mailbox */
+       const char *getName();
+       /** 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 *> *mailboxes;
+};
+}} // namespace simgrid::s4u
+
+#endif /* SIMGRID_S4U_MAILBOX_HPP */
diff --git a/include/simgrid/s4u/storage.hpp b/include/simgrid/s4u/storage.hpp
new file mode 100644 (file)
index 0000000..3447b72
--- /dev/null
@@ -0,0 +1,57 @@
+/* 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 INCLUDE_SIMGRID_S4U_STORAGE_HPP_
+#define INCLUDE_SIMGRID_S4U_STORAGE_HPP_
+
+#include <boost/unordered_map.hpp>
+#include "simgrid/simix.h"
+
+namespace simgrid {
+namespace s4u {
+
+class Storage {
+private:
+       Storage(std::string name, smx_storage_t inferior);
+       virtual ~Storage();
+public:
+       /** Retrieve a Storage by its name. It must exist in the platform file */
+       static Storage &byName(const char* name);
+       const char *name();
+       sg_size_t size_free();
+       sg_size_t size_used();
+       /** Retrieve the total amount of space of this storage element */
+       sg_size_t size();
+
+       /* TODO: missing API:
+XBT_PUBLIC(xbt_dict_t) MSG_storage_get_properties(msg_storage_t storage);
+XBT_PUBLIC(void) MSG_storage_set_property_value(msg_storage_t storage, const char *name, char *value,void_f_pvoid_t free_ctn);
+XBT_PUBLIC(const char *)MSG_storage_get_property_value(msg_storage_t storage, const char *name);
+XBT_PUBLIC(xbt_dynar_t) MSG_storages_as_dynar(void);
+XBT_PUBLIC(xbt_dict_t) MSG_storage_get_content(msg_storage_t storage);
+XBT_PUBLIC(msg_error_t) MSG_storage_file_move(msg_file_t fd, msg_host_t dest, char* mount, char* fullname);
+XBT_PUBLIC(const char *) MSG_storage_get_host(msg_storage_t storage);
+        */
+protected:
+       smx_storage_t inferior();
+private:
+       static boost::unordered_map<std::string, Storage *> *storages;
+       std::string p_name;
+       smx_storage_t p_inferior;
+
+
+public:
+       void set_userdata(void *data) {p_userdata = data;}
+       void *userdata() {return p_userdata;}
+private:
+       void *p_userdata = NULL;
+
+};
+
+} /* namespace s4u */
+} /* namespace simgrid */
+
+#endif /* INCLUDE_SIMGRID_S4U_STORAGE_HPP_ */
diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp
new file mode 100644 (file)
index 0000000..19e332f
--- /dev/null
@@ -0,0 +1,111 @@
+/* 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(smx_process_t smx_proc) {
+       p_smx_process = smx_proc;
+}
+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->name(), 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);
+}
+
+int s4u::Actor::main(int argc, char **argv) {
+       fprintf(stderr,"Error: You should override the method main(int, char**) in Actor class %s\n",getName());
+       return 0;
+}
+s4u::Actor *s4u::Actor::current() {
+       smx_process_t smx_proc = SIMIX_process_self();
+       simgrid::s4u::Actor* res = (simgrid::s4u::Actor*) SIMIX_process_self_get_data(smx_proc);
+       if (res == NULL) // The smx_process was not created by S4U (but by deployment?). Embed it in a S4U object
+               res = new Actor(smx_proc);
+       return res;
+}
+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);
+}
+
+e_smx_state_t s4u::Actor::execute(double flops) {
+       smx_synchro_t s = simcall_process_execute(NULL,flops,1.0/*priority*/,0./*bound*/, 0L/*affinity*/);
+    return simcall_process_execution_wait(s);
+}
+
+void *s4u::Actor::recv(Mailbox &chan) {
+       void *res=NULL;
+
+       Comm c = Comm::recv_init(this, chan);
+       c.setDstData(&res,sizeof(res));
+       c.wait();
+
+    return res;
+}
+void s4u::Actor::send(Mailbox &chan, void *payload, size_t simulatedSize) {
+       Comm c = Comm::send_init(this,chan);
+       c.setRemains(simulatedSize);
+       c.setSrcData(payload);
+       // c.start() is optional.
+       c.wait();
+}
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..02f5e98
--- /dev/null
@@ -0,0 +1,152 @@
+/* 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::Actor *receiver, s4u::Mailbox &chan) {
+       s4u::Comm *res = new s4u::Comm();
+       res->p_receiver = receiver;
+       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_receiver->getInferior(), 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_receiver->getInferior(), 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_receiver->getInferior(), 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;
+}
+
+s4u::Comm &s4u::Comm::recv_async(s4u::Actor *receiver, Mailbox &dest, void **data) {
+       s4u::Comm &res = s4u::Comm::recv_init(receiver, dest);
+
+       res.setDstData(data);
+
+       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_file.cpp b/src/s4u/s4u_file.cpp
new file mode 100644 (file)
index 0000000..dd50829
--- /dev/null
@@ -0,0 +1,58 @@
+/* Copyright (c) 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/actor.hpp"
+#include "simgrid/s4u/comm.hpp"
+#include "simgrid/s4u/host.hpp"
+#include "simgrid/s4u/mailbox.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file,"S4U files");
+
+#include "simgrid/s4u/file.hpp"
+#include "simgrid/s4u/host.hpp"
+#include "simgrid/simix.h"
+
+namespace simgrid {
+namespace s4u {
+
+File::File(const char*fullpath, void *userdata) {
+       // this cannot fail because we get a xbt_die if the mountpoint does not exist
+       p_inferior = simcall_file_open(fullpath, Host::current()->inferior());
+       p_path = fullpath;
+}
+
+File::~File() {
+       simcall_file_close(p_inferior, Host::current()->inferior());
+}
+
+sg_size_t File::read(sg_size_t size) {
+       return simcall_file_read(p_inferior, size, Host::current()->inferior());
+}
+sg_size_t File::write(sg_size_t size) {
+       return simcall_file_write(p_inferior,size, Host::current()->inferior());
+}
+sg_size_t File::size() {
+       return simcall_file_get_size(p_inferior);
+}
+
+void File::seek(sg_size_t pos) {
+       simcall_file_seek(p_inferior,pos,SEEK_SET);
+}
+sg_size_t File::tell() {
+       return simcall_file_tell(p_inferior);
+}
+void File::move(const char*fullpath) {
+       simcall_file_move(p_inferior,fullpath);
+}
+void File::unlink() {
+       sg_host_t attached = Host::current()->inferior(); // FIXME: we should check where this file is attached
+       simcall_file_unlink(p_inferior,attached);
+}
+
+}} // namespace simgrid::s4u
diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp
new file mode 100644 (file)
index 0000000..8456370
--- /dev/null
@@ -0,0 +1,84 @@
+/* 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"
+#include "simgrid/s4u/storage.hpp"
+
+namespace simgrid {
+namespace s4u {
+
+boost::unordered_map<std::string, Host*> *Host::hosts
+               = new boost::unordered_map<std::string, Host*>();
+
+Host::Host(const char*name) {
+       p_inferior = sg_host_by_name(name);
+       if (p_inferior==NULL)
+               xbt_die("No such host: %s",name); //FIXME: raise an exception
+}
+Host::~Host() {
+       if (mounts != NULL)
+               delete mounts;
+}
+
+Host *Host::byName(std::string name) {
+       Host * res = NULL;
+       try {
+               res = hosts->at(name);
+       } catch (std::out_of_range& e) {}
+
+       if (res==NULL) {
+               res = new Host(name.c_str());
+               hosts->insert({name,res});
+       }
+       return res;
+}
+Host *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 Host::byName(SIMIX_host_get_name(SIMIX_process_get_host(smx_proc)));
+}
+
+const char* Host::name() {
+       return sg_host_name(p_inferior);
+}
+
+void Host::turnOn() {
+       simcall_host_on(p_inferior);
+}
+void Host::turnOff() {
+       simcall_host_off(p_inferior);
+}
+bool Host::isOn() {
+       return simcall_host_get_state(p_inferior);
+}
+
+boost::unordered_map<std::string, Storage&> &Host::mountedStorages() {
+       if (mounts == NULL) {
+               mounts = new boost::unordered_map<std::string, Storage&> ();
+
+               xbt_dict_t dict = simcall_host_get_mounted_storage_list(p_inferior);
+
+               xbt_dict_cursor_t cursor;
+               char *mountname;
+               char *storagename;
+               xbt_dict_foreach(dict, cursor, mountname, storagename) {
+                       mounts->insert({mountname, Storage::byName(storagename)});
+               }
+               xbt_dict_free(&dict);
+       }
+
+       return *mounts;
+}
+
+
+} // namespace simgrid
+} // namespace s4u
diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_mailbox.cpp
new file mode 100644 (file)
index 0000000..d18150d
--- /dev/null
@@ -0,0 +1,43 @@
+/* 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::mailboxes = new boost::unordered_map<std::string, s4u::Mailbox*> ();
+
+
+s4u::Mailbox::Mailbox(const char*name, smx_rdv_t inferior) {
+       p_inferior = inferior;
+       p_name = name;
+       mailboxes->insert({name, this});
+}
+const char *s4u::Mailbox::getName() {
+       return p_name.c_str();
+}
+s4u::Mailbox *s4u::Mailbox::byName(const char*name) {
+       s4u::Mailbox *res;
+       try {
+               res = mailboxes->at(name);
+       } catch (std::out_of_range& e) {
+               // FIXME: there is a potential race condition here where two actors run Mailbox::byName on a non-existent mailbox
+               // during the same scheduling round. Both will be interrupted in the simcall creating the underlying simix rdv.
+               // Only one simix object will be created, but two S4U objects will be created.
+               // Only one S4U object will be stored in the hashmap and used, and the other one will be leaked.
+               new Mailbox(name,simcall_rdv_create(name));
+               res = mailboxes->at(name); // Use the stored one, even if it's not the one I created myself.
+       }
+       return res;
+}
diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp
new file mode 100644 (file)
index 0000000..3c5bb11
--- /dev/null
@@ -0,0 +1,59 @@
+/* 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/storage.hpp"
+
+#include "xbt/lib.h"
+extern xbt_lib_t storage_lib;
+
+namespace simgrid {
+namespace s4u {
+
+boost::unordered_map <std::string, Storage *> *Storage::storages = new boost::unordered_map<std::string, Storage*> ();
+Storage::Storage(std::string name, smx_storage_t inferior) {
+       p_name = name;
+       p_inferior = inferior;
+
+       storages->insert({name, this});
+}
+
+Storage::~Storage() {
+       // TODO Auto-generated destructor stub
+}
+
+smx_storage_t Storage::inferior() {
+       return p_inferior;
+}
+Storage &Storage::byName(const char*name) {
+       s4u::Storage *res = NULL;
+       try {
+               res = storages->at(name);
+       } catch (std::out_of_range& e) {
+               smx_storage_t inferior = xbt_lib_get_elm_or_null(storage_lib,name);
+               if (inferior == NULL)
+                       xbt_die("Storage %s does not exist. Please only use the storages that are defined in your platform.", name);
+
+               res = new Storage(name,inferior);
+       }
+       return *res;
+}
+
+const char*Storage::name() {
+       return p_name.c_str();
+}
+
+sg_size_t Storage::size_free() {
+       return simcall_storage_get_free_size(p_inferior);
+}
+sg_size_t Storage::size_used() {
+       return simcall_storage_get_used_size(p_inferior);
+}
+sg_size_t Storage::size() {
+       return SIMIX_storage_get_size(p_inferior);
+}
+
+} /* namespace s4u */
+} /* namespace simgrid */
index 2ef2909..e34d7e3 100644 (file)
@@ -389,6 +389,17 @@ 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_file.cpp  
+  src/s4u/s4u_host.cpp  
+  src/s4u/s4u_mailbox.cpp
+  src/s4u/s4u_storage.cpp
+)
+
 set(SIMGRID_SRC
   src/simgrid/sg_config.c
   src/simgrid/host.cpp
@@ -695,6 +706,15 @@ 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/file.hpp  
+  include/simgrid/s4u/host.hpp  
+  include/simgrid/s4u/mailbox.hpp  
+  include/simgrid/s4u/storage.hpp  
+  include/simgrid/s4u.h
   include/smpi/mpi.h
   include/smpi/smpi.h
   include/smpi/smpi_cocci.h
@@ -779,6 +799,7 @@ endif()
 ### Simgrid Lib sources
 set(simgrid_sources
   ${BINDINGS_SRC}
+  ${S4U_SRC}
   ${MSG_SRC}
   ${SIMDAG_SRC}
   ${SIMGRID_SRC}
@@ -1052,6 +1073,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 77d2dd7..afa1426 100644 (file)
@@ -179,6 +179,7 @@ set(source_to_pack
   ${MC_SRC}
   ${MC_SIMGRID_MC_SRC}
   ${MSG_SRC}
+  ${S4U_SRC}
   ${NS3_SRC}
   ${RNGSTREAM_SRC}
   ${SIMDAG_SRC}
index c04c5bc..fd58228 100644 (file)
@@ -58,6 +58,8 @@ 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/scala)
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_bypass)
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_kill)
index 4bb32bd..3c5612d 100644 (file)
@@ -283,6 +283,10 @@ 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)
+  ADD_TESH_FACTORIES(s4u-io "thread;ucontext;raw;boost" --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/io s4u_io_test.tesh)
+
 
   ### SIMDAG ###
   # BEGIN TESH TESTS