1 /* Copyright (c) 2007-2017. 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. */
6 #include "simgrid/msg.h"
7 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
9 static int computation_fun(int argc, char *argv[])
11 const char *pr_name = MSG_process_get_name(MSG_process_self());
12 const char *host_name = MSG_host_get_name(MSG_host_self());
14 msg_task_t task = MSG_task_create("Task", 1000000, 1000000, NULL);
16 double clock_sta = MSG_get_clock();
17 MSG_task_execute(task);
18 double clock_end = MSG_get_clock();
20 XBT_INFO("%s:%s task executed %g", host_name, pr_name, clock_end - clock_sta);
22 MSG_task_destroy(task);
27 static void launch_computation_worker(msg_host_t host)
29 const char *pr_name = "compute";
30 char **argv = xbt_new(char *, 2);
31 argv[0] = xbt_strdup(pr_name);
34 MSG_process_create_with_arguments(pr_name, computation_fun, NULL, host, 1, argv);
39 msg_process_t tx_proc;
43 static int communication_tx_fun(int argc, char *argv[])
45 xbt_assert(argc == 2);
46 const char *mbox = argv[1];
48 msg_task_t task = MSG_task_create("Task", 1000000, 1000000, NULL);
50 struct task_priv *priv = xbt_new(struct task_priv, 1);
51 priv->tx_proc = MSG_process_self();
52 priv->tx_host = MSG_host_self();
53 priv->clock_sta = MSG_get_clock();
55 MSG_task_set_data(task, priv);
57 MSG_task_send(task, mbox);
62 static int communication_rx_fun(int argc, char *argv[])
64 const char *pr_name = MSG_process_get_name(MSG_process_self());
65 const char *host_name = MSG_host_get_name(MSG_host_self());
66 xbt_assert(argc == 2);
67 const char *mbox = argv[1];
69 msg_task_t task = NULL;
70 MSG_task_recv(&task, mbox);
72 struct task_priv *priv = MSG_task_get_data(task);
73 double clock_end = MSG_get_clock();
75 XBT_INFO("%s:%s to %s:%s => %g sec", MSG_host_get_name(priv->tx_host), MSG_process_get_name(priv->tx_proc),
76 host_name, pr_name, clock_end - priv->clock_sta);
79 MSG_task_destroy(task);
84 static void launch_communication_worker(msg_host_t tx_host, msg_host_t rx_host)
86 char *mbox = bprintf("MBOX:%s-%s", MSG_host_get_name(tx_host), MSG_host_get_name(rx_host));
87 const char *pr_name_tx = "comm_tx";
89 char** argv = xbt_new(char*, 3);
90 argv[0] = xbt_strdup(pr_name_tx);
91 argv[1] = xbt_strdup(mbox);
94 MSG_process_create_with_arguments(pr_name_tx, communication_tx_fun, NULL, tx_host, 2, argv);
96 const char *pr_name_rx = "comm_rx";
97 argv = xbt_new(char *, 3);
98 argv[0] = xbt_strdup(pr_name_rx);
99 argv[1] = xbt_strdup(mbox);
102 MSG_process_create_with_arguments(pr_name_rx, communication_rx_fun, NULL, rx_host, 2, argv);
108 static int master_main(int argc, char *argv[])
110 msg_host_t pm0 = MSG_host_by_name("Fafard");
111 msg_host_t pm1 = MSG_host_by_name("Tremblay");
112 msg_host_t pm2 = MSG_host_by_name("Bourassa");
114 XBT_INFO("## Test 1 (started): check computation on normal PMs");
116 XBT_INFO("### Put a task on a PM");
117 launch_computation_worker(pm0);
118 MSG_process_sleep(2);
120 XBT_INFO("### Put two tasks on a PM");
121 launch_computation_worker(pm0);
122 launch_computation_worker(pm0);
123 MSG_process_sleep(2);
125 XBT_INFO("### Put a task on each PM");
126 launch_computation_worker(pm0);
127 launch_computation_worker(pm1);
128 MSG_process_sleep(2);
130 XBT_INFO("## Test 1 (ended)");
132 XBT_INFO("## Test 2 (started): check impact of running a task inside a VM (there is no degradation for the moment)");
134 XBT_INFO("### Put a VM on a PM, and put a task to the VM");
135 msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0");
137 launch_computation_worker((msg_host_t)vm0);
138 MSG_process_sleep(2);
141 XBT_INFO("## Test 2 (ended)");
143 XBT_INFO("## Test 3 (started): check impact of running a task collocated with a VM (there is no VM noise for the moment)");
145 XBT_INFO("### Put a VM on a PM, and put a task to the PM");
146 vm0 = MSG_vm_create_core(pm0, "VM0");
148 launch_computation_worker(pm0);
149 MSG_process_sleep(2);
152 XBT_INFO("## Test 3 (ended)");
154 XBT_INFO("## Test 4 (started): compare the cost of running two tasks inside two different VMs collocated or not (for"
155 " the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
157 XBT_INFO("### Put two VMs on a PM, and put a task to each VM");
158 vm0 = MSG_vm_create_core(pm0, "VM0");
159 msg_vm_t vm1 = MSG_vm_create_core(pm0, "VM1");
162 launch_computation_worker((msg_host_t)vm0);
163 launch_computation_worker((msg_host_t)vm1);
164 MSG_process_sleep(2);
168 XBT_INFO("### Put a VM on each PM, and put a task to each VM");
169 vm0 = MSG_vm_create_core(pm0, "VM0");
170 vm1 = MSG_vm_create_core(pm1, "VM1");
173 launch_computation_worker((msg_host_t)vm0);
174 launch_computation_worker((msg_host_t)vm1);
175 MSG_process_sleep(2);
178 XBT_INFO("## Test 4 (ended)");
180 XBT_INFO("## Test 5 (started): Analyse network impact");
181 XBT_INFO("### Make a connection between PM0 and PM1");
182 launch_communication_worker(pm0, pm1);
183 MSG_process_sleep(5);
185 XBT_INFO("### Make two connection between PM0 and PM1");
186 launch_communication_worker(pm0, pm1);
187 launch_communication_worker(pm0, pm1);
188 MSG_process_sleep(5);
190 XBT_INFO("### Make a connection between PM0 and VM0@PM0");
191 vm0 = MSG_vm_create_core(pm0, "VM0");
193 launch_communication_worker(pm0, (msg_host_t)vm0);
194 MSG_process_sleep(5);
197 XBT_INFO("### Make a connection between PM0 and VM0@PM1");
198 vm0 = MSG_vm_create_core(pm1, "VM0");
200 launch_communication_worker(pm0, (msg_host_t)vm0);
201 MSG_process_sleep(5);
204 XBT_INFO("### Make two connections between PM0 and VM0@PM1");
205 vm0 = MSG_vm_create_core(pm1, "VM0");
207 launch_communication_worker(pm0, (msg_host_t)vm0);
208 launch_communication_worker(pm0, (msg_host_t)vm0);
209 MSG_process_sleep(5);
212 XBT_INFO("### Make a connection between PM0 and VM0@PM1, and also make a connection between PM0 and PM1");
213 vm0 = MSG_vm_create_core(pm1, "VM0");
215 launch_communication_worker(pm0, (msg_host_t)vm0);
216 launch_communication_worker(pm0, pm1);
217 MSG_process_sleep(5);
220 XBT_INFO("### Make a connection between VM0@PM0 and PM1@PM1, and also make a connection between VM0@PM0 and VM1@PM1");
221 vm0 = MSG_vm_create_core(pm0, "VM0");
222 vm1 = MSG_vm_create_core(pm1, "VM1");
225 launch_communication_worker((msg_host_t)vm0, (msg_host_t)vm1);
226 launch_communication_worker((msg_host_t)vm0, (msg_host_t)vm1);
227 MSG_process_sleep(5);
231 XBT_INFO("## Test 5 (ended)");
233 XBT_INFO("## Test 6 (started): Check migration impact (not yet implemented neither on the CPU resource nor on the"
235 XBT_INFO("### Relocate VM0 between PM0 and PM1");
236 vm0 = MSG_vm_create_core(pm0, "VM0");
237 s_vm_params_t params;
238 memset(¶ms, 0, sizeof(params));
239 params.ramsize = 1L * 1024 * 1024 * 1024; // 1Gbytes
240 MSG_vm_set_params(vm0, ¶ms);
243 launch_communication_worker((msg_host_t)vm0, pm2);
244 MSG_process_sleep(0.01);
245 MSG_vm_migrate(vm0, pm1);
246 MSG_process_sleep(0.01);
247 MSG_vm_migrate(vm0, pm0);
248 MSG_process_sleep(5);
250 XBT_INFO("## Test 6 (ended)");
255 static void launch_master(msg_host_t host)
257 const char *pr_name = "master_";
258 char **argv = xbt_new(char *, 2);
259 argv[0] = xbt_strdup(pr_name);
262 MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
265 int main(int argc, char *argv[])
267 /* Get the arguments */
268 MSG_init(&argc, argv);
270 /* load the platform file */
271 const char* platform = "../../platforms/small_platform.xml";
274 MSG_create_environment(platform);
276 msg_host_t pm0 = MSG_host_by_name("Fafard");
279 int res = MSG_main();
280 XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
282 return !(res == MSG_OK);