1 /* Copyright (c) 2008, 2009, 2010. 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 FILENAME "/home/user/Install/simgrid/doc/simgrid/examples/cxx/basic/basic_platform.xml"
23 #include "surf/surf_private.h"
25 int host(int argc, char *argv[]);
27 XBT_LOG_NEW_DEFAULT_CATEGORY(io_file,
28 "Messages specific for this io example");
30 int host(int argc, char *argv[])
33 char* mount = bprintf("C:");
35 file = MSG_file_open(mount,FILENAME,"rw");
36 XBT_INFO("Host '%s' open %p",MSG_host_get_name(MSG_host_self()), file);
38 size_t read = MSG_file_read(mount,NULL,0,0,file);
39 XBT_INFO("Host '%s' read %zu", MSG_host_get_name(MSG_host_self()), read);
41 size_t write = MSG_file_write(mount,NULL,0,0,file);
42 XBT_INFO("Host '%s' write %zu", MSG_host_get_name(MSG_host_self()), write);
44 int res = MSG_file_stat(mount,0,NULL);
45 XBT_INFO("Host '%s' stat %d",MSG_host_get_name(MSG_host_self()), res);
47 res = MSG_file_close(mount,file);
48 XBT_INFO("Host '%s' close %d",MSG_host_get_name(MSG_host_self()), res);
54 int main(int argc, char **argv)
57 MSG_global_init(&argc, argv);
58 MSG_create_environment(argv[1]);
59 xbt_dynar_t hosts = MSG_hosts_as_dynar();
60 MSG_function_register("host", host);
62 XBT_INFO("Number of host '%lu'",xbt_dynar_length(hosts));
63 for(i = 0 ; i<xbt_dynar_length(hosts); i++)
65 char* name_host = bprintf("%d",i);
66 MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,m_host_t) );
69 xbt_dynar_free(&hosts);
72 XBT_INFO("Simulation time %g", MSG_get_clock());