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 int host(int argc, char *argv[]);
25 XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io,
26 "Messages specific for this io example");
29 int host(int argc, char *argv[]){
30 msg_file_t file = NULL;
32 sg_size_t read, write;
34 file = MSG_file_open(argv[1], NULL);
35 filename = MSG_file_get_name(file);
36 XBT_INFO("Opened file '%s'",filename);
39 XBT_INFO("Try to read %llu from '%s'",MSG_file_get_size(file),filename);
40 read = MSG_file_read(file, MSG_file_get_size(file));
41 XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu",read,filename,
43 XBT_INFO("Seek back to the begining of the stream...");
44 MSG_file_seek(file, 0, SEEK_SET);
45 XBT_INFO("Offset is now at: %llu", MSG_file_tell(file));
50 file = MSG_file_open(argv[2], NULL);
51 filename = MSG_file_get_name(file);
52 XBT_INFO("Opened file '%s'",filename);
53 XBT_INFO("Try to write 100KiB to '%s'",filename);
54 write = MSG_file_write(file, 100*1024);
55 XBT_INFO("Have written %llu bytes to '%s'. Offset is now at: %llu",write,filename,
60 dest = MSG_get_host_by_name(argv[3]);
61 XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename,
62 MSG_file_get_size(file), MSG_host_get_name(src),
64 MSG_file_rmove(file, dest, argv[4]);
72 int main(int argc, char **argv)
76 MSG_init(&argc, argv);
77 MSG_create_environment(argv[1]);
78 MSG_function_register("host", host);
79 MSG_launch_application(argv[2]);
83 XBT_INFO("Simulation time %g", MSG_get_clock());