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 xbt_mutex_t mutex = NULL;
16 xbt_cond_t cond = NULL;
17 static m_process_t process_to_migrate = NULL;
19 /** The guy we will move from host to host. It move alone and then is moved by policeman back */
20 static int emigrant(int argc, char *argv[])
24 ("I'll look for a new job on another machine where the grass is greener.");
25 MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin"));
27 XBT_INFO("Yeah, found something to do");
28 task = MSG_task_create("job", 98095000, 0, NULL);
29 MSG_task_execute(task);
30 MSG_task_destroy(task);
32 XBT_INFO("Moving back home after work");
33 MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Jacquelin"));
34 MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin"));
36 xbt_mutex_acquire(mutex);
37 process_to_migrate = MSG_process_self();
38 xbt_cond_broadcast(cond);
39 xbt_mutex_release(mutex);
40 MSG_process_suspend(MSG_process_self());
41 m_host_t h = MSG_process_get_host(MSG_process_self());
42 XBT_INFO("I've been moved on this new host: %s", h->name);
43 XBT_INFO("Uh, nothing to do here. Stopping now");
45 } /* end_of_emigrant */
48 /* This function move the emigrant on Jacquelin */
49 static int policeman(int argc, char *argv[])
52 xbt_mutex_acquire(mutex);
53 XBT_INFO("Wait a bit before migrating the emigrant.");
54 while (process_to_migrate == NULL) xbt_cond_wait(cond, mutex);
55 MSG_process_migrate(process_to_migrate, MSG_get_host_by_name("Jacquelin"));
56 XBT_INFO("I moved the emigrant");
57 MSG_process_resume(process_to_migrate);
58 xbt_mutex_release(mutex);
61 } /* end_of_policeman */
65 int main(int argc, char *argv[])
67 MSG_error_t res = MSG_OK;
69 /* Argument checking */
70 MSG_global_init(&argc, argv);
72 XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]);
73 XBT_CRITICAL("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
78 /* Simulation setting */
79 MSG_create_environment(argv[1]);
81 /* Application deployment */
82 MSG_function_register("emigrant", emigrant);
83 MSG_function_register("policeman", policeman);
84 MSG_launch_application(argv[2]);
86 /* Run the simulation */
87 mutex = xbt_mutex_init();
88 cond = xbt_cond_init();
90 XBT_INFO("Simulation time %g", MSG_get_clock());
91 xbt_cond_destroy(cond);
92 xbt_mutex_destroy(mutex);