Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7170bc15a6da295a93608aa70597299e3a8573bd
[simgrid.git] / examples / msg / tracing / link_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 <simgrid/msg.h>
8
9 /** @addtogroup MSG_examples
10  *
11  * - <b>tracing/link_user_variables.c</b>: This program demonstrates how to
12  * trace user variables associated to the links of the platform file. You need
13  * to provide the name of the link to update the value of the variable associated
14  * to that link.
15  * You might want to run this program with the following parameters:
16  * --cfg=tracing:yes
17  * --cfg=tracing/platform:yes
18  * (See \ref tracing_tracing_options for details)
19  */
20
21 int master(int argc, char *argv[]);
22
23 //dump function to create and execute a task
24 static void create_and_execute_task (void)
25 {
26   msg_task_t task = MSG_task_create("task", 1000000, 0, NULL);
27   MSG_task_execute (task);
28   MSG_task_destroy (task);
29 }
30
31 int master(int argc, char *argv[])
32 {
33   int i;
34
35   //set initial values for the link user variables
36   //this example only shows for links
37   //identified by "6" and "3" in the platform file
38
39   //Set the Link_Capacity variable
40   TRACE_link_variable_set("6", "Link_Capacity", 12.34);
41   TRACE_link_variable_set("3", "Link_Capacity", 56.78);
42
43   //Set the Link_Utilization variable
44   TRACE_link_variable_set("3", "Link_Utilization", 1.2);
45   TRACE_link_variable_set("6", "Link_Utilization", 3.4);
46
47   //run the simulation, update my variables accordingly
48   for (i = 0; i < 10; i++) {
49     create_and_execute_task ();
50
51     //Add to link user variables
52     TRACE_link_variable_add ("3", "Link_Utilization", 5.6);
53     TRACE_link_variable_add ("6", "Link_Utilization", 7.8);
54   }
55
56   for (i = 0; i < 10; i++) {
57     create_and_execute_task ();
58
59     //Subtract from link user variables
60     TRACE_link_variable_sub ("3", "Link_Utilization", 3.4);
61     TRACE_link_variable_sub ("6", "Link_Utilization", 5.6);
62   }
63
64   return 0;
65 }
66
67 /** Main function */
68 int main(int argc, char *argv[])
69 {
70   MSG_init(&argc, argv);
71   if (argc < 3) {
72     printf("Usage: %s platform_file deployment_file\n", argv[0]);
73     exit(1);
74   }
75
76   char *platform_file = argv[1];
77   char *deployment_file = argv[2];
78   MSG_create_environment(platform_file);
79
80   //declaring link user variables (one without, another with a RGB color)
81   TRACE_link_variable_declare("Link_Capacity");
82   TRACE_link_variable_declare_with_color ("Link_Utilization", "0.9 0.1 0.1");
83
84   //register "master" and "slave" functions and launch deployment
85   MSG_function_register("master", master);
86   MSG_function_register("slave", master);
87   MSG_launch_application(deployment_file);
88
89   MSG_main();
90   return 0;
91 }