1 /* Copyright (c) 2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 /** @addtogroup MSG_examples
9 * @subsection MSG_ex_resources Other resource kinds
11 * This section contains some sparse examples of how to use the other
12 * kind of resources, such as disk or GPU. These resources are quite
13 * experimental for now, but here we go anyway.
15 * - <b>io/remote.c</b> Example of delegated I/O operations
21 #include "surf/surf_private.h"
23 #define INMEGA (1024*1024)
25 int host(int argc, char *argv[]);
27 XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io,
28 "Messages specific for this io example");
31 int host(int argc, char *argv[]){
32 msg_file_t file = NULL;
34 sg_size_t read, write;
36 file = MSG_file_open(argv[1], NULL);
37 filename = MSG_file_get_name(file);
38 XBT_INFO("Opened file '%s'",filename);
41 XBT_INFO("Try to read %llu from '%s'",MSG_file_get_size(file),filename);
42 read = MSG_file_read(file, MSG_file_get_size(file));
43 XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu",read,filename,
45 XBT_INFO("Seek back to the begining of the stream...");
46 MSG_file_seek(file, 0, SEEK_SET);
47 XBT_INFO("Offset is now at: %llu", MSG_file_tell(file));
52 file = MSG_file_open(argv[2], NULL);
53 filename = MSG_file_get_name(file);
54 XBT_INFO("Opened file '%s'",filename);
55 XBT_INFO("Try to write %llu MiB to '%s'",
56 MSG_file_get_size(file)/1024,
58 write = MSG_file_write(file, MSG_file_get_size(file)*1024);
59 XBT_INFO("Have written %llu bytes to '%s'.",write,filename);
63 dest = MSG_get_host_by_name(argv[3]);
65 XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename,
66 MSG_file_get_size(file), MSG_host_get_name(src),
68 MSG_file_rmove(file, dest, argv[4]);
70 XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename,
71 MSG_file_get_size(file), MSG_host_get_name(src),
73 MSG_file_rcopy(file, dest, argv[4]);
83 int main(int argc, char **argv)
90 MSG_init(&argc, argv);
91 MSG_create_environment(argv[1]);
92 MSG_function_register("host", host);
93 MSG_launch_application(argv[2]);
95 storages = MSG_storages_as_dynar();
96 xbt_dynar_foreach(storages, cur, st){
97 XBT_INFO("Init: %llu MiB used on '%s'",
98 MSG_storage_get_used_size(st)/INMEGA,
99 MSG_storage_get_name(st));
104 xbt_dynar_foreach(storages, cur, st){
105 XBT_INFO("Init: %llu MiB used on '%s'",
106 MSG_storage_get_used_size(st)/INMEGA,
107 MSG_storage_get_name(st));
109 xbt_dynar_free_container(&storages);
111 XBT_INFO("Simulation time %g", MSG_get_clock());