1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2 * Copyright (c) 2012. Maximiliano Geier.
3 * 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 "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
11 #include "xbt/sysdep.h" /* calloc */
13 /* Create a log channel to have nice outputs. */
15 #include "xbt/asserts.h"
17 /** @addtogroup MSG_examples
19 * - <b>kadeploy/kadeploy.c: Kadeploy implementation</b>.
23 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kadeploy,
24 "Messages specific for kadeploy");
30 /* Random iterator for xbt_dynar */
31 typedef struct xbt_dynar_iterator_struct {
33 xbt_dynar_t indices_list;
36 unsigned int (*criteria_fn)(void* it);
37 } *xbt_dynar_iterator_t;
38 typedef struct xbt_dynar_iterator_struct xbt_dynar_iterator_s;
41 xbt_dynar_iterator_t xbt_dynar_iterator_new(xbt_dynar_t list, unsigned int (*criteria_fn)(void*));
42 void *xbt_dynar_iterator_next(xbt_dynar_iterator_t it);
43 void xbt_dynar_iterator_delete(xbt_dynar_iterator_t it);
44 unsigned int xbt_dynar_iterator_forward_criteria(void *p);
46 int broadcaster(int argc, char *argv[]);
47 int peer(int argc, char *argv[]);
49 void check_hosts(const int count, char **list);
50 xbt_dynar_t build_hostlist_from_argv(int argc, char *argv[]);
51 void build_chain(xbt_dynar_t host_list);
53 int peer_wait_for_init();
55 msg_error_t test_all(const char *platform_file,
56 const char *application_file);
58 double task_comm_size_lat = 10e0;
59 double task_comm_size_bw = 10e8;
61 /* Allocates and initializes a new xbt_dynar iterator for list, using criteria_fn as iteration criteria
62 criteria_fn: given an iterator, it must update the iterator and give the next element's index,
63 less than 0 otherwise*/
64 xbt_dynar_iterator_t xbt_dynar_iterator_new(xbt_dynar_t list, unsigned int (*criteria_fn)(void*))
66 xbt_dynar_iterator_t it = xbt_new(xbt_dynar_iterator_s, 1);
69 it->length = xbt_dynar_length(list);
70 it->indices_list = xbt_dynar_new(sizeof(unsigned int), NULL);
71 it->criteria_fn = criteria_fn;
75 /* Returns the next element iterated by iterator it, NULL if there are no more elements */
76 void *xbt_dynar_iterator_next(xbt_dynar_iterator_t it)
78 unsigned int next = it->criteria_fn((xbt_dynar_iterator_t)it);
79 XBT_INFO("%d current\n", next);
83 xbt_dynar_push(it->indices_list, &next);
84 return xbt_dynar_get_ptr(it->list, next);
88 void xbt_dynar_iterator_delete(xbt_dynar_iterator_t it)
90 xbt_dynar_free_container(&(it->indices_list));
94 unsigned int xbt_dynar_iterator_forward_criteria(void *p)
96 xbt_dynar_iterator_t it = (xbt_dynar_iterator_t)p;
98 if (it->current == -1) {
99 /* iterator initialization */
102 if (it->current < it->length) {
110 xbt_dynar_t build_hostlist_from_argv(int argc, char *argv[])
112 xbt_dynar_t host_list = xbt_dynar_new(sizeof(char*), NULL);
116 for (; i < argc; i++) {
117 XBT_INFO("host%d = %s", i, argv[i]);
118 h = MSG_get_host_by_name(argv[i]);
120 XBT_INFO("Unknown host %s. Stopping Now! ", argv[i]);
123 xbt_dynar_push(host_list, &(argv[i]));
129 void delete_hostlist(xbt_dynar_t h)
131 xbt_dynar_free_container(&h);
134 void build_chain(xbt_dynar_t host_list)
136 xbt_dynar_iterator_t it = xbt_dynar_iterator_new(host_list, xbt_dynar_iterator_forward_criteria);
139 for (cur = (char**)xbt_dynar_iterator_next(it); cur != NULL; cur = (char**)xbt_dynar_iterator_next(it)) {
140 XBT_INFO("iterating host = %s", *cur);
144 /*void setup_chain_criteria(chain_criteria_t c, char *(*fn)(void))
149 void build_chain(const int hostcount, char **hostlist)
152 for (i = 0; i < hostcount; i++) {
157 /** Emitter function */
158 int broadcaster(int argc, char *argv[])
161 xbt_dynar_t host_list = NULL;
162 msg_task_t task_la = NULL;
163 msg_task_t task_bw = NULL;
164 char sprintf_buffer_la[64];
165 char sprintf_buffer_bw[64];
167 XBT_INFO("broadcaster");
169 /* Check that every host in the command line actually exists and add it to a dynamic array */
170 host_list = build_hostlist_from_argv(argc, argv);
172 build_chain(host_list);
175 /*time = MSG_get_clock();
176 sprintf(sprintf_buffer_la, "latency task");
178 MSG_task_create(sprintf_buffer_la, 0.0, task_comm_size_lat, NULL);
179 task_la->data = xbt_new(double, 1);
180 *(double *) task_la->data = time;
181 XBT_INFO("task_la->data = %le", *((double *) task_la->data));
182 MSG_task_send(task_la, argv[1]);*/
185 /*time = MSG_get_clock();
186 sprintf(sprintf_buffer_bw, "bandwidth task");
188 MSG_task_create(sprintf_buffer_bw, 0.0, task_comm_size_bw, NULL);
189 task_bw->data = xbt_new(double, 1);
190 *(double *) task_bw->data = time;
191 XBT_INFO("task_bw->data = %le", *((double *) task_bw->data));
192 MSG_task_send(task_bw, argv[1]);
195 } /* end_of_client */
197 int peer_wait_for_init()
203 int peer(int argc, char *argv[])
205 double time, time1, sender_time;
206 msg_task_t task_la = NULL;
207 msg_task_t task_bw = NULL;
209 double communication_time = 0;
213 time = MSG_get_clock();
215 a = peer_wait_for_init();
217 /*a = MSG_task_receive(&task_la,MSG_host_get_name(MSG_host_self()));
219 time1 = MSG_get_clock();
220 sender_time = *((double *) (task_la->data));
222 communication_time = time1 - time;
223 XBT_INFO("Task received : %s", task_la->name);
224 xbt_free(task_la->data);
225 MSG_task_destroy(task_la);
226 XBT_INFO("Communic. time %le", communication_time);
227 XBT_INFO("--- la %f ----", communication_time);
229 xbt_die("Unexpected behavior");
234 /*a = MSG_task_receive(&task_bw,MSG_host_get_name(MSG_host_self()));
236 time1 = MSG_get_clock();
237 sender_time = *((double *) (task_bw->data));
239 communication_time = time1 - time;
240 XBT_INFO("Task received : %s", task_bw->name);
241 xbt_free(task_bw->data);
242 MSG_task_destroy(task_bw);
243 XBT_INFO("Communic. time %le", communication_time);
244 XBT_INFO("--- bw %f ----", task_comm_size_bw / communication_time);
246 xbt_die("Unexpected behavior");
251 } /* end_of_receiver */
255 msg_error_t test_all(const char *platform_file,
256 const char *application_file)
259 msg_error_t res = MSG_OK;
263 XBT_INFO("test_all");
265 /* Simulation setting */
266 MSG_create_environment(platform_file);
268 /* Application deployment */
269 MSG_function_register("broadcaster", broadcaster);
270 MSG_function_register("peer", peer);
272 MSG_launch_application(application_file);
277 } /* end_of_test_all */
281 int main(int argc, char *argv[])
283 msg_error_t res = MSG_OK;
286 unsigned int prev_exponent_format =
287 _set_output_format(_TWO_DIGIT_EXPONENT);
290 MSG_init(&argc, argv);
294 XBT_CRITICAL("Usage: %s platform_file deployment_file <model>\n",
297 ("example: %s msg_platform.xml msg_deployment.xml KCCFLN05_Vegas\n",
302 /* Options for the workstation/model:
304 KCCFLN05 => for maxmin
305 KCCFLN05_proportional => for proportional (Vegas)
306 KCCFLN05_Vegas => for TCP Vegas
307 KCCFLN05_Reno => for TCP Reno
309 //MSG_config("workstation/model", argv[3]);
311 res = test_all(argv[1], argv[2]);
313 XBT_INFO("Total simulation time: %le", MSG_get_clock());
318 _set_output_format(prev_exponent_format);