1 /* Copyright (c) 2008-2010, 2012-2013. 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/file.c</b> Example with the disk resource
18 #define FILENAME1 "./doc/simgrid/examples/platforms/g5k.xml"
19 #define FILENAME2 ".\\Windows\\setupact.log"
20 #define FILENAME3 "./doc/simgrid/examples/platforms/g5k_cabinets.xml"
21 #define FILENAME4 "./doc/simgrid/examples/platforms/nancy.xml"
26 #include "surf/surf_private.h"
29 int host(int argc, char *argv[]);
31 XBT_LOG_NEW_DEFAULT_CATEGORY(io_file,
32 "Messages specific for this io example");
34 int host(int argc, char *argv[])
36 msg_file_t file = NULL;
37 char* mount = xbt_strdup("/home");
38 sg_storage_size_t read,write;
40 if(!strcmp(MSG_process_get_name(MSG_process_self()),"0")){
41 file = MSG_file_open(mount,FILENAME1, NULL);
43 } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"1")) {
45 mount = xbt_strdup("/windows");
46 file = MSG_file_open(mount,FILENAME2, NULL);
47 } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"2")){
48 file = MSG_file_open(mount,FILENAME3, NULL);
49 } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"3"))
50 file = MSG_file_open(mount,FILENAME4, NULL);
51 else xbt_die("FILENAME NOT DEFINED %s",MSG_process_get_name(MSG_process_self()));
53 XBT_INFO("\tOpen file '%s'",file->fullname);
55 read = MSG_file_read(file, 10000000); // Read for 10MB
56 XBT_INFO("\tHave read %" PRIu64 " on %s",read,file->fullname);
58 write = MSG_file_write(file, 100000); // Write for 100KB
59 XBT_INFO("\tHave written %" PRIu64 " on %s",write,file->fullname);
61 read = MSG_file_read(file, 110000); // Read for 110KB
62 XBT_INFO("\tHave read %" PRIu64 " on %s (of size %" PRIu64 ")",read,file->fullname,
63 MSG_file_get_size(file));
65 XBT_INFO("\tClose file '%s'",file->fullname);
72 int main(int argc, char **argv)
75 MSG_init(&argc, argv);
76 MSG_create_environment(argv[1]);
77 xbt_dynar_t hosts = MSG_hosts_as_dynar();
78 MSG_function_register("host", host);
79 unsigned long nb_hosts = xbt_dynar_length(hosts);
80 XBT_INFO("Number of host '%lu'",nb_hosts);
81 for(i = 0 ; i<nb_hosts; i++)
83 char* name_host = bprintf("%d",i);
84 MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,msg_host_t) );
87 xbt_dynar_free(&hosts);
90 XBT_INFO("Simulation time %g", MSG_get_clock());