Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
yet another conversion+dungeon
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 2 Dec 2017 14:10:14 +0000 (15:10 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 2 Dec 2017 14:15:07 +0000 (15:15 +0100)
examples/msg/CMakeLists.txt
examples/msg/README.doc
examples/s4u/CMakeLists.txt
examples/s4u/README.doc
examples/s4u/io-raw-storage/s4u-io-raw-storage.cpp [new file with mode: 0644]
examples/s4u/io-raw-storage/s4u-io-raw-storage.tesh [new file with mode: 0644]
teshsuite/msg/CMakeLists.txt
teshsuite/msg/io-raw-storage/io-raw-storage.c [moved from examples/msg/io-storage/io-storage.c with 86% similarity]
teshsuite/msg/io-raw-storage/io-raw-storage.tesh [moved from examples/msg/io-storage/io-storage.tesh with 82% similarity]

index 5202915..50ead3b 100644 (file)
@@ -2,7 +2,7 @@
 foreach(x app-masterworker app-pingpong app-token-ring 
           cloud-capping cloud-masterworker cloud-migration cloud-simple cloud-two-tasks
           dht-pastry energy-consumption energy-onoff energy-pstate energy-vm platform-failures 
-          io-file io-remote io-storage task-priority 
+          io-file io-remote task-priority 
           plugin-hostload
           process-create process-join
           platform-properties process-startkilltime synchro-semaphore trace-categories 
@@ -78,7 +78,7 @@ set(xml_files    ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/a
 
 foreach(x app-chainsend app-masterworker app-pingpong app-token-ring
           cloud-capping cloud-masterworker cloud-migration cloud-simple 
-          cloud-two-tasks dht-pastry dht-kademlia platform-failures io-file io-remote io-storage task-priority 
+          cloud-two-tasks dht-pastry dht-kademlia platform-failures io-file io-remote task-priority 
           process-create process-join process-startkilltime
           platform-properties synchro-semaphore)
   ADD_TESH_FACTORIES(msg-${x} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/${x} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/${x} ${x}.tesh)
index 18acfac..47f3e9d 100644 (file)
@@ -143,10 +143,6 @@ TODO: show the XML files instead if it's what is interesting. On a "XML example
 The examples of this section demonstrate how to interact with the
 simulated storages.
 
-  - <b>Basic example</b>.
-    @ref examples/msg/io-storage/io-storage.c \n
-    All main storage and file functions are demoed.
-    
   - <b>File Management</b>. @ref examples/msg/io-file/io-file.c \n
     This example illustrates the use of operations on file
     (@ref MSG_file_open, @ref MSG_file_read, @ref MSG_file_write,
index 6f9e6d9..af062b2 100644 (file)
@@ -1,9 +1,10 @@
 foreach (example actions-comm actions-storage 
                  actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend actor-priority actor-yield
                  app-masterworker app-pingpong app-token-ring
-                async-wait async-waitany async-waitall
-                energy-link energy-ptask
-                plugin-hostload io mutex)
+                 async-wait async-waitany async-waitall
+                 energy-link energy-ptask
+                 io io-raw-storage
+                 plugin-hostload mutex)
   add_executable       (s4u-${example}  ${example}/s4u-${example}.cpp)
   target_link_libraries(s4u-${example}  simgrid)
   set_target_properties(s4u-${example}  PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example})
@@ -64,9 +65,10 @@ set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a
 foreach(example actions-comm actions-storage 
                 actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend actor-priority actor-yield
                 app-bittorrent app-masterworker app-pingpong app-token-ring 
-               async-wait async-waitall async-waitany
-               dht-chord 
-               energy-link energy-ptask
-               plugin-hostload io mutex)
+                async-wait async-waitall async-waitany
+                dht-chord 
+                energy-link energy-ptask
+                plugin-hostload mutex
+                io io-raw-storage)
   ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/${example} s4u-${example}.tesh)
 endforeach()
index 6c88294..bd3f2d0 100644 (file)
@@ -140,6 +140,15 @@ also the tesh files in the example directories for details.
     Presents a set of event handlers reproducing classical I/O
     primitives (open, read, close).
 
+@subsection s4u_ex_io Simulating disks
+
+The examples of this section demonstrate how to interact with the
+simulated storages.
+
+  - <b>Access to raw storage devices </b>.
+    @ref examples/s4u/io-raw-storage/s4u-io-raw-storage.cpp \n
+    This example illustrates how to simply read and write data on a
+    simulated storage resource.
 */
 
 /**
diff --git a/examples/s4u/io-raw-storage/s4u-io-raw-storage.cpp b/examples/s4u/io-raw-storage/s4u-io-raw-storage.cpp
new file mode 100644 (file)
index 0000000..b4dc505
--- /dev/null
@@ -0,0 +1,58 @@
+/* Copyright (c) 2017. 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.hpp"
+#include <string>
+#include <unordered_map>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(storage, "Messages specific for this simulation");
+
+static void host()
+{
+  /* - Display information on the disks mounted by the current host */
+  XBT_INFO("*** Storage info on %s ***", simgrid::s4u::Host::current()->getCname());
+
+  /* - Retrieve all mount points of current host */
+  std::unordered_map<std::string, simgrid::s4u::Storage*> const& storage_list =
+      simgrid::s4u::Host::current()->getMountedStorages();
+
+  /* - For each disk mounted on host, display disk name and mount point */
+  for (auto const& kv : storage_list)
+    XBT_INFO("Storage name: %s, mount name: %s", kv.second->getCname(), kv.first.c_str());
+
+  /* - Write 200,000 bytes on Disk4 */
+  simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName("Disk4");
+  sg_size_t write                = storage->write(200000);
+  XBT_INFO("Wrote %llu bytes on 'Disk4'", write);
+
+  /*  - Now read 200,000 bytes */
+  sg_size_t read = storage->read(200000);
+  XBT_INFO("Read %llu bytes on 'Disk4'", read);
+
+  /* - Attach some user data to disk1 */
+  XBT_INFO("*** Get/set data for storage element: Disk4 ***");
+
+  char* data = static_cast<char*>(storage->getUserdata());
+
+  XBT_INFO("Get storage data: '%s'", data);
+
+  storage->setUserdata(xbt_strdup("Some user data"));
+  data = static_cast<char*>(storage->getUserdata());
+  XBT_INFO("Set and get data: '%s'", data);
+  xbt_free(data);
+}
+
+int main(int argc, char** argv)
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  e.loadPlatform(argv[1]);
+
+  simgrid::s4u::Actor::createActor("", simgrid::s4u::Host::by_name("denise"), host);
+
+  e.run();
+  XBT_INFO("Simulated time: %g", simgrid::s4u::Engine::getClock());
+
+  return 0;
+}
diff --git a/examples/s4u/io-raw-storage/s4u-io-raw-storage.tesh b/examples/s4u/io-raw-storage/s4u-io-raw-storage.tesh
new file mode 100644 (file)
index 0000000..0a747b5
--- /dev/null
@@ -0,0 +1,12 @@
+#! ./tesh
+
+$ ${bindir:=.}/s4u-io-raw-storage$EXEEXT ${srcdir:=.}/storage/storage.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:@denise) *** Storage info on denise ***
+> [  0.000000] (1:@denise) Storage name: Disk2, mount name: c:
+> [  0.000000] (1:@denise) Storage name: Disk4, mount name: /home
+> [  0.003333] (1:@denise) Wrote 200000 bytes on 'Disk4'
+> [  0.004333] (1:@denise) Read 200000 bytes on 'Disk4'
+> [  0.004333] (1:@denise) *** Get/set data for storage element: Disk4 ***
+> [  0.004333] (1:@denise) Get storage data: '(null)'
+> [  0.004333] (1:@denise) Set and get data: 'Some user data'
+> [  0.004333] (0:maestro@) Simulated time: 0.00433333
index 0ad9b87..b1eee3c 100644 (file)
@@ -4,6 +4,7 @@ foreach(x actions-comm actions-storage
           cloud-sharing get_sender host_on_off host_on_off_recv host_on_off_processes
           process-daemon process-kill process-migration process-suspend process-yield
           energy-ptask
+          io-raw-storage
           trace_integration)
   add_executable       (${x}  ${x}/${x}.c)
   target_link_libraries(${x}  simgrid)
@@ -67,6 +68,7 @@ foreach(x get_sender host_on_off host_on_off_processes host_on_off_recv
     task_destroy_cancel task_listen_from task_progress 
     process-daemon process-kill process-migration process-suspend process-yield
     energy-ptask
+    io-raw-storage
     trace_integration)
   ADD_TESH_FACTORIES(tesh-msg-${x} "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x}/${x}.tesh)
 endforeach()
similarity index 86%
rename from examples/msg/io-storage/io-storage.c
rename to teshsuite/msg/io-raw-storage/io-raw-storage.c
index 5d299ea..c9225d2 100644 (file)
@@ -5,9 +5,10 @@
 
 #include "simgrid/msg.h"
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
+XBT_LOG_NEW_DEFAULT_CATEGORY(storage, "Messages specific for this simulation");
 
-static int host(int argc, char *argv[]){
+static int host(int argc, char* argv[])
+{
   const char* host_name = MSG_host_get_name(MSG_host_self());
 
   /* - Display information on the disks mounted by the current host */
@@ -28,7 +29,7 @@ static int host(int argc, char *argv[]){
 
   /* - Write 200,000 bytes on Disk4 */
   msg_storage_t storage = MSG_storage_get_by_name("Disk4");
-  sg_size_t write = MSG_storage_write(storage, 200000); // Write 200,000 bytes
+  sg_size_t write       = MSG_storage_write(storage, 200000); // Write 200,000 bytes
   XBT_INFO("Wrote %llu bytes on 'Disk4'", write);
 
   /*  - Now read 200,000 bytes */
@@ -50,13 +51,13 @@ static int host(int argc, char *argv[]){
   return 1;
 }
 
-int main(int argc, char *argv[])
+int main(int argc, charargv[])
 {
   MSG_init(&argc, argv);
 
   MSG_create_environment(argv[1]);
   MSG_function_register("host", host);
-  xbt_dynar_t hosts =  MSG_hosts_as_dynar();
+  xbt_dynar_t hosts = MSG_hosts_as_dynar();
   MSG_process_create(NULL, host, NULL, xbt_dynar_get_as(hosts, 3, msg_host_t));
   xbt_dynar_free(&hosts);
 
similarity index 82%
rename from examples/msg/io-storage/io-storage.tesh
rename to teshsuite/msg/io-raw-storage/io-raw-storage.tesh
index 2ee8016..1d7523f 100644 (file)
@@ -1,6 +1,6 @@
 #! ./tesh
 
-$ ${bindir:=.}/io-storage$EXEEXT ${srcdir:=.}/storage/storage.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+$ ${bindir:=.}/io-raw-storage$EXEEXT ${platfdir:=.}/storage/storage.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
 > [  0.000000] (1:@denise) *** Storage info on denise ***
 > [  0.000000] (1:@denise) Storage name: Disk2, mount name: c:
 > [  0.000000] (1:@denise) Storage name: Disk4, mount name: /home