Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
08dc58bb844ee433fca077e39d195ad4eb299c76
[simgrid.git] / examples / deprecated / msg / trace-link-user-variables / trace-link-user-variables.c
1 /* Copyright (c) 2012-2019. 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 this example only shows for links identified by "6" and "3" in the
19   //platform file
20
21   //Set the Link_Capacity variable
22   TRACE_link_variable_set("6", "Link_Capacity", 12.34);
23   TRACE_link_variable_set("3", "Link_Capacity", 56.78);
24
25   //Set the Link_Utilization variable
26   TRACE_link_variable_set("3", "Link_Utilization", 1.2);
27   TRACE_link_variable_set("6", "Link_Utilization", 3.4);
28
29   //run the simulation, update my variables accordingly
30   for (int i = 0; i < 10; i++) {
31     create_and_execute_task ();
32
33     //Add to link user variables
34     TRACE_link_variable_add ("3", "Link_Utilization", 5.6);
35     TRACE_link_variable_add ("6", "Link_Utilization", 7.8);
36   }
37
38   for (int i = 0; i < 10; i++) {
39     create_and_execute_task ();
40
41     //Subtract from link user variables
42     TRACE_link_variable_sub ("3", "Link_Utilization", 3.4);
43     TRACE_link_variable_sub ("6", "Link_Utilization", 5.6);
44   }
45
46   return 0;
47 }
48
49 int main(int argc, char *argv[])
50 {
51   MSG_init(&argc, argv);
52   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
53              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
54
55   MSG_create_environment(argv[1]);
56
57   //declaring link user variables (one without, another with a RGB color)
58   TRACE_link_variable_declare("Link_Capacity");
59   TRACE_link_variable_declare_with_color ("Link_Utilization", "0.9 0.1 0.1");
60
61   //register functions and launch deployment
62   MSG_function_register("master", trace_fun);
63   MSG_function_register("worker", trace_fun);
64   MSG_launch_application(argv[2]);
65
66   MSG_main();
67   return 0;
68 }