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 * - <b>io/remote.c</b> Example of delegated I/O operations
14 #include "simgrid/msg.h"
15 #include "surf/surf_private.h"
17 #define INMEGA (1024*1024)
19 int host(int argc, char *argv[]);
21 XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io,
22 "Messages specific for this io example");
25 int host(int argc, char *argv[]){
26 msg_file_t file = NULL;
28 sg_size_t read, write;
30 file = MSG_file_open(argv[1], NULL);
31 filename = MSG_file_get_name(file);
32 XBT_INFO("Opened file '%s'",filename);
35 XBT_INFO("Try to read %llu from '%s'",MSG_file_get_size(file),filename);
36 read = MSG_file_read(file, MSG_file_get_size(file));
37 XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu",read,filename,
39 XBT_INFO("Seek back to the begining of the stream...");
40 MSG_file_seek(file, 0, SEEK_SET);
41 XBT_INFO("Offset is now at: %llu", MSG_file_tell(file));
46 file = MSG_file_open(argv[2], NULL);
47 filename = MSG_file_get_name(file);
48 XBT_INFO("Opened file '%s'",filename);
49 XBT_INFO("Try to write %llu MiB to '%s'",
50 MSG_file_get_size(file)/1024,
52 write = MSG_file_write(file, MSG_file_get_size(file)*1024);
53 XBT_INFO("Have written %llu bytes to '%s'.",write,filename);
57 dest = MSG_host_by_name(argv[3]);
59 XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename,
60 MSG_file_get_size(file), MSG_host_get_name(src),
62 MSG_file_rmove(file, dest, argv[4]);
64 XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename,
65 MSG_file_get_size(file), MSG_host_get_name(src),
67 MSG_file_rcopy(file, dest, argv[4]);
77 int main(int argc, char **argv)
84 MSG_init(&argc, argv);
85 MSG_create_environment(argv[1]);
86 MSG_function_register("host", host);
87 MSG_launch_application(argv[2]);
89 storages = MSG_storages_as_dynar();
90 xbt_dynar_foreach(storages, cur, st){
91 XBT_INFO("Init: %llu MiB used on '%s'",
92 MSG_storage_get_used_size(st)/INMEGA,
93 MSG_storage_get_name(st));
98 xbt_dynar_foreach(storages, cur, st){
99 XBT_INFO("Init: %llu MiB used on '%s'",
100 MSG_storage_get_used_size(st)/INMEGA,
101 MSG_storage_get_name(st));
103 xbt_dynar_free_container(&storages);
105 XBT_INFO("Simulation time %g", MSG_get_clock());