Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add an example of process migration in examples/msg/migration
[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,"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("I'll look for a new job on another machine where the grass is greener.");
20   MSG_process_change_host(MSG_get_host_by_name("Boivin"));
21   INFO0("Yeah, found something to do");
22   task = MSG_task_create("job",98095000,0,NULL);
23   MSG_task_execute(task);
24   MSG_task_destroy(task);
25   INFO0("Moving back home after work");
26   MSG_process_change_host(MSG_get_host_by_name("Jacquelin"));
27   INFO0("Uh, nothing to do here. Stopping now");
28   return 0;
29 } /* end_of_emigrant */
30
31 /* This function would move the emigrant back home, if it were possible to do so in the MSG API.
32  * Nothing for now.
33  */
34 static int policeman(int argc, char *argv[])
35 {
36   INFO0("No function in the API to move the emigrant back, so do nothing.");
37   return 0;
38 } /* end_of_policeman */
39
40
41 /** Main function */
42 int main(int argc, char *argv[]) {
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",argv[0]);
50      exit(1);
51   }
52
53   /* Simulation setting */
54   MSG_create_environment(argv[1]);
55
56   /* Application deployment */
57   MSG_function_register("emigrant", emigrant);
58   MSG_launch_application(argv[2]);
59
60   /* Run the simulation */
61   res = MSG_main();
62   INFO1("Simulation time %g",MSG_get_clock());
63   if (res==MSG_OK)
64           res = MSG_clean();
65
66   if(res==MSG_OK)
67     return 0;
68   else
69     return 1;
70 } /* end_of_main */