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;
22 INFO0("Setting process category");
23 TRACE_msg_set_process_category(MSG_process_self(), "emigrant", "1 0 0");
26 while (1){ // I am an eternal emigrant
27 MSG_task_receive(&(task), "master_mailbox");
28 destination = (char*)MSG_task_get_data (task);
29 if (!destination) break; //there is no destination, die
30 INFO1("Migrating to %s", destination);
31 MSG_process_change_host(MSG_get_host_by_name(destination));
32 MSG_process_sleep(2); // I am tired, have to sleep for 2 seconds
33 xbt_free (destination);
34 MSG_task_destroy (task);
40 static int master(int argc, char *argv[])
44 TRACE_msg_set_process_category(MSG_process_self(), "master", "1 0 0");
46 // I am the master of emigrant process,
47 // I tell it where it must emigrate to.
48 xbt_dynar_t destinations = xbt_dynar_new (sizeof(char*), xbt_free);
49 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
50 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Jupiter"));
51 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
52 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
53 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Bourassa"));
54 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
55 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
56 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
57 xbt_dynar_push_as (destinations, char*, NULL);
61 xbt_dynar_foreach(destinations, i, destination){
62 task = MSG_task_create("task", 0, 0, NULL);
64 MSG_task_set_data(task, xbt_strdup (destination));
66 TRACE_msg_set_task_category(task, "migration_order");
67 MSG_task_send (task, "master_mailbox");
74 int main(int argc, char *argv[])
76 MSG_error_t res = MSG_OK;
78 /* Argument checking */
79 MSG_global_init(&argc, argv);
81 CRITICAL1("Usage: %s platform_file deployment_file\n", argv[0]);
82 CRITICAL1("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
87 /* Simulation setting */
88 MSG_create_environment(argv[1]);
90 TRACE_category ("migration_order");
92 /* Application deployment */
93 MSG_function_register("emigrant", emigrant);
94 MSG_function_register("master", master);
95 MSG_launch_application(argv[2]);
97 /* Run the simulation */
99 INFO1("Simulation time %g", MSG_get_clock());