1 /* Copyright (c) 2010-2015. 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 /** @addtogroup MSG_examples
9 * - <b>Process migration: trace-process-migration/trace-process-migration.c</b>. Running this program with the
10 * <i>--cfg=tracing:yes</i> and <i>--cfg=tracing/msg/process:yes</i> options enables a Gantt-chart visualization of
11 * where the process has been hosted during its execution. Migrations are represented by arrows from the origin to
12 * the destination host.
15 #include "simgrid/msg.h"
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[])
20 msg_task_t task = NULL;
21 char *destination = NULL;
25 while (1){ // I am an eternal emigrant
26 MSG_task_receive(&(task), "master_mailbox");
27 destination = (char*)MSG_task_get_data (task);
28 MSG_task_destroy (task);
29 if (!destination) break; //there is no destination, die
30 MSG_process_migrate(MSG_process_self(), MSG_host_by_name(destination));
31 MSG_process_sleep(2); // I am tired, have to sleep for 2 seconds
38 static int policeman(int argc, char *argv[])
40 msg_task_t task = NULL;
42 // I am the master of emigrant process,
43 // I tell it where it must emigrate to.
44 xbt_dynar_t destinations = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
45 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
46 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Jupiter"));
47 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
48 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
49 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Bourassa"));
50 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
51 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
52 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
53 xbt_dynar_push_as (destinations, char*, NULL);
57 xbt_dynar_foreach(destinations, i, destination){
58 task = MSG_task_create("task", 0, 0, NULL);
60 MSG_task_set_data(task, xbt_strdup (destination));
62 MSG_task_set_category(task, "migration_order");
63 MSG_task_send (task, "master_mailbox");
66 xbt_dynar_free (&destinations);
70 int main(int argc, char *argv[])
72 MSG_init(&argc, argv);
73 xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
75 MSG_create_environment(argv[1]);
77 TRACE_category ("migration_order");
79 MSG_process_create("emigrant", emigrant, NULL, MSG_get_host_by_name("Fafard"));
80 MSG_process_create("policeman", policeman, NULL, MSG_get_host_by_name("Tremblay"));