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_srcdst_user_variables.c</b>: This program demonstrates how to
12 * trace user variables associated to the links of the platform file. Instead of
13 * providing the name of the link to update one of its variable, this example shows
14 * how to provide two hosts as parameter (source and destination, use their names as
15 * defined in the platform file). The tracing mechanism will get the route between
16 * these two hosts, if there is one defined in the platform file, and update the variable
17 * of all the links of that route to the value provided.
18 * You might want to run this program with the following parameters:
20 * --cfg=tracing/platform:yes
21 * (See \ref tracing_tracing_options for details)
24 int master(int argc, char *argv[]);
26 //dump function to create and execute a task
27 static void create_and_execute_task (void)
29 msg_task_t task = MSG_task_create("task", 1000000, 0, NULL);
30 MSG_task_execute (task);
31 MSG_task_destroy (task);
34 int master(int argc, char *argv[])
38 //Set initial values for the link user variables
40 //This example uses source and destination where
41 //source and destination are the name of hosts in
44 //The functions will set/change the value of the variable
45 //for all links in the route between source and destination.
47 //Set the Link_Capacity variable
48 TRACE_link_srcdst_variable_set("Tremblay", "Bourassa", "Link_Capacity", 12.34);
49 TRACE_link_srcdst_variable_set("Fafard", "Ginette", "Link_Capacity", 56.78);
51 //Set the Link_Utilization variable
52 TRACE_link_srcdst_variable_set("Tremblay", "Bourassa", "Link_Utilization", 1.2);
53 TRACE_link_srcdst_variable_set("Fafard", "Ginette", "Link_Utilization", 3.4);
55 //run the simulation, update my variables accordingly
56 for (i = 0; i < 10; i++) {
57 create_and_execute_task ();
59 //Add to link user variables
60 TRACE_link_srcdst_variable_add ("Tremblay", "Bourassa", "Link_Utilization", 5.6);
61 TRACE_link_srcdst_variable_add ("Fafard", "Ginette", "Link_Utilization", 7.8);
64 for (i = 0; i < 10; i++) {
65 create_and_execute_task ();
67 //Subtract from link user variables
68 TRACE_link_srcdst_variable_sub ("Tremblay", "Bourassa", "Link_Utilization", 3.4);
69 TRACE_link_srcdst_variable_sub ("Fafard", "Ginette", "Link_Utilization", 5.6);
76 int main(int argc, char *argv[])
78 MSG_init(&argc, argv);
80 printf("Usage: %s platform_file deployment_file\n", argv[0]);
84 char *platform_file = argv[1];
85 char *deployment_file = argv[2];
86 MSG_create_environment(platform_file);
88 //declaring link user variables (one without, another with a RGB color)
89 TRACE_link_variable_declare("Link_Capacity");
90 TRACE_link_variable_declare_with_color ("Link_Utilization", "0.9 0.1 0.1");
92 //register "master" and "slave" functions and launch deployment
93 MSG_function_register("master", master);
94 MSG_function_register("slave", master);
95 MSG_launch_application(deployment_file);