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 long number_of_tasks = atol(argv[1]);
25 long slaves_count = atol(argv[4]);
28 for (i = 0; i < number_of_tasks; i++) {
31 //creating task and setting its category
33 task = MSG_task_create ("task_compute", 10000000, 0, NULL);
34 TRACE_msg_set_task_category (task, "compute");
36 task = MSG_task_create ("task_request", 10, 10, NULL);
37 TRACE_msg_set_task_category (task, "request");
39 task = MSG_task_create ("task_data", 10, 10000000, NULL);
40 TRACE_msg_set_task_category (task, "data");
42 MSG_task_send(task, "master_mailbox");
45 for (i = 0; i < slaves_count; i++) {
46 m_task_t finalize = MSG_task_create ("finalize", 0, 1000, 0);
47 TRACE_msg_set_task_category(finalize, "finalize");
48 MSG_task_send(finalize, "master_mailbox");
54 /** Receiver function */
55 int slave(int argc, char *argv[])
61 res = MSG_task_receive(&(task), "master_mailbox");
63 if (!strcmp(MSG_task_get_name(task),"finalize")) {
64 MSG_task_destroy(task);
68 MSG_task_execute(task);
69 MSG_task_destroy(task);
76 MSG_error_t test_all(const char *platform_file,
77 const char *application_file)
79 MSG_error_t res = MSG_OK;
81 { /* Simulation setting */
82 MSG_set_channel_number(0);
83 MSG_create_environment(platform_file);
85 { /* Application deployment */
86 MSG_function_register("master", master);
87 MSG_function_register("slave", slave);
88 MSG_launch_application(application_file);
92 INFO1("Simulation time %g",MSG_get_clock());
98 int main(int argc, char *argv[])
100 MSG_error_t res = MSG_OK;
102 //starting the simulation tracing
103 TRACE_start ("categories.trace");
105 //declaring user categories
106 TRACE_category ("compute");
107 TRACE_category ("request");
108 TRACE_category ("data");
109 TRACE_category ("finalize");
111 MSG_global_init(&argc,argv);
113 printf ("Usage: %s platform_file deployment_file\n",argv[0]);
114 printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
117 res = test_all(argv[1],argv[2]);
120 //ending the simulation tracing