1 /* Copyright (c) 2007-2012. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "xbt/sysdep.h" /* calloc, printf */
10 /* Create a log channel to have nice outputs. */
12 #include "xbt/asserts.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
14 "Messages specific for this msg example");
17 int computation_fun(int argc, char *argv[])
19 const char *pr_name = MSG_process_get_name(MSG_process_self());
20 const char *host_name = MSG_host_get_name(MSG_host_self());
22 msg_task_t task = MSG_task_create("Task", 1000000, 1000000, NULL);
24 double clock_sta = MSG_get_clock();
25 MSG_task_execute(task);
26 double clock_end = MSG_get_clock();
28 XBT_INFO("%s:%s task executed %g", host_name, pr_name, clock_end - clock_sta);
30 MSG_task_destroy(task);
35 void launch_computation_worker(msg_host_t host)
37 const char *pr_name = "compute";
38 char **argv = xbt_new(char *, 2);
39 argv[0] = xbt_strdup(pr_name);
42 MSG_process_create_with_arguments(pr_name, computation_fun, NULL, host, 1, argv);
47 msg_process_t tx_proc;
51 int communication_tx_fun(int argc, char *argv[])
53 xbt_assert(argc == 2);
54 const char *mbox = argv[1];
56 msg_task_t task = MSG_task_create("Task", 1000000, 1000000, NULL);
58 struct task_priv *priv = xbt_new(struct task_priv, 1);
59 priv->tx_proc = MSG_process_self();
60 priv->tx_host = MSG_host_self();
61 priv->clock_sta = MSG_get_clock();
63 MSG_task_set_data(task, priv);
65 MSG_task_send(task, mbox);
70 int communication_rx_fun(int argc, char *argv[])
72 const char *pr_name = MSG_process_get_name(MSG_process_self());
73 const char *host_name = MSG_host_get_name(MSG_host_self());
74 xbt_assert(argc == 2);
75 const char *mbox = argv[1];
77 msg_task_t task = NULL;
78 MSG_task_recv(&task, mbox);
80 struct task_priv *priv = MSG_task_get_data(task);
81 double clock_end = MSG_get_clock();
83 XBT_INFO("%s:%s to %s:%s => %g sec",
84 MSG_host_get_name(priv->tx_host),
85 MSG_process_get_name(priv->tx_proc),
86 host_name, pr_name, clock_end - priv->clock_sta);
88 MSG_task_destroy(task);
93 void launch_communication_worker(msg_host_t tx_host, msg_host_t rx_host)
95 char *mbox = bprintf("MBOX:%s-%s",
96 MSG_host_get_name(tx_host),
97 MSG_host_get_name(rx_host));
102 argv = xbt_new(char *, 3);
103 argv[0] = xbt_strdup(pr_name);
104 argv[1] = xbt_strdup(mbox);
107 MSG_process_create_with_arguments(pr_name, communication_tx_fun, NULL, tx_host, 2, argv);
110 argv = xbt_new(char *, 3);
111 argv[0] = xbt_strdup(pr_name);
112 argv[1] = xbt_strdup(mbox);
115 MSG_process_create_with_arguments(pr_name, communication_rx_fun, NULL, rx_host, 2, argv);
121 int master_main(int argc, char *argv[])
123 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
124 msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
125 msg_host_t pm1 = xbt_dynar_get_as(hosts_dynar, 1, msg_host_t);
126 msg_host_t pm2 = xbt_dynar_get_as(hosts_dynar, 2, msg_host_t);
130 XBT_INFO("## Test 1 (started): check computation on normal PMs");
132 XBT_INFO("### Put a task on a PM");
133 launch_computation_worker(pm0);
134 MSG_process_sleep(2);
136 XBT_INFO("### Put two tasks on a PM");
137 launch_computation_worker(pm0);
138 launch_computation_worker(pm0);
139 MSG_process_sleep(2);
141 XBT_INFO("### Put a task on each PM");
142 launch_computation_worker(pm0);
143 launch_computation_worker(pm1);
144 MSG_process_sleep(2);
146 XBT_INFO("## Test 1 (ended)");
149 XBT_INFO("## Test 2 (started): check impact of running a task inside a VM (there is no degradation for the moment)");
151 XBT_INFO("### Put a VM on a PM, and put a task to the VM");
152 vm0 = MSG_vm_create_core(pm0, "VM0");
154 launch_computation_worker(vm0);
155 MSG_process_sleep(2);
158 XBT_INFO("## Test 2 (ended)");
161 XBT_INFO("## Test 3 (started): check impact of running a task collocated with a VM (there is no VM noise for the moment)");
163 XBT_INFO("### Put a VM on a PM, and put a task to the PM");
164 vm0 = MSG_vm_create_core(pm0, "VM0");
166 launch_computation_worker(pm0);
167 MSG_process_sleep(2);
170 XBT_INFO("## Test 3 (ended)");
173 XBT_INFO("## Test 4 (started): compare the cost of running two tasks inside two different VMs collocated or not (for the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
175 XBT_INFO("### Put two VMs on a PM, and put a task to each VM");
176 vm0 = MSG_vm_create_core(pm0, "VM0");
177 vm1 = MSG_vm_create_core(pm0, "VM1");
180 launch_computation_worker(vm0);
181 launch_computation_worker(vm1);
182 MSG_process_sleep(2);
186 XBT_INFO("### Put a VM on each PM, and put a task to each VM");
187 vm0 = MSG_vm_create_core(pm0, "VM0");
188 vm1 = MSG_vm_create_core(pm1, "VM1");
191 launch_computation_worker(vm0);
192 launch_computation_worker(vm1);
193 MSG_process_sleep(2);
196 XBT_INFO("## Test 4 (ended)");
199 XBT_INFO("## Test 5 (started): Analyse network impact");
200 XBT_INFO("### Make a connection between PM0 and PM1");
201 launch_communication_worker(pm0, pm1);
202 MSG_process_sleep(5);
204 XBT_INFO("### Make two connection between PM0 and PM1");
205 launch_communication_worker(pm0, pm1);
206 launch_communication_worker(pm0, pm1);
207 MSG_process_sleep(5);
209 XBT_INFO("### Make a connection between PM0 and VM0@PM0");
210 vm0 = MSG_vm_create_core(pm0, "VM0");
212 launch_communication_worker(pm0, vm0);
213 MSG_process_sleep(5);
216 XBT_INFO("### Make a connection between PM0 and VM0@PM1");
217 vm0 = MSG_vm_create_core(pm1, "VM0");
219 launch_communication_worker(pm0, vm0);
220 MSG_process_sleep(5);
223 XBT_INFO("### Make two connections between PM0 and VM0@PM1");
224 vm0 = MSG_vm_create_core(pm1, "VM0");
226 launch_communication_worker(pm0, vm0);
227 launch_communication_worker(pm0, vm0);
228 MSG_process_sleep(5);
231 XBT_INFO("### Make a connection between PM0 and VM0@PM1, and also make a connection between PM0 and PM1");
232 vm0 = MSG_vm_create_core(pm1, "VM0");
234 launch_communication_worker(pm0, vm0);
235 launch_communication_worker(pm0, pm1);
236 MSG_process_sleep(5);
239 XBT_INFO("### Make a connection between VM0@PM0 and PM1@PM1, and also make a connection between VM0@PM0 and VM1@PM1");
240 vm0 = MSG_vm_create_core(pm0, "VM0");
241 vm1 = MSG_vm_create_core(pm1, "VM1");
244 launch_communication_worker(vm0, vm1);
245 launch_communication_worker(vm0, vm1);
246 MSG_process_sleep(5);
250 XBT_INFO("## Test 5 (ended)");
253 XBT_INFO("## Test 6 (started): Check migration impact (not yet implemented neither on the CPU resource nor on the network one");
254 XBT_INFO("### Relocate VM0 between PM0 and PM1");
255 vm0 = MSG_vm_create_core(pm0, "VM0");
257 launch_communication_worker(vm0, pm2);
258 MSG_process_sleep(0.01);
259 MSG_vm_migrate(vm0, pm1);
260 MSG_process_sleep(0.01);
261 MSG_vm_migrate(vm0, pm0);
262 MSG_process_sleep(5);
264 XBT_INFO("## Test 6 (ended)");
269 void launch_master(msg_host_t host)
271 const char *pr_name = "master_";
272 char **argv = xbt_new(char *, 2);
273 argv[0] = xbt_strdup(pr_name);
276 msg_process_t pr = MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
280 int main(int argc, char *argv[])
282 /* Get the arguments */
283 MSG_init(&argc, argv);
285 /* load the platform file */
286 MSG_create_environment(argv[1]);
288 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
289 msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
292 int res = MSG_main();
293 XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
296 return !(res == MSG_OK);