Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / examples / msg / cloud-scale / cloud-scale.c
1 /* Copyright (c) 2007-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <sys/time.h>
8 #include "simgrid/msg.h"
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
11
12 static int task_count=0;
13 static int computation_fun(int argc, char *argv[]) {
14   msg_task_t task = MSG_task_create("Task", 2210000, 0, NULL);
15   MSG_task_execute(task);
16   task_count++;
17   MSG_task_destroy(task);
18   return 0;
19 }
20
21 static void launch_computation_worker(msg_host_t host) {
22   MSG_process_create("compute", computation_fun, NULL, host);
23 }
24
25 static int master_main(int argc, char *argv[])
26 {
27   xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
28
29   int npm = 10;
30   int nvm = 1000;
31
32   msg_host_t *pm = xbt_new(msg_host_t, npm);
33   msg_vm_t   *vm = xbt_new(msg_vm_t, nvm);
34
35   int i = 0;
36   for (i = 0; i < npm; i++) {
37     pm[i] = xbt_dynar_get_as(hosts_dynar, i, msg_host_t);
38   }
39
40   XBT_INFO("## Test (start)");
41   for (i = 0; i < nvm; i++) {
42     int pm_index = i % npm;
43     char *vm_name = bprintf("vm%d", i);
44     vm[i] = MSG_vm_create_core(pm[pm_index], vm_name);
45     MSG_vm_start(vm[i]);
46
47     launch_computation_worker(vm[i]);
48
49     xbt_free(vm_name);
50   }
51
52   for (i = 0; i < 10; i++) {
53     MSG_process_sleep(1);
54     XBT_INFO("Completed tasks: %d", task_count);
55   }
56
57   for (i = 0; i < nvm; i++) {
58     MSG_vm_destroy(vm[i]);
59   }
60
61   XBT_INFO("## Test (ended)");
62   return 0;
63 }
64
65 static void launch_master(msg_host_t host)
66 {
67   const char *pr_name = "master_";
68   char **argv = xbt_new(char *, 2);
69   argv[0] = xbt_strdup(pr_name);
70   argv[1] = NULL;
71
72   MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
73 }
74
75
76 int main(int argc, char *argv[])
77 {
78   /* Get the arguments */
79   MSG_init(&argc, argv);
80
81   /* load the platform file */
82   xbt_assert(argc == 2);
83   MSG_create_environment(argv[1]);
84
85   xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
86   msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
87   launch_master(pm0);
88
89   int res = MSG_main();
90   XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
91
92   return !(res == MSG_OK);
93 }