1 /* Copyright (c) 2010-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 /** @addtogroup MSG_examples
9 * - <b>tracing/categories.c</b> This is a master/worker program. The master creates tasks and send them to workers.
10 * For each task received, the worker executes it and then destroys it. This program declares several tracing categories
11 * that are used to classify tasks. When the program is executed, the tracing mechanism registers the resource
12 * utilization of hosts and links according to these categories. You might want to run this program with the following
15 * --cfg=tracing/categorized:yes
16 * --cfg=tracing/uncategorized:yes
17 * --cfg=viva/categorized:viva_cat.plist
18 * --cfg=viva/uncategorized:viva_uncat.plist
19 * (See \ref tracing_tracing_options for details)
22 #include "simgrid/msg.h"
24 static int master(int argc, char *argv[])
26 long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
27 long workers_count = xbt_str_parse_int(argv[4], "Invalid amount of workers: %s");
30 for (i = 0; i < number_of_tasks; i++) {
31 msg_task_t task = NULL;
33 //creating task and setting its category
35 task = MSG_task_create("task_compute", 10000000, 0, NULL);
36 MSG_task_set_category(task, "compute");
38 task = MSG_task_create("task_request", 10, 10, NULL);
39 MSG_task_set_category(task, "request");
41 task = MSG_task_create("task_data", 10, 10000000, NULL);
42 MSG_task_set_category(task, "data");
44 MSG_task_send(task, "master_mailbox");
47 for (i = 0; i < workers_count; i++) {
48 msg_task_t finalize = MSG_task_create("finalize", 0, 1000, 0);
49 MSG_task_set_category(finalize, "finalize");
50 MSG_task_send(finalize, "master_mailbox");
56 static int worker(int argc, char *argv[])
58 msg_task_t task = NULL;
61 MSG_task_receive(&(task), "master_mailbox");
63 if (!strcmp(MSG_task_get_name(task), "finalize")) {
64 MSG_task_destroy(task);
68 MSG_task_execute(task);
69 MSG_task_destroy(task);
75 int main(int argc, char *argv[])
77 MSG_init(&argc, argv);
78 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
79 "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
81 MSG_create_environment(argv[1]);
83 //declaring user categories with RGB colors
84 TRACE_category_with_color ("compute", "1 0 0"); //red
85 TRACE_category_with_color ("request", "0 1 0"); //green
86 TRACE_category_with_color ("data", "0 0 1"); //blue
87 TRACE_category_with_color ("finalize", "0 0 0");//black
89 MSG_function_register("master", master);
90 MSG_function_register("worker", worker);
91 MSG_launch_application(argv[2]);