Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix: forgot to properly update migration.tesh
[simgrid.git] / examples / msg / migration / migration.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   TRACE_msg_set_process_category (MSG_process_self(), "emigrant");
20   m_task_t task;
21   INFO0
22     ("I'll look for a new job on another machine where the grass is greener.");
23   MSG_process_change_host(MSG_get_host_by_name("Boivin"));
24   INFO0("Yeah, found something to do");
25   task = MSG_task_create("job", 98095000, 0, NULL);
26   MSG_task_execute(task);
27   MSG_task_destroy(task);
28   MSG_process_sleep (2);
29   INFO0("Moving back home after work");
30   MSG_process_change_host(MSG_get_host_by_name("Jacquelin"));
31   MSG_process_change_host(MSG_get_host_by_name("Boivin"));
32   MSG_process_sleep (4);
33   INFO0("Uh, nothing to do here. Stopping now");
34   return 0;
35 }                               /* end_of_emigrant */
36
37 /* This function would move the emigrant back home, if it were possible to do so in the MSG API.
38  * Nothing for now.
39  */
40 static int policeman(int argc, char *argv[])
41 {
42   INFO0("No function in the API to move the emigrant back, so do nothing.");
43   return 0;
44 }                               /* end_of_policeman */
45
46
47 /** Main function */
48 int main(int argc, char *argv[])
49 {
50   MSG_error_t res = MSG_OK;
51
52   TRACE_start_with_mask ("zmsg_test.trace", TRACE_PLATFORM|TRACE_PROCESS);
53   TRACE_category ("emigrant");
54
55   /* Argument checking */
56   MSG_global_init(&argc, argv);
57   if (argc < 3) {
58     CRITICAL1("Usage: %s platform_file deployment_file\n", argv[0]);
59     CRITICAL1("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
60               argv[0]);
61     exit(1);
62   }
63
64   /* Simulation setting */
65   MSG_create_environment(argv[1]);
66
67   /* Application deployment */
68   MSG_function_register("emigrant", emigrant);
69   MSG_launch_application(argv[2]);
70
71   /* Run the simulation */
72   res = MSG_main();
73   INFO1("Simulation time %g", MSG_get_clock());
74   if (res == MSG_OK)
75     res = MSG_clean();
76
77   TRACE_end ();
78
79   if (res == MSG_OK)
80     return 0;
81   else
82     return 1;
83 }                               /* end_of_main */