Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add MSG functions for file.
[simgrid.git] / examples / msg / io / file.c
1 /* Copyright (c) 2008, 2009, 2010. 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 #include <stdio.h>
8 #include <stdlib.h>
9 #include "simix/simix.h"
10 #include "msg/msg.h"
11 #include "surf/surf_private.h"
12
13 int host(int argc, char *argv[]);
14
15 XBT_LOG_NEW_DEFAULT_CATEGORY(file,
16                              "Messages specific for this simix example");
17
18 int host(int argc, char *argv[])
19 {
20   size_t read = simcall_file_read(NULL,0,0,NULL);
21   XBT_INFO("Host '%s' read %ld",MSG_host_get_name(MSG_host_self()),read);
22   size_t write = simcall_file_write(NULL,0,0,NULL);
23   XBT_INFO("Host '%s' write %ld",MSG_host_get_name(MSG_host_self()), write);
24   return 0;
25 }
26
27 int main(int argc, char **argv)
28 {
29     int i,res;
30   MSG_global_init(&argc, argv);
31   MSG_create_environment(argv[1]);
32   m_host_t *host_table =  MSG_get_host_table();
33   int number_of_hosts = MSG_get_host_number();
34   MSG_function_register("host", host);
35
36   XBT_INFO("Number of host '%d'",number_of_hosts);
37   for(i = 0 ; i<number_of_hosts; i++)
38   {
39     char* name_host = bprintf("%d",i);
40     MSG_process_create( name_host, host, NULL, host_table[i] );
41     free(name_host);
42   }
43   xbt_free(host_table);
44
45   res = MSG_main();
46   XBT_INFO("Simulation time %g", MSG_get_clock());
47   MSG_clean();
48   if (res == MSG_OK)
49     return 0;
50   else
51     return 1;
52
53 }