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,
15 "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,
20 const char *application_file);
22 /** Emitter function */
23 int master(int argc, char *argv[])
25 long number_of_tasks = atol(argv[1]);
26 long slaves_count = atol(argv[4]);
29 for (i = 0; i < number_of_tasks; i++) {
32 //creating task and setting its category
34 task = MSG_task_create("task_compute", 10000000, 0, NULL);
35 TRACE_msg_set_task_category(task, "compute");
37 task = MSG_task_create("task_request", 10, 10, NULL);
38 TRACE_msg_set_task_category(task, "request");
40 task = MSG_task_create("task_data", 10, 10000000, NULL);
41 TRACE_msg_set_task_category(task, "data");
43 MSG_task_send(task, "master_mailbox");
46 for (i = 0; i < slaves_count; i++) {
47 m_task_t finalize = MSG_task_create("finalize", 0, 1000, 0);
48 TRACE_msg_set_task_category(finalize, "finalize");
49 MSG_task_send(finalize, "master_mailbox");
55 /** Receiver function */
56 int slave(int argc, char *argv[])
62 res = MSG_task_receive(&(task), "master_mailbox");
64 if (!strcmp(MSG_task_get_name(task), "finalize")) {
65 MSG_task_destroy(task);
69 MSG_task_execute(task);
70 MSG_task_destroy(task);
77 MSG_error_t test_all(const char *platform_file,
78 const char *application_file)
80 MSG_error_t res = MSG_OK;
82 { /* Simulation setting */
83 MSG_set_channel_number(0);
84 MSG_create_environment(platform_file);
86 { /* Application deployment */
87 MSG_function_register("master", master);
88 MSG_function_register("slave", slave);
89 MSG_launch_application(application_file);
93 INFO1("Simulation time %g", MSG_get_clock());
99 int main(int argc, char *argv[])
101 MSG_error_t res = MSG_OK;
103 MSG_global_init(&argc, argv);
105 printf("Usage: %s platform_file deployment_file\n", argv[0]);
106 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
110 //declaring user categories with RGB colors
111 TRACE_category_with_color ("compute", "1 0 0"); //red
112 TRACE_category_with_color ("request", "0 1 0"); //green
113 TRACE_category_with_color ("data", "0 0 1"); //blue
114 TRACE_category_with_color ("finalize", "0 0 0");//black
116 res = test_all(argv[1], argv[2]);