1 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "xbt/sysdep.h" /* calloc, printf */
10 /* Create a log channel to have nice outputs. */
12 #include "xbt/asserts.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
14 "Messages specific for this msg example");
16 int master(int argc, char *argv[]);
17 int slave(int argc, char *argv[]);
18 MSG_error_t test_all(const char *platform_file,
19 const char *application_file);
21 /** Emitter function */
22 int master(int argc, char *argv[])
24 long number_of_tasks = atol(argv[1]);
25 double task_comp_size = atof(argv[2]);
26 double task_comm_size = atof(argv[3]);
27 long slaves_count = atol(argv[4]);
28 XBT_INFO("master %ld %f %f %ld", number_of_tasks, task_comp_size,
29 task_comm_size, slaves_count);
32 for (i = 0; i < number_of_tasks; i++) {
34 snprintf (task_name, 100, "task-%d", i);
36 task = MSG_task_create(task_name, task_comp_size, task_comm_size, NULL);
38 //setting the category of task to "compute"
39 //the category of a task must be defined before it is sent or executed
40 TRACE_msg_set_task_category(task, "compute");
41 MSG_task_send(task, "master_mailbox");
44 for (i = 0; i < slaves_count; i++) {
46 snprintf (task_name, 100, "task-%d", i);
47 m_task_t finalize = MSG_task_create(task_name, 0, 0, xbt_strdup("finalize"));
48 TRACE_msg_set_task_category(finalize, "finalize");
49 MSG_task_send(finalize, "master_mailbox");
55 /** Receiver function */
56 int slave(int argc, char *argv[])
62 res = MSG_task_receive(&(task), "master_mailbox");
68 char *data = MSG_task_get_data(task);
69 if (data && !strcmp(data, "finalize")) {
70 MSG_task_destroy(task);
74 XBT_INFO("Executing task %f", MSG_task_get_compute_duration(task));
75 MSG_task_execute(task);
76 XBT_INFO("End of execution");
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_set_channel_number(0);
91 MSG_create_environment(platform_file);
94 //declaring user categories
95 TRACE_category_with_color ("compute", "1 0 0"); //compute is red
96 TRACE_category_with_color ("finalize", "0 1 0"); //finalize is green
98 { /* Application deployment */
99 MSG_function_register("master", master);
100 MSG_function_register("slave", slave);
101 MSG_launch_application(application_file);
105 XBT_INFO("Simulation time %g", MSG_get_clock());
111 int main(int argc, char *argv[])
113 MSG_error_t res = MSG_OK;
115 MSG_global_init(&argc, argv);
117 printf("Usage: %s platform_file deployment_file\n", argv[0]);
118 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
122 res = test_all(argv[1], argv[2]);