Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sed -i -e 's/\t/ /g' [sources] Please people, stop using tabs
[simgrid.git] / examples / s4u / basic / s4u_basic.cpp
1 /* Copyright (c) 2006-2015. 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 <xbt/sysdep.h>
7
8 #include "simgrid/s4u.h"
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
11
12 class Worker : simgrid::s4u::Actor {
13 public:
14   Worker(const char*procname, simgrid::s4u::Host *host,int argc, char **argv)
15       : simgrid::s4u::Actor(procname,host,argc,argv){}
16
17   int main(int argc, char **argv) {
18     XBT_INFO("Hello s4u, I'm ready to serve");
19
20     char *msg = (char*)recv(*simgrid::s4u::Mailbox::byName("worker"));
21     XBT_INFO("I received '%s'",msg);
22     XBT_INFO("I'm done. See you.");
23     return 1;
24   }
25 };
26
27 class Master : simgrid::s4u::Actor {
28 public:
29   Master(const char*procname, simgrid::s4u::Host *host,int argc, char **argv)
30       : Actor(procname,host,argc,argv){}
31
32   int main(int argc, char **argv) {
33     const char *msg = "GaBuZoMeu";
34     XBT_INFO("Hello s4u, I have something to send");
35     send(*simgrid::s4u::Mailbox::byName("worker"), xbt_strdup(msg), strlen(msg));
36
37     XBT_INFO("I'm done. See you.");
38     return 1;
39   }
40 };
41
42
43 int main(int argc, char **argv) {
44   simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv);
45   e->loadPlatform("../../platforms/two_hosts_platform.xml");
46
47   new Worker("worker", simgrid::s4u::Host::by_name("host0"), 0, NULL);
48   new Master("master", simgrid::s4u::Host::by_name("host1"), 0, NULL);
49   e->run();
50   return 0;
51 }