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. */
8 #include "simgrid/msg.h"
10 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
14 * ./examples/msg/cloud/scale ../examples/platforms/g5k.xml
16 * 1. valgrind --tool=callgrind ./examples/msg/cloud/scale ../examples/platforms/g5k.xml
20 static double time_precise(void) {
22 int ret = gettimeofday(&tv, NULL);
23 xbt_assert(ret >= 0, "gettimeofday");
24 return (double) tv.tv_sec + tv.tv_usec * 0.001 * 0.001;
27 static int computation_fun(int argc, char *argv[]) {
29 // double clock_sta = time_precise();
31 msg_task_t task = MSG_task_create("Task", 10000000, 0, NULL);
32 MSG_task_execute(task);
33 MSG_task_destroy(task);
35 // double clock_end = time_precise();
37 // XBT_INFO("%f", clock_end - clock_sta);
42 static void launch_computation_worker(msg_host_t host) {
43 MSG_process_create("compute", computation_fun, NULL, host);
46 static int master_main(int argc, char *argv[])
48 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
53 msg_host_t *pm = xbt_new(msg_host_t, npm);
54 msg_vm_t *vm = xbt_new(msg_vm_t, nvm);
57 for (i = 0; i < npm; i++) {
58 pm[i] = xbt_dynar_get_as(hosts_dynar, i, msg_host_t);
61 for (i = 0; i < nvm; i++) {
62 int pm_index = i % npm;
63 char *vm_name = bprintf("vm%d", i);
64 vm[i] = MSG_vm_create_core(pm[pm_index], vm_name);
67 launch_computation_worker(vm[i]);
72 XBT_INFO("## Test (start)");
74 for (i = 0; i < 10; i++) {
75 double clock_sta = time_precise();
77 double clock_end = time_precise();
78 XBT_INFO("duration %f", clock_end - clock_sta);
81 for (i = 0; i < nvm; i++) {
82 MSG_vm_destroy(vm[i]);
85 XBT_INFO("## Test (ended)");
89 static void launch_master(msg_host_t host)
91 const char *pr_name = "master_";
92 char **argv = xbt_new(char *, 2);
93 argv[0] = xbt_strdup(pr_name);
96 MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
100 int main(int argc, char *argv[])
102 /* Get the arguments */
103 MSG_init(&argc, argv);
105 /* load the platform file */
106 xbt_assert(argc == 2);
107 MSG_create_environment(argv[1]);
109 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
110 msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
113 int res = MSG_main();
114 XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
116 return !(res == MSG_OK);