1 /* Copyright (c) 2007-2015. 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 "simgrid/msg.h"
10 #include "xbt/sysdep.h" /* calloc, printf */
12 /* Create a log channel to have nice outputs. */
14 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
16 "Messages specific for this msg example");
20 * ./examples/msg/cloud/scale ../examples/platforms/g5k.xml
22 * 1. valgrind --tool=callgrind ./examples/msg/cloud/scale ../examples/platforms/g5k.xml
26 static double time_precise(void) {
28 int ret = gettimeofday(&tv, NULL);
30 xbt_die("gettimeofday");
32 double now = (double) tv.tv_sec + tv.tv_usec * 0.001 * 0.001;
37 static int computation_fun(int argc, char *argv[]) {
39 // double clock_sta = time_precise();
41 msg_task_t task = MSG_task_create("Task", 10000000, 0, NULL);
42 MSG_task_execute(task);
43 MSG_task_destroy(task);
45 // double clock_end = time_precise();
47 // XBT_INFO("%f", clock_end - clock_sta);
54 static void launch_computation_worker(msg_host_t host) {
55 MSG_process_create("compute", computation_fun, NULL, host);
58 static int master_main(int argc, char *argv[])
60 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
65 msg_host_t *pm = xbt_new(msg_host_t, npm);
66 msg_vm_t *vm = xbt_new(msg_vm_t, nvm);
69 for (i = 0; i < npm; i++) {
70 pm[i] = xbt_dynar_get_as(hosts_dynar, i, msg_host_t);
73 for (i = 0; i < nvm; i++) {
74 int pm_index = i % npm;
75 char *vm_name = bprintf("vm%d", i);
76 vm[i] = MSG_vm_create_core(pm[pm_index], vm_name);
79 launch_computation_worker(vm[i]);
85 XBT_INFO("## Test (start)");
87 for (i = 0; i < 10; i++) {
88 double clock_sta = time_precise();
90 double clock_end = time_precise();
91 XBT_INFO("duration %f", clock_end - clock_sta);
95 for (i = 0; i < nvm; i++) {
96 MSG_vm_destroy(vm[i]);
99 XBT_INFO("## Test (ended)");
104 static void launch_master(msg_host_t host)
106 const char *pr_name = "master_";
107 char **argv = xbt_new(char *, 2);
108 argv[0] = xbt_strdup(pr_name);
111 MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
115 int main(int argc, char *argv[])
117 /* Get the arguments */
118 MSG_init(&argc, argv);
120 /* load the platform file */
121 xbt_assert(argc == 2);
122 MSG_create_environment(argv[1]);
124 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
125 msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
128 int res = MSG_main();
129 XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
132 return !(res == MSG_OK);