Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Indent the rest of the code (examples, buildtools, doc...) except for examples/SMPI...
[simgrid.git] / examples / msg / tracing / procmig.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2009 The SimGrid team. All rights reserved.                */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "msg/msg.h"            /* core library */
9 #include "xbt/sysdep.h"         /* calloc */
10
11 /* Create a log channel to have nice outputs. */
12 #include "xbt/log.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
14                              "Messages specific for this msg example");
15
16 /** The guy we will move from host to host. It move alone and then is moved by policeman back  */
17 static int emigrant(int argc, char *argv[])
18 {
19   INFO0("Setting process category");
20   TRACE_msg_set_process_category(MSG_process_self(), "emigrant");
21   MSG_process_sleep(2);
22   INFO0("Migrating to Tremblay");
23   MSG_process_change_host(MSG_get_host_by_name("Tremblay"));
24   MSG_process_sleep(2);
25   INFO0("Migrating to Jupiter");
26   MSG_process_change_host(MSG_get_host_by_name("Jupiter"));
27   MSG_process_sleep(2);
28   INFO0("Migrating to Fafard");
29   MSG_process_change_host(MSG_get_host_by_name("Fafard"));
30   MSG_process_sleep(2);
31   INFO0("Migrating to Ginette");
32   MSG_process_change_host(MSG_get_host_by_name("Ginette"));
33   MSG_process_sleep(2);
34   INFO0("Migrating to Bourassa");
35   MSG_process_change_host(MSG_get_host_by_name("Bourassa"));
36   MSG_process_sleep(2);
37   return 0;
38 }
39
40 /** Main function */
41 int main(int argc, char *argv[])
42 {
43   MSG_error_t res = MSG_OK;
44
45   /* Argument checking */
46   MSG_global_init(&argc, argv);
47   if (argc < 3) {
48     CRITICAL1("Usage: %s platform_file deployment_file\n", argv[0]);
49     CRITICAL1("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
50               argv[0]);
51     exit(1);
52   }
53   //starting the simulation trace
54   TRACE_start();
55   TRACE_category("emigrant");
56
57   /* Simulation setting */
58   MSG_create_environment(argv[1]);
59
60   /* Application deployment */
61   MSG_function_register("emigrant", emigrant);
62   MSG_launch_application(argv[2]);
63
64   /* Run the simulation */
65   res = MSG_main();
66   INFO1("Simulation time %g", MSG_get_clock());
67   if (res == MSG_OK)
68     res = MSG_clean();
69
70   //ending the simulation trace
71   TRACE_end();
72
73   if (res == MSG_OK)
74     return 0;
75   else
76     return 1;
77 }                               /* end_of_main */