Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc' into mc++
[simgrid.git] / examples / msg / tracing / link_srcdst_user_variables.c
1 /* Copyright (c) 2012-2014. 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 <msg/msg.h>
8
9 /** @addtogroup MSG_examples
10  *
11  * - <b>tracing/link_srcdst_user_variables.c</b>: This program demonstrates how to
12  * trace user variables associated to the links of the platform file. Instead of
13  * providing the name of the link to update one of its variable, this example shows
14  * how to provide two hosts as parameter (source and destination, use their names as
15  * defined in the platform file). The tracing mechanism will get the route between
16  * these two hosts, if there is one defined in the platform file, and update the variable
17  * of all the links of that route to the value provided.
18  * You might want to run this program with the following parameters:
19  * --cfg=tracing:yes
20  * --cfg=tracing/platform:yes
21  * (See \ref tracing_tracing_options for details)
22  */
23
24 int master(int argc, char *argv[]);
25
26 //dump function to create and execute a task
27 static void create_and_execute_task (void)
28 {
29   msg_task_t task = MSG_task_create("task", 1000000, 0, NULL);
30   MSG_task_execute (task);
31   MSG_task_destroy (task);
32 }
33
34 int master(int argc, char *argv[])
35 {
36   int i;
37
38   //Set initial values for the link user variables
39   //
40   //This example uses source and destination where
41   //source and destination are the name of hosts in
42   //the platform file.
43   //
44   //The functions will set/change the value of the variable
45   //for all links in the route between source and destination.
46
47   //Set the Link_Capacity variable
48   TRACE_link_srcdst_variable_set("Tremblay", "Bourassa", "Link_Capacity", 12.34);
49   TRACE_link_srcdst_variable_set("Fafard", "Ginette", "Link_Capacity", 56.78);
50
51   //Set the Link_Utilization variable
52   TRACE_link_srcdst_variable_set("Tremblay", "Bourassa", "Link_Utilization", 1.2);
53   TRACE_link_srcdst_variable_set("Fafard", "Ginette", "Link_Utilization", 3.4);
54
55   //run the simulation, update my variables accordingly
56   for (i = 0; i < 10; i++) {
57     create_and_execute_task ();
58
59     //Add to link user variables
60     TRACE_link_srcdst_variable_add ("Tremblay", "Bourassa", "Link_Utilization", 5.6);
61     TRACE_link_srcdst_variable_add ("Fafard", "Ginette", "Link_Utilization", 7.8);
62   }
63
64   for (i = 0; i < 10; i++) {
65     create_and_execute_task ();
66
67     //Subtract from link user variables
68     TRACE_link_srcdst_variable_sub ("Tremblay", "Bourassa", "Link_Utilization", 3.4);
69     TRACE_link_srcdst_variable_sub ("Fafard", "Ginette", "Link_Utilization", 5.6);
70   }
71
72   return 0;
73 }
74
75 /** Main function */
76 int main(int argc, char *argv[])
77 {
78   MSG_init(&argc, argv);
79   if (argc < 3) {
80     printf("Usage: %s platform_file deployment_file\n", argv[0]);
81     exit(1);
82   }
83
84   char *platform_file = argv[1];
85   char *deployment_file = argv[2];
86   MSG_create_environment(platform_file);
87
88   //declaring link user variables (one without, another with a RGB color)
89   TRACE_link_variable_declare("Link_Capacity");
90   TRACE_link_variable_declare_with_color ("Link_Utilization", "0.9 0.1 0.1");
91
92   //register "master" and "slave" functions and launch deployment
93   MSG_function_register("master", master);
94   MSG_function_register("slave", master);
95   MSG_launch_application(deployment_file);
96
97   MSG_main();
98   return 0;
99 }