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 /** Emitter function */
17 int master(int argc, char *argv[])
19 long number_of_tasks = atol(argv[1]);
20 double task_comp_size = atof(argv[2]);
21 double task_comm_size = atof(argv[3]);
22 long slaves_count = atol(argv[4]);
23 XBT_INFO("master %ld %f %f %ld", number_of_tasks, task_comp_size,
24 task_comm_size, slaves_count);
27 for (i = 0; i < number_of_tasks; i++) {
29 snprintf (task_name, 100, "task-%d", i);
31 task = MSG_task_create(task_name, task_comp_size, task_comm_size, NULL);
33 //setting the category of task to "compute"
34 //the category of a task must be defined before it is sent or executed
35 TRACE_msg_set_task_category(task, "compute");
36 MSG_task_send(task, "master_mailbox");
39 for (i = 0; i < slaves_count; i++) {
41 snprintf (task_name, 100, "task-%d", i);
42 m_task_t finalize = MSG_task_create(task_name, 0, 0, xbt_strdup("finalize"));
43 TRACE_msg_set_task_category(finalize, "finalize");
44 MSG_task_send(finalize, "master_mailbox");
50 /** Receiver function */
51 int slave(int argc, char *argv[])
57 MSG_task_receive(&(task), "master_mailbox");
59 char *data = MSG_task_get_data(task);
60 if (data && !strcmp(data, "finalize")) {
62 MSG_task_destroy(task);
66 XBT_INFO("Executing task %f", MSG_task_get_compute_duration(task));
67 MSG_task_execute(task);
68 XBT_INFO("End of execution");
69 MSG_task_destroy(task);
76 int main(int argc, char *argv[])
78 MSG_global_init(&argc, argv);
80 printf("Usage: %s platform_file deployment_file\n", argv[0]);
84 char *platform_file = argv[1];
85 char *deployment_file = argv[2];
86 MSG_create_environment(platform_file);
88 TRACE_category_with_color ("compute", "1 0 0"); //compute is red
89 TRACE_category_with_color ("finalize", "0 1 0"); //finalize is green
91 MSG_function_register("master", master);
92 MSG_function_register("slave", slave);
93 MSG_launch_application(deployment_file);