Logo AND Algorithmique Numérique Distribuée

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