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;
33 sg_size_t read;//,write;
35 file = MSG_file_open(argv[1], NULL);
36 filename = MSG_file_get_name(file);
37 XBT_INFO("Opened file '%s'",filename);
40 // st = MSG_storage_get_by_name(st_name);
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);
50 //int host(int argc, char *argv[])
52 // msg_file_t file = NULL;
53 // sg_size_t read,write;
55 // const char* st_name;
57 // if(!strcmp(MSG_process_get_name(MSG_process_self()),"0")){
58 // file = MSG_file_open(FILENAME1, NULL);
59 // MSG_file_dump(file);
61 // } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"1")) {
62 // file = MSG_file_open(FILENAME2, NULL);
64 // } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"2")){
65 // file = MSG_file_open(FILENAME3, NULL);
67 // } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"3")){
68 // file = MSG_file_open(FILENAME4, NULL);
71 // else xbt_die("FILENAME NOT DEFINED %s",MSG_process_get_name(MSG_process_self()));
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);
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));
80 // /* Try to read for 10MB */
81 // read = MSG_file_read(file, 10000000);
82 // XBT_INFO("\tHave read %llu from '%s'",read,filename);
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));
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));
93 // /* rewind to the beginning of the file */
94 // XBT_INFO("\tComing back to the beginning of the stream for file '%s'",
96 // MSG_file_seek(file, 0, SEEK_SET);
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));
103 // /* rewind once again to the beginning of the file */
104 // XBT_INFO("\tComing back to the beginning of the stream for file '%s'",
106 // MSG_file_seek(file, 0, SEEK_SET);
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));
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));
116 // XBT_INFO("\tClose file '%s'",filename);
117 // MSG_file_close(file);
123 int main(int argc, char **argv)
127 MSG_init(&argc, argv);
128 MSG_create_environment(argv[1]);
129 MSG_function_register("host", host);
130 MSG_launch_application(argv[2]);
134 XBT_INFO("Simulation time %g", MSG_get_clock());