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,"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, const char *application_file);
21 /** Emitter function */
22 int master(int argc, char *argv[])
24 //defining the category of the master process
25 TRACE_msg_set_process_category (MSG_process_self(), "master");
27 long number_of_tasks = atol(argv[1]);
28 long slaves_count = atol(argv[4]);
33 for (i = 0; i < number_of_tasks; i++){
35 task = MSG_task_create ("task_compute", p, c, NULL);
36 TRACE_msg_set_task_category (task, "compute");
37 MSG_task_send(task, "master_mailbox");
39 task = MSG_task_create ("task_request", p, c, NULL);
40 TRACE_msg_set_task_category (task, "request");
41 MSG_task_send(task, "master_mailbox");
43 task = MSG_task_create ("task_data", p, c, NULL);
44 TRACE_msg_set_task_category (task, "data");
45 MSG_task_send(task, "master_mailbox");
48 for (i = 0; i < slaves_count; i++) {
49 m_task_t finalize = MSG_task_create ("finalize", 0, 1000, 0);
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[])
60 //defining the category of this slave process
61 TRACE_msg_set_process_category (MSG_process_self(), "slave");
67 res = MSG_task_receive(&(task), "master_mailbox");
69 if (!strcmp(MSG_task_get_name(task),"finalize")) {
70 MSG_task_destroy(task);
74 MSG_task_execute(task);
75 MSG_task_destroy(task);
82 MSG_error_t test_all(const char *platform_file,
83 const char *application_file)
85 MSG_error_t res = MSG_OK;
87 { /* Simulation setting */
88 MSG_set_channel_number(0);
89 MSG_create_environment(platform_file);
91 { /* Application deployment */
92 MSG_function_register("master", master);
93 MSG_function_register("slave", slave);
94 MSG_launch_application(application_file);
98 INFO1("Simulation time %g",MSG_get_clock());
104 int main(int argc, char *argv[])
106 MSG_error_t res = MSG_OK;
108 //starting the simulation tracing with the TRACE_VOLUME mask
109 // - the communication volume among processes expects that:
110 // - the processes involved have a category
111 // - the tasks sent have a category
112 TRACE_start_with_mask ("volume.trace", TRACE_VOLUME);
114 //declaring user categories (for tasks)
115 TRACE_category ("compute");
116 TRACE_category ("request");
117 TRACE_category ("data");
118 TRACE_category ("finalize");
120 //declaring user categories (for processes)
121 TRACE_category ("master");
122 TRACE_category ("slave");
124 MSG_global_init(&argc,argv);
126 printf ("Usage: %s platform_file deployment_file\n",argv[0]);
127 printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
130 res = test_all(argv[1],argv[2]);
133 //ending the simulation tracing