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 double task_comp_size = atof(argv[2]);
25 double task_comm_size = atof(argv[3]);
26 long slaves_count = atol(argv[4]);
28 //setting the variable "is_master" (previously declared) to value 1
29 TRACE_host_variable_set ("is_master", 1);
31 TRACE_mark ("msmark", "start_send_tasks");
33 for (i = 0; i < number_of_tasks; i++) {
35 task = MSG_task_create("task", task_comp_size, task_comm_size, NULL);
37 //setting the variable "task_creation" to value i
38 TRACE_host_variable_set ("task_creation", i);
40 //setting the category of task to "compute"
41 //the category of a task must be defined before it is sent or executed
42 TRACE_msg_set_task_category (task, "compute");
43 MSG_task_send(task, "master_mailbox");
45 TRACE_mark ("msmark", "finish_send_tasks");
47 for (i = 0; i < slaves_count; i++) {
48 m_task_t finalize = MSG_task_create ("finalize", 0, 0, 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[])
62 TRACE_host_variable_set ("is_slave", 1);
64 res = MSG_task_receive(&(task), "master_mailbox");
66 if (!strcmp(MSG_task_get_name(task),"finalize")) {
67 MSG_task_destroy(task);
71 //adding the value returned by MSG_task_get_compute_duration(task)
72 //to the variable "task_computation"
73 TRACE_host_variable_add ("task_computation",
74 MSG_task_get_compute_duration(task));
75 MSG_task_execute(task);
76 MSG_task_destroy(task);
83 MSG_error_t test_all(const char *platform_file,
84 const char *application_file)
86 MSG_error_t res = MSG_OK;
88 { /* Simulation setting */
89 MSG_set_channel_number(0);
90 MSG_create_environment(platform_file);
92 { /* Application deployment */
93 MSG_function_register("master", master);
94 MSG_function_register("slave", slave);
95 MSG_launch_application(application_file);
99 INFO1("Simulation time %g",MSG_get_clock());
105 int main(int argc, char *argv[])
107 MSG_error_t res = MSG_OK;
109 MSG_global_init(&argc,argv);
111 printf ("Usage: %s platform_file deployment_file\n",argv[0]);
112 printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
116 //starting the simulation tracing
119 //declaring user variables
120 TRACE_host_variable_declare ("is_slave");
121 TRACE_host_variable_declare ("is_master");
122 TRACE_host_variable_declare ("task_creation");
123 TRACE_host_variable_declare ("task_computation");
125 //declaring user markers
126 TRACE_declare_mark ("msmark");
128 //declaring user categories
129 TRACE_category ("compute");
130 TRACE_category ("finalize");
132 res = test_all(argv[1],argv[2]);
135 //ending the simulation tracing