Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merging changes done by Steven, Samuel and Luka, regarding simulation of StarPU-MPI
[simgrid.git] / examples / msg / io / file_unlink.c
1 /* Copyright (c) 2008-2010, 2012-2015. 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  * - <b>io/file_unlink.c</b> TBA
10  */
11
12 #define FILENAME1 "/home/doc/simgrid/examples/platforms/g5k.xml"
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include "simgrid/msg.h"
17
18 int host(int argc, char *argv[]);
19
20 XBT_LOG_NEW_DEFAULT_CATEGORY(io_file,
21                              "Messages specific for this io example");
22
23 int host(int argc, char *argv[])
24 {
25   msg_file_t file = NULL;
26   sg_size_t write;
27
28   // First open
29   XBT_INFO("\tOpen file '%s'",FILENAME1);
30   file = MSG_file_open(FILENAME1, NULL);
31
32   // Unlink the file
33   XBT_INFO("\tUnlink file '%s'",MSG_file_get_name(file));
34   MSG_file_unlink(file);
35
36   // Re Open the file wich is in fact created
37   XBT_INFO("\tOpen file '%s'",FILENAME1);
38   file = MSG_file_open(FILENAME1, NULL);
39
40   // Write into the new file
41   write = MSG_file_write(file,100000);  // Write for 100Ko
42   XBT_INFO("\tHave written %llu on %s",write,MSG_file_get_name(file));
43
44   // Write into the new file
45   write = MSG_file_write(file,100000);  // Write for 100Ko
46   XBT_INFO("\tHave written %llu on %s",write,MSG_file_get_name(file));
47
48   // Close the file
49   XBT_INFO("\tClose file '%s'",MSG_file_get_name(file));
50   MSG_file_close(file);
51
52   return 0;
53 }
54
55 int main(int argc, char **argv)
56 {
57   int res;
58   MSG_init(&argc, argv);
59   MSG_create_environment(argv[1]);
60   xbt_dynar_t hosts =  MSG_hosts_as_dynar();
61   MSG_function_register("host", host);
62   unsigned long nb_hosts = xbt_dynar_length(hosts);
63   XBT_INFO("Number of host '%lu'",nb_hosts);
64   char* name_host = xbt_strdup("0");
65   MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,0,msg_host_t) );
66   free(name_host);
67
68   xbt_dynar_free(&hosts);
69
70   res = MSG_main();
71   XBT_INFO("Simulation time %g", MSG_get_clock());
72   if (res == MSG_OK)
73     return 0;
74   else
75     return 1;
76
77 }