1 /* Copyright (c) 2010 The SimGrid team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 /** @addtogroup MSG_examples
8 * - <b>tracing/procmig.c</b> example to trace process migration using the mask TRACE_PROCESS
11 #include "msg/msg.h" /* core library */
12 #include "xbt/sysdep.h" /* calloc */
14 /* Create a log channel to have nice outputs. */
16 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
17 "Messages specific for this msg example");
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[])
23 char *destination = NULL;
27 while (1){ // I am an eternal emigrant
28 MSG_task_receive(&(task), "master_mailbox");
29 destination = (char*)MSG_task_get_data (task);
30 MSG_task_destroy (task);
31 if (!destination) break; //there is no destination, die
32 MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name(destination));
33 MSG_process_sleep(2); // I am tired, have to sleep for 2 seconds
40 static int master(int argc, char *argv[])
44 // I am the master of emigrant process,
45 // I tell it where it must emigrate to.
46 xbt_dynar_t destinations = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
47 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
48 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Jupiter"));
49 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
50 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
51 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Bourassa"));
52 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
53 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
54 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
55 xbt_dynar_push_as (destinations, char*, NULL);
59 xbt_dynar_foreach(destinations, i, destination){
60 task = MSG_task_create("task", 0, 0, NULL);
62 MSG_task_set_data(task, xbt_strdup (destination));
64 TRACE_msg_set_task_category(task, "migration_order");
65 MSG_task_send (task, "master_mailbox");
68 xbt_dynar_free (&destinations);
73 int main(int argc, char *argv[])
75 /* Argument checking */
76 MSG_global_init(&argc, argv);
78 XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]);
82 char *platform_file = argv[1];
83 char *deployment_file = argv[2];
84 MSG_create_environment(platform_file);
86 TRACE_category ("migration_order");
88 /* Application deployment */
89 MSG_function_register("emigrant", emigrant);
90 MSG_function_register("master", master);
91 MSG_launch_application(deployment_file);