1 /* Copyright (c) 2010-2016. 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 #include "simgrid/msg.h"
8 /* The guy we will move from host to host. It move alone and then is moved by policeman back */
9 static int emigrant(int argc, char *argv[])
11 msg_task_t task = NULL;
12 char *destination = NULL;
16 while (1){ // I am an eternal emigrant
17 MSG_task_receive(&(task), "master_mailbox");
18 destination = (char*)MSG_task_get_data (task);
19 MSG_task_destroy (task);
20 if (destination == NULL)
21 break; //there is no destination, die
22 MSG_process_migrate(MSG_process_self(), MSG_host_by_name(destination));
23 MSG_process_sleep(2); // I am tired, have to sleep for 2 seconds
30 static int policeman(int argc, char *argv[])
32 // I am the master of emigrant process,
33 // I tell it where it must emigrate to.
34 xbt_dynar_t destinations = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
35 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
36 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Jupiter"));
37 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
38 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
39 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Bourassa"));
40 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
41 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
42 xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
43 xbt_dynar_push_as (destinations, char*, NULL);
47 xbt_dynar_foreach(destinations, i, destination){
48 msg_task_t task = MSG_task_create("task", 0, 0, NULL);
49 if (destination != NULL){
50 MSG_task_set_data(task, xbt_strdup (destination));
52 MSG_task_set_category(task, "migration_order");
53 MSG_task_send (task, "master_mailbox");
55 xbt_dynar_free (&destinations);
59 int main(int argc, char *argv[])
61 MSG_init(&argc, argv);
62 xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
64 MSG_create_environment(argv[1]);
66 TRACE_category ("migration_order");
68 MSG_process_create("emigrant", emigrant, NULL, MSG_get_host_by_name("Fafard"));
69 MSG_process_create("policeman", policeman, NULL, MSG_get_host_by_name("Tremblay"));