1 /* Copyright (c) 2008-2010, 2012-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/file.c</b> Example with the disk resource
18 #define FILENAME1 "/home/doc/simgrid/examples/platforms/g5k.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[])
32 msg_file_t file = NULL;
36 XBT_INFO("\tOpen file '%s'",FILENAME1);
37 file = MSG_file_open(FILENAME1, NULL);
40 XBT_INFO("\tUnlink file '%s'",MSG_file_get_name(file));
41 MSG_file_unlink(file);
43 // Re Open the file wich is in fact created
44 XBT_INFO("\tOpen file '%s'",FILENAME1);
45 file = MSG_file_open(FILENAME1, NULL);
47 // Write into the new file
48 write = MSG_file_write(file,100000); // Write for 100Ko
49 XBT_INFO("\tHave written %llu on %s",write,MSG_file_get_name(file));
52 XBT_INFO("\tClose file '%s'",MSG_file_get_name(file));
58 int main(int argc, char **argv)
61 MSG_init(&argc, argv);
62 MSG_create_environment(argv[1]);
63 xbt_dynar_t hosts = MSG_hosts_as_dynar();
64 MSG_function_register("host", host);
65 unsigned long nb_hosts = xbt_dynar_length(hosts);
66 XBT_INFO("Number of host '%lu'",nb_hosts);
67 char* name_host = xbt_strdup("0");
68 MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,0,msg_host_t) );
71 xbt_dynar_free(&hosts);
74 XBT_INFO("Simulation time %g", MSG_get_clock());