1 /* Copyright (c) 2010. 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/ms.c</b> TODO
14 #include "xbt/sysdep.h" /* calloc, printf */
16 /* Create a log channel to have nice outputs. */
18 #include "xbt/asserts.h"
19 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
20 "Messages specific for this msg example");
22 int master(int argc, char *argv[]);
23 int slave(int argc, char *argv[]);
25 /** Emitter function */
26 int master(int argc, char *argv[])
28 long number_of_tasks = atol(argv[1]);
29 double task_comp_size = atof(argv[2]);
30 double task_comm_size = atof(argv[3]);
31 long slaves_count = atol(argv[4]);
33 //setting the variable "is_master" (previously declared) to value 1
34 TRACE_host_variable_set(MSG_host_self()->name, "is_master", 1);
36 TRACE_mark("msmark", "start_send_tasks");
38 for (i = 0; i < number_of_tasks; i++) {
40 task = MSG_task_create("task", task_comp_size, task_comm_size, NULL);
42 //setting the variable "task_creation" to value i
43 TRACE_host_variable_set(MSG_host_self()->name, "task_creation", i);
45 //setting the category of task to "compute"
46 //the category of a task must be defined before it is sent or executed
47 TRACE_msg_set_task_category(task, "compute");
48 MSG_task_send(task, "master_mailbox");
50 TRACE_mark("msmark", "finish_send_tasks");
52 for (i = 0; i < slaves_count; i++) {
53 m_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
54 TRACE_msg_set_task_category(finalize, "finalize");
55 MSG_task_send(finalize, "master_mailbox");
61 /** Receiver function */
62 int slave(int argc, char *argv[])
66 TRACE_host_variable_set(MSG_host_self()->name, "is_slave", 1);
68 MSG_task_receive(&(task), "master_mailbox");
70 if (!strcmp(MSG_task_get_name(task), "finalize")) {
71 MSG_task_destroy(task);
74 //adding the value returned by MSG_task_get_compute_duration(task)
75 //to the variable "task_computation"
76 TRACE_host_variable_add(MSG_host_self()->name,
78 MSG_task_get_compute_duration(task));
79 MSG_task_execute(task);
80 MSG_task_destroy(task);
87 int main(int argc, char *argv[])
89 MSG_global_init(&argc, argv);
91 printf("Usage: %s platform_file deployment_file\n", argv[0]);
95 char *platform_file = argv[1];
96 char *deployment_file = argv[2];
97 MSG_create_environment(platform_file);
99 //declaring user variables
100 TRACE_host_variable_declare("is_slave");
101 TRACE_host_variable_declare("is_master");
102 TRACE_host_variable_declare("task_creation");
103 TRACE_host_variable_declare("task_computation");
105 //declaring user markers
106 TRACE_declare_mark("msmark");
108 //declaring user categories with RGB colors (values from 0 to 1)
109 TRACE_category_with_color ("compute", "1 0 0"); //compute is red
110 TRACE_category_with_color ("finalize", "0 1 0"); //finalize is green
111 //categories without user-defined colors receive
112 //random colors generated by the tracing system
113 TRACE_category ("request");
114 TRACE_category_with_color ("report", NULL);
116 MSG_function_register("master", master);
117 MSG_function_register("slave", slave);
118 MSG_launch_application(deployment_file);