1 /* Copyright (c) 2014-2015. 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 * - <b>io/remote.c</b> Example of delegated I/O operations
14 #include "simgrid/msg.h"
16 #define INMEGA (1024*1024)
18 int host(int argc, char *argv[]);
20 XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io,
21 "Messages specific for this io example");
24 int host(int argc, char *argv[]){
25 msg_file_t file = NULL;
27 sg_size_t read, write;
29 file = MSG_file_open(argv[1], NULL);
30 filename = MSG_file_get_name(file);
31 XBT_INFO("Opened file '%s'",filename);
34 XBT_INFO("Try to read %llu from '%s'",MSG_file_get_size(file),filename);
35 read = MSG_file_read(file, MSG_file_get_size(file));
36 XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu",read,filename,
38 XBT_INFO("Seek back to the begining of the stream...");
39 MSG_file_seek(file, 0, SEEK_SET);
40 XBT_INFO("Offset is now at: %llu", MSG_file_tell(file));
45 file = MSG_file_open(argv[2], NULL);
46 filename = MSG_file_get_name(file);
47 XBT_INFO("Opened file '%s'",filename);
48 XBT_INFO("Try to write %llu MiB to '%s'",
49 MSG_file_get_size(file)/1024,
51 write = MSG_file_write(file, MSG_file_get_size(file)*1024);
52 XBT_INFO("Have written %llu bytes to '%s'.",write,filename);
56 dest = MSG_host_by_name(argv[3]);
58 XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename,
59 MSG_file_get_size(file), MSG_host_get_name(src),
61 MSG_file_rmove(file, dest, argv[4]);
63 XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename,
64 MSG_file_get_size(file), MSG_host_get_name(src),
66 MSG_file_rcopy(file, dest, argv[4]);
76 int main(int argc, char **argv)
83 MSG_init(&argc, argv);
84 MSG_create_environment(argv[1]);
85 MSG_function_register("host", host);
86 MSG_launch_application(argv[2]);
88 storages = MSG_storages_as_dynar();
89 xbt_dynar_foreach(storages, cur, st){
90 XBT_INFO("Init: %llu MiB used on '%s'",
91 MSG_storage_get_used_size(st)/INMEGA,
92 MSG_storage_get_name(st));
97 xbt_dynar_foreach(storages, cur, st){
98 XBT_INFO("Init: %llu MiB used on '%s'",
99 MSG_storage_get_used_size(st)/INMEGA,
100 MSG_storage_get_name(st));
102 xbt_dynar_free_container(&storages);
104 XBT_INFO("Simulation time %g", MSG_get_clock());