Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix linking of storage example on Windows.
[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 //  msg_storage_t st;
33   sg_size_t read;//,write;
34
35   file = MSG_file_open(argv[1], NULL);
36   filename = MSG_file_get_name(file);
37   XBT_INFO("Opened file '%s'",filename);
38   MSG_file_dump(file);
39
40  // st = MSG_storage_get_by_name(st_name);
41
42   XBT_INFO("Try to read %llu from '%s'",MSG_file_get_size(file),filename);
43   read = MSG_file_read(file, MSG_file_get_size(file));
44   XBT_INFO("Have read %llu from '%s'",read,filename);
45
46   MSG_file_close(file);
47   return 0;
48 }
49
50 //int host(int argc, char *argv[])
51 //{
52 //  msg_file_t file = NULL;
53 //  sg_size_t read,write;
54 //  msg_storage_t st;
55 //  const char* st_name;
56 //
57 //  if(!strcmp(MSG_process_get_name(MSG_process_self()),"0")){
58 //    file = MSG_file_open(FILENAME1, NULL);
59 //    MSG_file_dump(file);
60 //    st_name = "Disk4";
61 //  } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"1")) {
62 //    file = MSG_file_open(FILENAME2, NULL);
63 //    st_name = "Disk2";
64 //  } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"2")){
65 //    file = MSG_file_open(FILENAME3, NULL);
66 //    st_name = "Disk3";
67 //  } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"3")){
68 //    file = MSG_file_open(FILENAME4, NULL);
69 //    st_name = "Disk1";
70 //  }
71 //  else xbt_die("FILENAME NOT DEFINED %s",MSG_process_get_name(MSG_process_self()));
72 //
73 //  const char* filename = MSG_file_get_name(file);
74 //  XBT_INFO("\tOpen file '%s'",filename);
75 //  st = MSG_storage_get_by_name(st_name);
76 //
77 //  XBT_INFO("\tCapacity of the storage element '%s' is stored on: %llu / %llu",
78 //            filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st));
79 //
80 //  /* Try to read for 10MB */
81 //  read = MSG_file_read(file, 10000000);
82 //  XBT_INFO("\tHave read %llu from '%s'",read,filename);
83 //
84 //  /* Write 100KB in file from the current position, i.e, end of file or 10MB */
85 //  write = MSG_file_write(file, 100000);
86 //  XBT_INFO("\tHave written %llu in '%s'. Size now is: %llu",write,filename,
87 //           MSG_file_get_size(file));
88 //
89 //
90 //  XBT_INFO("\tCapacity of the storage element '%s' is stored on: %llu / %llu",
91 //            filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st));
92 //
93 //  /* rewind to the beginning of the file */
94 //  XBT_INFO("\tComing back to the beginning of the stream for file '%s'",
95 //           filename);
96 //  MSG_file_seek(file, 0, SEEK_SET);
97 //
98 //  /* Try to read 110KB */
99 //  read = MSG_file_read(file, 110000);
100 //  XBT_INFO("\tHave read %llu from '%s' (of size %llu)",read,filename,
101 //      MSG_file_get_size(file));
102 //
103 //  /* rewind once again to the beginning of the file */
104 //  XBT_INFO("\tComing back to the beginning of the stream for file '%s'",
105 //           filename);
106 //  MSG_file_seek(file, 0, SEEK_SET);
107 //
108 //  /* Write 110KB in file from the current position, i.e, end of file or 10MB */
109 //  write = MSG_file_write(file, 110000);
110 //  XBT_INFO("\tHave written %llu in '%s'. Size now is: %llu", write,filename,
111 //      MSG_file_get_size(file));
112 //
113 //  XBT_INFO("\tCapacity of the storage element '%s' is stored on: %llu / %llu",
114 //            filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st));
115 //
116 //  XBT_INFO("\tClose file '%s'",filename);
117 //  MSG_file_close(file);
118 //
119 //
120 //  return 0;
121 //}
122
123 int main(int argc, char **argv)
124 {
125   int res;
126
127   MSG_init(&argc, argv);
128   MSG_create_environment(argv[1]);
129   MSG_function_register("host", host);
130   MSG_launch_application(argv[2]);
131
132   res = MSG_main();
133
134   XBT_INFO("Simulation time %g", MSG_get_clock());
135   if (res == MSG_OK)
136     return 0;
137   else
138     return 1;
139 }