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>Links: trace-link-user-variables/trace-link-user-variables.c</b>. You need to provide the name of the link to
12 * update the value of the variable associated to that link.
15 //dump function to create and execute a task
16 static void create_and_execute_task (void)
18 msg_task_t task = MSG_task_create("task", 1000000, 0, NULL);
19 MSG_task_execute (task);
20 MSG_task_destroy (task);
23 static int trace_fun(int argc, char *argv[])
25 //set initial values for the link user variables this example only shows for links identified by "6" and "3" in the
28 //Set the Link_Capacity variable
29 TRACE_link_variable_set("6", "Link_Capacity", 12.34);
30 TRACE_link_variable_set("3", "Link_Capacity", 56.78);
32 //Set the Link_Utilization variable
33 TRACE_link_variable_set("3", "Link_Utilization", 1.2);
34 TRACE_link_variable_set("6", "Link_Utilization", 3.4);
36 //run the simulation, update my variables accordingly
37 for (int i = 0; i < 10; i++) {
38 create_and_execute_task ();
40 //Add to link user variables
41 TRACE_link_variable_add ("3", "Link_Utilization", 5.6);
42 TRACE_link_variable_add ("6", "Link_Utilization", 7.8);
45 for (int i = 0; i < 10; i++) {
46 create_and_execute_task ();
48 //Subtract from link user variables
49 TRACE_link_variable_sub ("3", "Link_Utilization", 3.4);
50 TRACE_link_variable_sub ("6", "Link_Utilization", 5.6);
56 int main(int argc, char *argv[])
58 MSG_init(&argc, argv);
59 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
60 "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
62 MSG_create_environment(argv[1]);
64 //declaring link user variables (one without, another with a RGB color)
65 TRACE_link_variable_declare("Link_Capacity");
66 TRACE_link_variable_declare_with_color ("Link_Utilization", "0.9 0.1 0.1");
68 //register functions and launch deployment
69 MSG_function_register("master", trace_fun);
70 MSG_function_register("worker", trace_fun);
71 MSG_launch_application(argv[2]);