Logo AND Algorithmique Numérique Distribuée

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