Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
pluginify storage contents
[simgrid.git] / teshsuite / s4u / concurrent_rw / concurrent_rw.cpp
1 /* Copyright (c) 2008-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/s4u.hpp"
7 #include <unistd.h>
8
9 #define FILENAME1 "/home/doc/simgrid/examples/platforms/g5k.xml"
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u test");
12
13 static void host()
14 {
15   char name[2048];
16   int id = simgrid::s4u::this_actor::getPid();
17   snprintf(name, 2048, "%s%i", FILENAME1, id);
18   simgrid::s4u::File* file = new simgrid::s4u::File(name, NULL);
19   XBT_INFO("process %d is writing!", id);
20   file->write(3000000);
21   XBT_INFO("process %d goes to sleep for %d seconds", id, id);
22   simgrid::s4u::this_actor::sleep_for(id);
23   XBT_INFO("process %d is writing again!", id);
24   file->write(3000000);
25   XBT_INFO("process %d goes to sleep for %d seconds", id, 6 - id);
26   simgrid::s4u::this_actor::sleep_for(6 - id);
27   XBT_INFO("process %d is reading!", id);
28   file->seek(0);
29   file->read(3000000);
30   XBT_INFO("process %d goes to sleep for %d seconds", id, id);
31   simgrid::s4u::this_actor::sleep_for(id);
32   XBT_INFO("process %d is reading again!", id);
33   file->seek(0);
34   file->read(3000000);
35
36   XBT_INFO("process %d => Size of %s: %llu", id, name, file->size());
37   // Close the file
38   delete file;
39 }
40
41 int main(int argc, char** argv)
42 {
43   simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
44   sg_storage_file_system_init();
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   delete e;
54   return 0;
55 }