3 /* Copyright (c) 2009 The SimGrid team. All rights reserved. */
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. */
8 #include "msg/msg.h" /* core library */
9 #include "xbt/sysdep.h" /* calloc */
11 /* Create a log channel to have nice outputs. */
13 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
14 "Messages specific for this msg example");
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[])
20 char *destination = NULL;
24 while (1){ // I am an eternal emigrant
25 MSG_task_receive(&(task), "master_mailbox");
26 destination = (char*)MSG_task_get_data (task);
27 if (!destination) break; //there is no destination, die
28 XBT_INFO("Migrating to %s", destination);
29 MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name(destination));
30 MSG_process_sleep(2); // I am tired, have to sleep for 2 seconds
31 MSG_task_destroy (task);
37 static int master(int argc, char *argv[])
41 // I am the master of emigrant process,
42 // I tell it where it must emigrate to.
43 xbt_dynar_t destinations = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
44 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
45 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Jupiter"));
46 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
47 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
48 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Bourassa"));
49 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
50 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
51 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
52 xbt_dynar_push_as (destinations, char*, NULL);
56 xbt_dynar_foreach(destinations, i, destination){
57 task = MSG_task_create("task", 0, 0, NULL);
59 MSG_task_set_data(task, xbt_strdup (destination));
61 TRACE_msg_set_task_category(task, "migration_order");
62 MSG_task_send (task, "master_mailbox");
65 xbt_dynar_free (&destinations);
70 int main(int argc, char *argv[])
72 MSG_error_t res = MSG_OK;
74 /* Argument checking */
75 MSG_global_init(&argc, argv);
77 XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]);
78 XBT_CRITICAL("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
83 /* Simulation setting */
84 MSG_create_environment(argv[1]);
86 TRACE_category ("migration_order");
88 /* Application deployment */
89 MSG_function_register("emigrant", emigrant);
90 MSG_function_register("master", master);
91 MSG_launch_application(argv[2]);
93 /* Run the simulation */
95 XBT_INFO("Simulation time %g", MSG_get_clock());