Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b0d435fd6e9bbbccebd905522d2e3f67e6f59158
[simgrid.git] / examples / msg / trace-route-user-variables / trace-route-user-variables.c
1 /* Copyright (c) 2012-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <simgrid/msg.h>
7
8 //dump function to create and execute a task
9 static void create_and_execute_task (void)
10 {
11   msg_task_t task = MSG_task_create("task", 1000000, 0, NULL);
12   MSG_task_execute (task);
13   MSG_task_destroy (task);
14 }
15
16 static int trace_fun(int argc, char *argv[])
17 {
18   //Set initial values for the link user variables
19   //This example uses source and destination where source and destination are the name of hosts inthe platform file.
20   //The functions will set/change the value of the variable for all links in the route between source and destination.
21
22   //Set the Link_Capacity variable
23   TRACE_link_srcdst_variable_set("Tremblay", "Bourassa", "Link_Capacity", 12.34);
24   TRACE_link_srcdst_variable_set("Fafard", "Ginette", "Link_Capacity", 56.78);
25
26   //Set the Link_Utilization variable
27   TRACE_link_srcdst_variable_set("Tremblay", "Bourassa", "Link_Utilization", 1.2);
28   TRACE_link_srcdst_variable_set("Fafard", "Ginette", "Link_Utilization", 3.4);
29
30   //run the simulation, update my variables accordingly
31   for (int i = 0; i < 10; i++) {
32     create_and_execute_task ();
33
34     //Add to link user variables
35     TRACE_link_srcdst_variable_add ("Tremblay", "Bourassa", "Link_Utilization", 5.6);
36     TRACE_link_srcdst_variable_add ("Fafard", "Ginette", "Link_Utilization", 7.8);
37   }
38
39   for (int i = 0; i < 10; i++) {
40     create_and_execute_task ();
41
42     //Subtract from link user variables
43     TRACE_link_srcdst_variable_sub ("Tremblay", "Bourassa", "Link_Utilization", 3.4);
44     TRACE_link_srcdst_variable_sub ("Fafard", "Ginette", "Link_Utilization", 5.6);
45   }
46
47   return 0;
48 }
49
50 int main(int argc, char *argv[])
51 {
52   MSG_init(&argc, argv);
53   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
54              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
55
56   MSG_create_environment(argv[1]);
57
58   //declaring link user variables (one without, another with a RGB color)
59   TRACE_link_variable_declare("Link_Capacity");
60   TRACE_link_variable_declare_with_color ("Link_Utilization", "0.9 0.1 0.1");
61
62   //register functions and launch deployment
63   MSG_function_register("master", trace_fun);
64   MSG_function_register("worker", trace_fun);
65   MSG_launch_application(argv[2]);
66
67   MSG_main();
68   return 0;
69 }