Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2024745368cc6e30b52ee886275fc55bc501e8ce
[simgrid.git] / teshsuite / msg / storage / concurrent_rw.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 #include "simgrid/msg.h"
8 #include <unistd.h>
9
10 #define FILENAME1 "/home/doc/simgrid/examples/platforms/g5k.xml"
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
13
14 static int host(int argc, char *argv[])
15 {
16   char name[2048];
17   int id = MSG_process_self_PID();
18   sprintf(name,"%s%i", FILENAME1, id);
19   msg_file_t file = MSG_file_open(name, NULL);
20   XBT_INFO("process %d is writing!", id);
21   MSG_file_write(file, 3000000);
22   XBT_INFO("process %d goes to sleep for %d seconds", id, id);
23   MSG_process_sleep(id);
24   XBT_INFO("process %d is writing again!", id);
25   MSG_file_write(file, 3000000);
26   XBT_INFO("process %d goes to sleep for %d seconds", id, 6 - id);
27   MSG_process_sleep(6-id);
28   XBT_INFO("process %d is reading!", id);
29   MSG_file_seek(file, 0, SEEK_SET);
30   MSG_file_read(file, 3000000);
31   XBT_INFO("process %d goes to sleep for %d seconds", id, id);
32   MSG_process_sleep(id);
33   XBT_INFO("process %d is reading again!", id);
34   MSG_file_seek(file, 0, SEEK_SET);
35   MSG_file_read(file, 3000000);
36
37   XBT_INFO("process %d => Size of %s: %llu", id, MSG_file_get_name(file), MSG_file_get_size(file));
38   MSG_file_close(file);
39
40   return 0;
41 }
42
43 int main(int argc, char **argv)
44 {
45   MSG_init(&argc, argv);
46   MSG_create_environment(argv[1]);
47
48   MSG_function_register("host", host);
49   for(int i = 0 ; i < 5; i++){
50     MSG_process_create("bob", host, NULL, MSG_host_by_name(xbt_strdup("bob")));
51   }
52
53   int res = MSG_main();
54   XBT_INFO("Simulation time %g", MSG_get_clock());
55
56   return res != MSG_OK;
57 }