1 /* Copyright (c) 2012-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include <simgrid/msg.h>
9 /** @addtogroup MSG_examples
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
15 * You might want to run this program with the following parameters:
17 * --cfg=tracing/platform:yes
18 * (See \ref tracing_tracing_options for details)
21 int master(int argc, char *argv[]);
23 //dump function to create and execute a task
24 static void create_and_execute_task (void)
26 msg_task_t task = MSG_task_create("task", 1000000, 0, NULL);
27 MSG_task_execute (task);
28 MSG_task_destroy (task);
31 int master(int argc, char *argv[])
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
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);
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);
47 //run the simulation, update my variables accordingly
48 for (i = 0; i < 10; i++) {
49 create_and_execute_task ();
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);
56 for (i = 0; i < 10; i++) {
57 create_and_execute_task ();
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);
68 int main(int argc, char *argv[])
70 MSG_init(&argc, argv);
72 printf("Usage: %s platform_file deployment_file\n", argv[0]);
76 char *platform_file = argv[1];
77 char *deployment_file = argv[2];
78 MSG_create_environment(platform_file);
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");
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);