3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/sysdep.h" /* calloc, printf */
12 /* Create a log channel to have nice outputs. */
14 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
16 "Messages specific for this msg example");
18 int master(int argc, char *argv[]);
19 int slave(int argc, char *argv[]);
20 MSG_error_t test_all(const char *platform_file,
21 const char *application_file);
23 /** Emitter function */
24 int master(int argc, char *argv[])
26 long number_of_tasks = atol(argv[1]);
27 double task_comp_size = atof(argv[2]);
28 double task_comm_size = atof(argv[3]);
29 long slaves_count = atol(argv[4]);
30 XBT_INFO("master %ld %f %f %ld", number_of_tasks, task_comp_size,
31 task_comm_size, slaves_count);
34 for (i = 0; i < number_of_tasks; i++) {
36 snprintf (task_name, 100, "task-%d", i);
38 task = MSG_task_create(task_name, task_comp_size, task_comm_size, NULL);
40 //setting the category of task to "compute"
41 //the category of a task must be defined before it is sent or executed
42 TRACE_msg_set_task_category(task, "compute");
43 MSG_task_send(task, "master_mailbox");
46 for (i = 0; i < slaves_count; i++) {
48 snprintf (task_name, 100, "task-%d", i);
49 m_task_t finalize = MSG_task_create(task_name, 0, 0, xbt_strdup("finalize"));
50 TRACE_msg_set_task_category(finalize, "finalize");
51 MSG_task_send(finalize, "master_mailbox");
57 /** Receiver function */
58 int slave(int argc, char *argv[])
64 res = MSG_task_receive(&(task), "master_mailbox");
70 char *data = MSG_task_get_data(task);
71 if (data && !strcmp(data, "finalize")) {
72 MSG_task_destroy(task);
76 XBT_INFO("Executing task %f", MSG_task_get_compute_duration(task));
77 MSG_task_execute(task);
78 XBT_INFO("End of execution");
79 MSG_task_destroy(task);
86 MSG_error_t test_all(const char *platform_file,
87 const char *application_file)
89 MSG_error_t res = MSG_OK;
91 { /* Simulation setting */
92 MSG_set_channel_number(0);
93 MSG_create_environment(platform_file);
96 //declaring user categories
97 TRACE_category_with_color ("compute", "1 0 0"); //compute is red
98 TRACE_category_with_color ("finalize", "0 1 0"); //finalize is green
100 { /* Application deployment */
101 MSG_function_register("master", master);
102 MSG_function_register("slave", slave);
103 MSG_launch_application(application_file);
107 XBT_INFO("Simulation time %g", MSG_get_clock());
113 int main(int argc, char *argv[])
115 MSG_error_t res = MSG_OK;
117 MSG_global_init(&argc, argv);
119 printf("Usage: %s platform_file deployment_file\n", argv[0]);
120 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
124 res = test_all(argv[1], argv[2]);