Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert io-remote
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 2 Dec 2017 15:30:08 +0000 (16:30 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 2 Dec 2017 15:30:08 +0000 (16:30 +0100)
examples/s4u/CMakeLists.txt
examples/s4u/README.doc
examples/s4u/io-file-remote/s4u-io-file-remote.cpp [new file with mode: 0644]
examples/s4u/io-file-remote/s4u-io-file-remote.tesh [new file with mode: 0644]
examples/s4u/io-file-remote/s4u-io-file-remote_d.xml [new file with mode: 0644]

index af062b2..4654f87 100644 (file)
@@ -3,7 +3,7 @@ foreach (example actions-comm actions-storage
                  app-masterworker app-pingpong app-token-ring
                  async-wait async-waitany async-waitall
                  energy-link energy-ptask
-                 io io-raw-storage
+                 io io-file-remote io-raw-storage
                  plugin-hostload mutex)
   add_executable       (s4u-${example}  ${example}/s4u-${example}.cpp)
   target_link_libraries(s4u-${example}  simgrid)
@@ -54,6 +54,7 @@ set(xml_files     ${xml_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord_d.xml
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/io-file-remote/s4u-io-file-remote_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actor-lifetime/s4u-actor-lifetime_d.xml
                  PARENT_SCOPE)
 set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm-split-p0.txt
@@ -69,6 +70,6 @@ foreach(example actions-comm actions-storage
                 dht-chord 
                 energy-link energy-ptask
                 plugin-hostload mutex
-                io io-raw-storage)
+                io io-file-remote 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 bd3f2d0..11d4e65 100644 (file)
@@ -140,7 +140,7 @@ 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
+@subsection s4u_ex_io Simulating disks and files
 
 The examples of this section demonstrate how to interact with the
 simulated storages.
@@ -149,6 +149,12 @@ simulated storages.
     @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.
+
+  - <b>Remote I/O</b>. 
+    @ref examples/s4u/io-file-remote/s4u-io-file-remote.cpp \n
+    I/O operations on files can also be done in a remote fashion, 
+    i.e. when the accessed disk is not mounted on the caller's host.
+
 */
 
 /**
@@ -166,7 +172,8 @@ simulated storages.
 @example examples/s4u/app-token-ring/s4u-app-token-ring.cpp
 @example examples/s4u/app-masterworker/s4u-app-masterworker.cpp
 @example examples/s4u/app-pingpong/s4u-app-pingpong.cpp
-
+@example examples/s4u/io-file-remote/s4u-io-file-remote.cpp
+@example examples/s4u/io-raw-storage/s4u-io-raw-storage.cpp
 @example examples/s4u/mutex/s4u-mutex.cpp
 
 */
\ No newline at end of file
diff --git a/examples/s4u/io-file-remote/s4u-io-file-remote.cpp b/examples/s4u/io-file-remote/s4u-io-file-remote.cpp
new file mode 100644 (file)
index 0000000..46fbede
--- /dev/null
@@ -0,0 +1,75 @@
+/* Copyright (c) 2014-2016. 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 <src/plugins/file_system/FileSystem.hpp>
+#include <string>
+
+#define INMEGA (1024 * 1024)
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io, "Messages specific for this io example");
+
+static int host(int argc, char* argv[])
+{
+  simgrid::s4u::File* file = new simgrid::s4u::File(argv[1], nullptr);
+  const char* filename     = file->getPath();
+  XBT_INFO("Opened file '%s'", filename);
+  file->dump();
+
+  XBT_INFO("Try to read %llu from '%s'", file->size(), filename);
+  sg_size_t read = file->read(file->size());
+  XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu", read, filename, file->tell());
+  XBT_INFO("Seek back to the begining of the stream...");
+  file->seek(0, SEEK_SET);
+  XBT_INFO("Offset is now at: %llu", file->tell());
+
+  delete file;
+
+  if (argc > 5) {
+    file     = new simgrid::s4u::File(argv[2], nullptr);
+    filename = file->getPath();
+    XBT_INFO("Opened file '%s'", filename);
+    XBT_INFO("Try to write %llu MiB to '%s'", file->size() / 1024, filename);
+    sg_size_t write = file->write(file->size() * 1024);
+    XBT_INFO("Have written %llu bytes to '%s'.", write, filename);
+
+    if (std::stoi(argv[5]) != 0) {
+      XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file->size(),
+               simgrid::s4u::Host::current()->getCname(), argv[3]);
+      file->remoteMove(simgrid::s4u::Host::by_name(argv[3]), argv[4]);
+    } else {
+      XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file->size(),
+               simgrid::s4u::Host::current()->getCname(), argv[3]);
+      file->remoteCopy(simgrid::s4u::Host::by_name(argv[3]), argv[4]);
+      delete file;
+    }
+  }
+
+  return 0;
+}
+
+int main(int argc, char** argv)
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  sg_storage_file_system_init();
+  e.loadPlatform(argv[1]);
+  e.registerFunction("host", host);
+  e.loadDeployment(argv[2]);
+
+  for (auto const& s : *simgrid::s4u::allStorages()) {
+    XBT_INFO("Init: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s.second) / INMEGA,
+             sg_storage_get_size_free(s.second) / INMEGA, s.second->getCname());
+  }
+
+  e.run();
+
+  for (auto const& s : *simgrid::s4u::allStorages()) {
+    XBT_INFO("End: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s.second) / INMEGA,
+             sg_storage_get_size_free(s.second) / INMEGA, s.second->getCname());
+  }
+
+  XBT_INFO("Simulation time %g", simgrid::s4u::Engine::getClock());
+  return 0;
+}
diff --git a/examples/s4u/io-file-remote/s4u-io-file-remote.tesh b/examples/s4u/io-file-remote/s4u-io-file-remote.tesh
new file mode 100644 (file)
index 0000000..79c115d
--- /dev/null
@@ -0,0 +1,64 @@
+#! ./tesh
+
+$ ${bindir:=.}/s4u-io-file-remote$EXEEXT ${srcdir:=.}/storage/remote_io.xml ${srcdir:=.}/../s4u/io-file-remote/s4u-io-file-remote_d.xml "--log=root.fmt:[%10.6r]%e(%i@%5h)%e%m%n"
+> [  0.000000] (0@     ) Init: 12/476824 MiB used/free on 'Disk1'
+> [  0.000000] (0@     ) Init: 2280/474556 MiB used/free on 'Disk2'
+> [  0.000000] (1@alice) Opened file 'c:\Windows\setupact.log'
+> [  0.000000] (1@alice) File Descriptor information:
+>              Full path: 'c:\Windows\setupact.log'
+>              Size: 101663
+>              Mount point: 'c:'
+>              Storage Id: 'Disk2'
+>              Storage Type: 'SATA-II_HDD'
+>              File Descriptor Id: 0
+> [  0.000000] (1@alice) Try to read 101663 from 'c:\Windows\setupact.log'
+> [  0.000000] (2@  bob) Opened file '/scratch/lib/libsimgrid.so.3.6.2'
+> [  0.000000] (2@  bob) File Descriptor information:
+>              Full path: '/scratch/lib/libsimgrid.so.3.6.2'
+>              Size: 12710497
+>              Mount point: '/scratch'
+>              Storage Id: 'Disk1'
+>              Storage Type: 'SATA-II_HDD'
+>              File Descriptor Id: 0
+> [  0.000000] (2@  bob) Try to read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2'
+> [  0.000000] (3@ carl) Opened file '/scratch/lib/libsimgrid.so.3.6.2'
+> [  0.000000] (3@ carl) File Descriptor information:
+>              Full path: '/scratch/lib/libsimgrid.so.3.6.2'
+>              Size: 12710497
+>              Mount point: '/scratch'
+>              Storage Id: 'Disk1'
+>              Storage Type: 'SATA-II_HDD'
+>              File Descriptor Id: 0
+> [  0.000000] (3@ carl) Try to read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2'
+> [  0.000000] (4@ dave) Opened file 'c:\Windows\bootstat.dat'
+> [  0.000000] (4@ dave) File Descriptor information:
+>              Full path: 'c:\Windows\bootstat.dat'
+>              Size: 67584
+>              Mount point: 'c:'
+>              Storage Id: 'Disk2'
+>              Storage Type: 'SATA-II_HDD'
+>              File Descriptor Id: 0
+> [  0.000000] (4@ dave) Try to read 67584 from 'c:\Windows\bootstat.dat'
+> [  0.001469] (4@ dave) Have read 67584 from 'c:\Windows\bootstat.dat'. Offset is now at: 67584
+> [  0.001469] (4@ dave) Seek back to the begining of the stream...
+> [  0.001469] (4@ dave) Offset is now at: 0
+> [  0.001469] (4@ dave) Opened file 'c:\Windows\Professional.xml'
+> [  0.001469] (4@ dave) Try to write 31 MiB to 'c:\Windows\Professional.xml'
+> [  0.003741] (1@alice) Have read 101663 from 'c:\Windows\setupact.log'. Offset is now at: 101663
+> [  0.003741] (1@alice) Seek back to the begining of the stream...
+> [  0.003741] (1@alice) Offset is now at: 0
+> [  0.276315] (3@ carl) Have read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2'. Offset is now at: 12710497
+> [  0.276315] (3@ carl) Seek back to the begining of the stream...
+> [  0.276315] (3@ carl) Offset is now at: 0
+> [  0.387036] (2@  bob) Have read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2'. Offset is now at: 12710497
+> [  0.387036] (2@  bob) Seek back to the begining of the stream...
+> [  0.387036] (2@  bob) Offset is now at: 0
+> [  0.387036] (2@  bob) Opened file '/scratch/doc/simgrid/examples/platforms/g5k.xml'
+> [  0.387036] (2@  bob) Try to write 16 MiB to '/scratch/doc/simgrid/examples/platforms/g5k.xml'
+> [  0.528211] (4@ dave) Have written 32646144 bytes to 'c:\Windows\Professional.xml'.
+> [  0.528211] (4@ dave) Move 'c:\Windows\Professional.xml' (of size 32646144) from 'dave' to 'carl'
+> [  0.819921] (2@  bob) Have written 17436672 bytes to '/scratch/doc/simgrid/examples/platforms/g5k.xml'.
+> [  0.819921] (2@  bob) Copy '/scratch/doc/simgrid/examples/platforms/g5k.xml' (of size 17436672) from 'bob' to 'alice'
+> [  1.843969] (0@     ) End: 60/476776 MiB used/free on 'Disk1'
+> [  1.843969] (0@     ) End: 2297/474539 MiB used/free on 'Disk2'
+> [  1.843969] (0@     ) Simulation time 1.84397
diff --git a/examples/s4u/io-file-remote/s4u-io-file-remote_d.xml b/examples/s4u/io-file-remote/s4u-io-file-remote_d.xml
new file mode 100644 (file)
index 0000000..838ab3d
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
+<platform version="4.1">
+  <actor host="alice" function="host">
+    <argument value = "c:\Windows\setupact.log"/>
+  </actor>
+  <actor host="bob" function="host">
+    <argument value = "/scratch/lib/libsimgrid.so.3.6.2"/>
+    <argument value = "/scratch/doc/simgrid/examples/platforms/g5k.xml"/>
+    <argument value = "alice"/>
+    <argument value = "c:\Windows\Platforms\g5k.xml"/>
+    <argument value = "0"/>
+  </actor>
+  <actor host="carl" function="host">
+    <argument value = "/scratch/lib/libsimgrid.so.3.6.2"/>
+  </actor>
+  <actor host="dave" function="host">
+    <argument value = "c:\Windows\bootstat.dat"/>
+    <argument value = "c:\Windows\Professional.xml"/>
+    <argument value = "carl"/>
+    <argument value = "/scratch/mailbox/Professional.xml"/>
+    <argument value = "1"/>
+  </actor>
+</platform>