Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
missing file for distcheck
[simgrid.git] / examples / msg / io / remote.c
1 /* Copyright (c) 2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 /** @addtogroup MSG_examples
8  * 
9  * @subsection MSG_ex_resources Other resource kinds
10  * 
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.
14  * 
15  * - <b>io/remote.c</b> Example of delegated I/O operations
16  */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include "msg/msg.h"
21 #include "surf/surf_private.h"
22
23 int host(int argc, char *argv[]);
24
25 XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io,
26                              "Messages specific for this io example");
27
28
29 int host(int argc, char *argv[]){
30   msg_file_t file = NULL;
31   const char* filename;
32   sg_size_t read, write;
33
34   file = MSG_file_open(argv[1], NULL);
35   filename = MSG_file_get_name(file);
36   XBT_INFO("Opened file '%s'",filename);
37   MSG_file_dump(file);
38
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,
42       MSG_file_tell(file));
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));
46
47   MSG_file_close(file);
48
49   if (argc > 2){
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,
56         MSG_file_tell(file));
57
58     msg_host_t src, dest;
59     src= MSG_host_self();
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),
63            argv[3]);
64     MSG_file_rmove(file, dest, argv[4]);
65   }
66
67   return 0;
68 }
69
70
71
72 int main(int argc, char **argv)
73 {
74   int res;
75
76   MSG_init(&argc, argv);
77   MSG_create_environment(argv[1]);
78   MSG_function_register("host", host);
79   MSG_launch_application(argv[2]);
80
81   res = MSG_main();
82
83   XBT_INFO("Simulation time %g", MSG_get_clock());
84   if (res == MSG_OK)
85     return 0;
86   else
87     return 1;
88 }