Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / examples / msg / trace-link-srcdst-user-variables / trace-link-srcdst-user-variables.c
1 /* Copyright (c) 2012-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <simgrid/msg.h>
8
9 /** @addtogroup MSG_examples
10  *
11  * - <b>Routes: trace-link-srcdst-user-variables/trace-link-srcdst-user-variables.c</b>. Instead of providing the name
12  *   of the link to update one of its variable, this example shows how to provide two hosts as parameter (source and
13  *   destination, as defined in the platform file). The tracing mechanism will get the route between these two hosts, if
14  *   it is defined in the platform file, and update the variable of all the links of that route to the value provided.
15  */
16
17 //dump function to create and execute a task
18 static void create_and_execute_task (void)
19 {
20   msg_task_t task = MSG_task_create("task", 1000000, 0, NULL);
21   MSG_task_execute (task);
22   MSG_task_destroy (task);
23 }
24
25 static int trace_fun(int argc, char *argv[])
26 {
27   //Set initial values for the link user variables
28   //This example uses source and destination where source and destination are the name of hosts inthe platform file.
29   //The functions will set/change the value of the variable for all links in the route between source and destination.
30
31   //Set the Link_Capacity variable
32   TRACE_link_srcdst_variable_set("Tremblay", "Bourassa", "Link_Capacity", 12.34);
33   TRACE_link_srcdst_variable_set("Fafard", "Ginette", "Link_Capacity", 56.78);
34
35   //Set the Link_Utilization variable
36   TRACE_link_srcdst_variable_set("Tremblay", "Bourassa", "Link_Utilization", 1.2);
37   TRACE_link_srcdst_variable_set("Fafard", "Ginette", "Link_Utilization", 3.4);
38
39   //run the simulation, update my variables accordingly
40   for (int i = 0; i < 10; i++) {
41     create_and_execute_task ();
42
43     //Add to link user variables
44     TRACE_link_srcdst_variable_add ("Tremblay", "Bourassa", "Link_Utilization", 5.6);
45     TRACE_link_srcdst_variable_add ("Fafard", "Ginette", "Link_Utilization", 7.8);
46   }
47
48   for (int i = 0; i < 10; i++) {
49     create_and_execute_task ();
50
51     //Subtract from link user variables
52     TRACE_link_srcdst_variable_sub ("Tremblay", "Bourassa", "Link_Utilization", 3.4);
53     TRACE_link_srcdst_variable_sub ("Fafard", "Ginette", "Link_Utilization", 5.6);
54   }
55
56   return 0;
57 }
58
59 int main(int argc, char *argv[])
60 {
61   MSG_init(&argc, argv);
62   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
63              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
64
65   MSG_create_environment(argv[1]);
66
67   //declaring link user variables (one without, another with a RGB color)
68   TRACE_link_variable_declare("Link_Capacity");
69   TRACE_link_variable_declare_with_color ("Link_Utilization", "0.9 0.1 0.1");
70
71   //register functions and launch deployment
72   MSG_function_register("master", trace_fun);
73   MSG_function_register("worker", trace_fun);
74   MSG_launch_application(argv[2]);
75
76   MSG_main();
77   return 0;
78 }