1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "xbt/sysdep.h" /* calloc, printf */
11 /* Create a log channel to have nice outputs. */
13 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"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, const char *application_file);
20 /** Emitter function */
21 int master(int argc, char *argv[])
23 long number_of_tasks = atol(argv[1]);
24 long slaves_count = atol(argv[4]);
27 for (i = 0; i < number_of_tasks; i++) {
30 //creating task and setting its category
32 task = MSG_task_create ("task_compute", 10000000, 0, NULL);
33 TRACE_msg_set_task_category (task, "compute");
35 task = MSG_task_create ("task_request", 10, 10, NULL);
36 TRACE_msg_set_task_category (task, "request");
38 task = MSG_task_create ("task_data", 10, 10000000, NULL);
39 TRACE_msg_set_task_category (task, "data");
41 MSG_task_send(task, "master_mailbox");
44 for (i = 0; i < slaves_count; i++) {
45 m_task_t finalize = MSG_task_create ("finalize", 0, 1000, 0);
46 TRACE_msg_set_task_category(finalize, "finalize");
47 MSG_task_send(finalize, "master_mailbox");
53 /** Receiver function */
54 int slave(int argc, char *argv[])
60 res = MSG_task_receive(&(task), "master_mailbox");
62 if (!strcmp(MSG_task_get_name(task),"finalize")) {
63 MSG_task_destroy(task);
67 MSG_task_execute(task);
68 MSG_task_destroy(task);
75 MSG_error_t test_all(const char *platform_file,
76 const char *application_file)
78 MSG_error_t res = MSG_OK;
80 { /* Simulation setting */
81 MSG_set_channel_number(0);
82 MSG_create_environment(platform_file);
84 { /* Application deployment */
85 MSG_function_register("master", master);
86 MSG_function_register("slave", slave);
87 MSG_launch_application(application_file);
91 INFO1("Simulation time %g",MSG_get_clock());
97 int main(int argc, char *argv[])
99 MSG_error_t res = MSG_OK;
101 MSG_global_init(&argc,argv);
103 printf ("Usage: %s platform_file deployment_file\n",argv[0]);
104 printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
108 //starting the simulation tracing
111 //declaring user categories
112 TRACE_category ("compute");
113 TRACE_category ("request");
114 TRACE_category ("data");
115 TRACE_category ("finalize");
117 res = test_all(argv[1],argv[2]);
120 //ending the simulation tracing