1 /* Copyright (c) 2012-2015. 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 trace user variables associated to
12 * the links of the platform file. Instead of providing the name of the link to update one of its variable, this
13 * example shows how to provide two hosts as parameter (source and destination, use their names as defined in the
14 * platform file). The tracing mechanism will get the route between these two hosts, if there is one defined in the
15 * platform file, and update the variable of all the links of that route to the value provided.
16 * You might want to run this program with the following parameters:
18 * --cfg=tracing/platform:yes
19 * (See \ref tracing_tracing_options for details)
22 //dump function to create and execute a task
23 static void create_and_execute_task (void)
25 msg_task_t task = MSG_task_create("task", 1000000, 0, NULL);
26 MSG_task_execute (task);
27 MSG_task_destroy (task);
30 static int master(int argc, char *argv[])
32 //Set initial values for the link user variables
33 //This example uses source and destination where source and destination are the name of hosts inthe platform file.
34 //The functions will set/change the value of the variable for all links in the route between source and destination.
36 //Set the Link_Capacity variable
37 TRACE_link_srcdst_variable_set("Tremblay", "Bourassa", "Link_Capacity", 12.34);
38 TRACE_link_srcdst_variable_set("Fafard", "Ginette", "Link_Capacity", 56.78);
40 //Set the Link_Utilization variable
41 TRACE_link_srcdst_variable_set("Tremblay", "Bourassa", "Link_Utilization", 1.2);
42 TRACE_link_srcdst_variable_set("Fafard", "Ginette", "Link_Utilization", 3.4);
44 //run the simulation, update my variables accordingly
45 for (int i = 0; i < 10; i++) {
46 create_and_execute_task ();
48 //Add to link user variables
49 TRACE_link_srcdst_variable_add ("Tremblay", "Bourassa", "Link_Utilization", 5.6);
50 TRACE_link_srcdst_variable_add ("Fafard", "Ginette", "Link_Utilization", 7.8);
53 for (int i = 0; i < 10; i++) {
54 create_and_execute_task ();
56 //Subtract from link user variables
57 TRACE_link_srcdst_variable_sub ("Tremblay", "Bourassa", "Link_Utilization", 3.4);
58 TRACE_link_srcdst_variable_sub ("Fafard", "Ginette", "Link_Utilization", 5.6);
64 int main(int argc, char *argv[])
66 MSG_init(&argc, argv);
67 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
68 "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
70 MSG_create_environment(argv[1]);
72 //declaring link user variables (one without, another with a RGB color)
73 TRACE_link_variable_declare("Link_Capacity");
74 TRACE_link_variable_declare_with_color ("Link_Utilization", "0.9 0.1 0.1");
76 //register "master" and "slave" functions and launch deployment
77 MSG_function_register("master", master);
78 MSG_function_register("slave", master);
79 MSG_launch_application(argv[2]);