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
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)
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,
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})
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()
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.
*/
/**
--- /dev/null
+/* 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;
+}
--- /dev/null
+#! ./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
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)
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()
#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 */
/* - 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 */
return 1;
}
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
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);
#! ./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