Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the communication optimization.
[simgrid.git] / teshsuite / s4u / concurrent_rw / concurrent_rw.cpp
1 /* Copyright (c) 2008-2010, 2012-2015, 2017. 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/s4u.hpp"
8 #include <unistd.h>
9
10 #define FILENAME1 "/home/doc/simgrid/examples/platforms/g5k.xml"
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u test");
13
14 static void host()
15 {
16   char name[2048];
17   int id = simgrid::s4u::this_actor::pid();
18   snprintf(name, 2048, "%s%i", FILENAME1, id);
19   simgrid::s4u::File* file = new simgrid::s4u::File(name, NULL);
20   XBT_INFO("process %d is writing!", id);
21   file->write(3000000);
22   XBT_INFO("process %d goes to sleep for %d seconds", id, id);
23   simgrid::s4u::this_actor::sleep_for(id);
24   XBT_INFO("process %d is writing again!", id);
25   file->write(3000000);
26   XBT_INFO("process %d goes to sleep for %d seconds", id, 6 - id);
27   simgrid::s4u::this_actor::sleep_for(6 - id);
28   XBT_INFO("process %d is reading!", id);
29   file->seek(0);
30   file->read(3000000);
31   XBT_INFO("process %d goes to sleep for %d seconds", id, id);
32   simgrid::s4u::this_actor::sleep_for(id);
33   XBT_INFO("process %d is reading again!", id);
34   file->seek(0);
35   file->read(3000000);
36
37   XBT_INFO("process %d => Size of %s: %llu", id, name, file->size());
38   // Close the file
39   delete file;
40 }
41
42 int main(int argc, char** argv)
43 {
44   simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
45   e->loadPlatform(argv[1]);
46
47   for (int i = 0; i < 5; i++)
48     simgrid::s4u::Actor::createActor("host", simgrid::s4u::Host::by_name("bob"), host);
49
50   e->run();
51   XBT_INFO("Simulation time %g", e->getClock());
52
53   return 0;
54 }