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 long slaves_count = atol(argv[4]);
32 for (i = 0; i < number_of_tasks; i++) {
34 task = MSG_task_create("task_compute", p, c, NULL);
35 TRACE_msg_set_task_category(task, "compute");
36 MSG_task_send(task, "master_mailbox");
38 task = MSG_task_create("task_request", p, c, NULL);
39 TRACE_msg_set_task_category(task, "request");
40 MSG_task_send(task, "master_mailbox");
42 task = MSG_task_create("task_data", p, c, NULL);
43 TRACE_msg_set_task_category(task, "data");
44 MSG_task_send(task, "master_mailbox");
47 for (i = 0; i < slaves_count; i++) {
48 m_task_t finalize = MSG_task_create("finalize", 0, 1000, 0);
49 TRACE_msg_set_task_category(finalize, "finalize");
50 MSG_task_send(finalize, "master_mailbox");
56 /** Receiver function */
57 int slave(int argc, char *argv[])
63 res = MSG_task_receive(&(task), "master_mailbox");
65 if (!strcmp(MSG_task_get_name(task), "finalize")) {
66 MSG_task_destroy(task);
70 MSG_task_execute(task);
71 MSG_task_destroy(task);
78 MSG_error_t test_all(const char *platform_file,
79 const char *application_file)
81 MSG_error_t res = MSG_OK;
83 { /* Simulation setting */
84 MSG_set_channel_number(0);
85 MSG_create_environment(platform_file);
88 //--cfg=tracing/msg/volume
89 // - the communication volume among processes expects that:
90 // - the processes involved have a category
91 // - the sent tasks have a category
93 //declaring user categories (for tasks)
94 TRACE_category_with_color ("compute", "1 0 0"); //red
95 TRACE_category_with_color ("request", "0 1 0"); //green
96 TRACE_category_with_color ("data", "0 0 1"); //blue
97 TRACE_category_with_color ("finalize", "0 0 0");//black
99 { /* Application deployment */
100 MSG_function_register("master", master);
101 MSG_function_register("slave", slave);
102 MSG_launch_application(application_file);
106 INFO1("Simulation time %g", MSG_get_clock());
112 int main(int argc, char *argv[])
114 MSG_error_t res = MSG_OK;
116 MSG_global_init(&argc, argv);
118 printf("Usage: %s platform_file deployment_file\n", argv[0]);
119 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
123 res = test_all(argv[1], argv[2]);