Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
update all the platforms file with the new s/:/_/ in DTD
[simgrid.git] / examples / msg / migration / migration.c
1 /* Copyright (c) 2009, 2010. 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 "msg/msg.h"            /* core library */
8 #include "xbt/sysdep.h"         /* calloc */
9
10 /* Create a log channel to have nice outputs. */
11 #include "xbt/log.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
13                              "Messages specific for this msg example");
14
15 /** The guy we will move from host to host. It move alone and then is moved by policeman back  */
16 static int emigrant(int argc, char *argv[])
17 {
18   m_task_t task;
19   INFO0
20     ("I'll look for a new job on another machine where the grass is greener.");
21   MSG_process_change_host(MSG_get_host_by_name("Boivin"));
22   INFO0("Yeah, found something to do");
23   task = MSG_task_create("job", 98095000, 0, NULL);
24   MSG_task_execute(task);
25   MSG_task_destroy(task);
26   MSG_process_sleep (2);
27   INFO0("Moving back home after work");
28   MSG_process_change_host(MSG_get_host_by_name("Jacquelin"));
29   MSG_process_change_host(MSG_get_host_by_name("Boivin"));
30   MSG_process_sleep (4);
31   INFO0("Uh, nothing to do here. Stopping now");
32   return 0;
33 }                               /* end_of_emigrant */
34
35 /* This function would move the emigrant back home, if it were possible to do so in the MSG API.
36  * Nothing for now.
37  */
38 static int policeman(int argc, char *argv[])
39 {
40   INFO0("No function in the API to move the emigrant back, so do nothing.");
41   return 0;
42 }                               /* end_of_policeman */
43
44
45 /** Main function */
46 int main(int argc, char *argv[])
47 {
48   MSG_error_t res = MSG_OK;
49
50   /* Argument checking */
51   MSG_global_init(&argc, argv);
52   if (argc < 3) {
53     CRITICAL1("Usage: %s platform_file deployment_file\n", argv[0]);
54     CRITICAL1("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
55               argv[0]);
56     exit(1);
57   }
58
59   /* Simulation setting */
60   MSG_create_environment(argv[1]);
61
62   /* Application deployment */
63   MSG_function_register("emigrant", emigrant);
64   MSG_launch_application(argv[2]);
65
66   /* Run the simulation */
67   res = MSG_main();
68   INFO1("Simulation time %g", MSG_get_clock());
69   if (res == MSG_OK)
70     res = MSG_clean();
71
72   if (res == MSG_OK)
73     return 0;
74   else
75     return 1;
76 }                               /* end_of_main */