1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "msg/msg.h" /* core library */
8 #include "xbt/sysdep.h" /* calloc */
10 /* Create a log channel to have nice outputs. */
12 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
13 "Messages specific for this msg example");
15 static m_process_t process_to_migrate = NULL;
17 /** The guy we will move from host to host. It move alone and then is moved by policeman back */
18 static int emigrant(int argc, char *argv[])
22 ("I'll look for a new job on another machine where the grass is greener.");
23 MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin"));
25 XBT_INFO("Yeah, found something to do");
26 task = MSG_task_create("job", 98095000, 0, NULL);
27 MSG_task_execute(task);
28 MSG_task_destroy(task);
30 XBT_INFO("Moving back home after work");
31 MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Jacquelin"));
32 MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin"));
34 process_to_migrate = MSG_process_self();
35 MSG_process_suspend(MSG_process_self());
36 m_host_t h = MSG_process_get_host(MSG_process_self());
37 XBT_INFO("I've been moved on this new host: %s", h->name);
38 XBT_INFO("Uh, nothing to do here. Stopping now");
40 } /* end_of_emigrant */
43 /* This function move the emigrant on Jacquelin */
44 static int policeman(int argc, char *argv[])
46 XBT_INFO("Wait a bit before migrating the emigrant.");
47 while (process_to_migrate == NULL) MSG_process_sleep(1);
48 MSG_process_migrate(process_to_migrate, MSG_get_host_by_name("Jacquelin"));
49 XBT_INFO("I moved the emigrant");
50 MSG_process_resume(process_to_migrate);
52 } /* end_of_policeman */
56 int main(int argc, char *argv[])
58 MSG_error_t res = MSG_OK;
60 /* Argument checking */
61 MSG_global_init(&argc, argv);
63 XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]);
64 XBT_CRITICAL("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
69 /* Simulation setting */
70 MSG_create_environment(argv[1]);
72 /* Application deployment */
73 MSG_function_register("emigrant", emigrant);
74 MSG_function_register("policeman", policeman);
75 MSG_launch_application(argv[2]);
77 /* Run the simulation */
79 XBT_INFO("Simulation time %g", MSG_get_clock());