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. */
9 #include "xbt/sysdep.h" /* calloc, printf */
11 /* Create a log channel to have nice outputs. */
13 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
15 "Messages specific for this msg example");
17 int master(int argc, char *argv[]);
18 int slave(int argc, char *argv[]);
19 MSG_error_t test_all(const char *platform_file,
20 const char *application_file);
22 /** Emitter function */
23 int master(int argc, char *argv[])
25 long number_of_tasks = atol(argv[1]);
26 double task_comp_size = atof(argv[2]);
27 double task_comm_size = atof(argv[3]);
28 long slaves_count = atol(argv[4]);
30 //setting the variable "is_master" (previously declared) to value 1
31 TRACE_host_variable_set(MSG_host_self()->name, "is_master", 1);
33 TRACE_mark("msmark", "start_send_tasks");
35 for (i = 0; i < number_of_tasks; i++) {
37 task = MSG_task_create("task", task_comp_size, task_comm_size, NULL);
39 //setting the variable "task_creation" to value i
40 TRACE_host_variable_set(MSG_host_self()->name, "task_creation", i);
42 //setting the category of task to "compute"
43 //the category of a task must be defined before it is sent or executed
44 TRACE_msg_set_task_category(task, "compute");
45 MSG_task_send(task, "master_mailbox");
47 TRACE_mark("msmark", "finish_send_tasks");
49 for (i = 0; i < slaves_count; i++) {
50 m_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
51 TRACE_msg_set_task_category(finalize, "finalize");
52 MSG_task_send(finalize, "master_mailbox");
58 /** Receiver function */
59 int slave(int argc, char *argv[])
63 TRACE_host_variable_set(MSG_host_self()->name, "is_slave", 1);
65 MSG_task_receive(&(task), "master_mailbox");
67 if (!strcmp(MSG_task_get_name(task), "finalize")) {
68 MSG_task_destroy(task);
71 //adding the value returned by MSG_task_get_compute_duration(task)
72 //to the variable "task_computation"
73 TRACE_host_variable_add(MSG_host_self()->name,
75 MSG_task_get_compute_duration(task));
76 MSG_task_execute(task);
77 MSG_task_destroy(task);
84 MSG_error_t test_all(const char *platform_file,
85 const char *application_file)
87 MSG_error_t res = MSG_OK;
89 { /* Simulation setting */
90 MSG_create_environment(platform_file);
93 /* declaring tracing categories */
95 //declaring user variables
96 TRACE_host_variable_declare("is_slave");
97 TRACE_host_variable_declare("is_master");
98 TRACE_host_variable_declare("task_creation");
99 TRACE_host_variable_declare("task_computation");
101 //declaring user markers
102 TRACE_declare_mark("msmark");
104 //declaring user categories with RGB colors (values from 0 to 1)
105 TRACE_category_with_color ("compute", "1 0 0"); //compute is red
106 TRACE_category_with_color ("finalize", "0 1 0"); //finalize is green
107 //categories without user-defined colors receive
108 //random colors generated by the tracing system
109 TRACE_category ("request");
110 TRACE_category_with_color ("report", NULL);
112 { /* Application deployment */
113 MSG_function_register("master", master);
114 MSG_function_register("slave", slave);
115 MSG_launch_application(application_file);
119 XBT_INFO("Simulation time %g", MSG_get_clock());
125 int main(int argc, char *argv[])
127 MSG_error_t res = MSG_OK;
129 MSG_global_init(&argc, argv);
131 printf("Usage: %s platform_file deployment_file\n", argv[0]);
132 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
136 res = test_all(argv[1], argv[2]);