Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #177 from Takishipp/sd_exit
[simgrid.git] / teshsuite / msg / cloud-sharing / cloud-sharing.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 "simgrid/msg.h"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
9
10 static int computation_fun(int argc, char* argv[])
11 {
12   msg_task_t task = MSG_task_create("Task", 100000000, 0, NULL);
13
14   double clock_sta = MSG_get_clock();
15   MSG_task_execute(task);
16   double clock_end = MSG_get_clock();
17
18   XBT_INFO("Task took %gs to execute", clock_end - clock_sta);
19
20   MSG_task_destroy(task);
21
22   return 0;
23 }
24
25 static int master_main(int argc, char* argv[])
26 {
27   msg_host_t pm0 = MSG_host_by_name("node-0.acme.org");
28   msg_host_t pm1 = MSG_host_by_name("node-1.acme.org");
29   xbt_assert(pm0, "Host node-0.acme.org does not seem to exist");
30
31   XBT_INFO("## Test 1 (started): check computation on normal PMs");
32
33   XBT_INFO("### Put a task on a PM");
34   MSG_process_create("compute", computation_fun, NULL, pm0);
35   MSG_process_sleep(2);
36
37   XBT_INFO("### Put two tasks on a PM");
38   MSG_process_create("compute", computation_fun, NULL, pm0);
39   MSG_process_create("compute", computation_fun, NULL, pm0);
40   MSG_process_sleep(2);
41
42   XBT_INFO("### Put a task on each PM");
43   MSG_process_create("compute", computation_fun, NULL, pm0);
44   MSG_process_create("compute", computation_fun, NULL, pm1);
45   MSG_process_sleep(2);
46
47   XBT_INFO("## Test 1 (ended)");
48
49   XBT_INFO("## Test 2 (started): check impact of running a task inside a VM (there is no degradation for the moment)");
50
51   XBT_INFO("### Put a VM on a PM, and put a task to the VM");
52   msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0");
53   MSG_vm_start(vm0);
54   MSG_process_create("compute", computation_fun, NULL, vm0);
55   MSG_process_sleep(2);
56   MSG_vm_destroy(vm0);
57
58   XBT_INFO("## Test 2 (ended)");
59
60   XBT_INFO(
61       "## Test 3 (started): check impact of running a task collocated with a VM (there is no VM noise for the moment)");
62
63   XBT_INFO("### Put a VM on a PM, and put a task to the PM");
64   vm0 = MSG_vm_create_core(pm0, "VM0");
65   MSG_vm_start(vm0);
66   MSG_process_create("compute", computation_fun, NULL, pm0);
67   MSG_process_sleep(2);
68   MSG_vm_destroy(vm0);
69
70   XBT_INFO("## Test 3 (ended)");
71
72   XBT_INFO("## Test 4 (started): compare the cost of running two tasks inside two different VMs collocated or not (for"
73            " the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
74
75   XBT_INFO("### Put two VMs on a PM, and put a task to each VM");
76   vm0          = MSG_vm_create_core(pm0, "VM0");
77   msg_vm_t vm1 = MSG_vm_create_core(pm0, "VM1");
78   MSG_vm_start(vm0);
79   MSG_vm_start(vm1);
80   MSG_process_create("compute", computation_fun, NULL, vm0);
81   MSG_process_create("compute", computation_fun, NULL, vm1);
82   MSG_process_sleep(2);
83   MSG_vm_destroy(vm0);
84   MSG_vm_destroy(vm1);
85
86   XBT_INFO("### Put a VM on each PM, and put a task to each VM");
87   vm0 = MSG_vm_create_core(pm0, "VM0");
88   vm1 = MSG_vm_create_core(pm1, "VM1");
89   MSG_vm_start(vm0);
90   MSG_vm_start(vm1);
91   MSG_process_create("compute", computation_fun, NULL, vm0);
92   MSG_process_create("compute", computation_fun, NULL, vm1);
93   MSG_process_sleep(2);
94   MSG_vm_destroy(vm0);
95   MSG_vm_destroy(vm1);
96   XBT_INFO("## Test 4 (ended)");
97
98   return 0;
99 }
100
101 int main(int argc, char* argv[])
102 {
103   /* Get the arguments */
104   MSG_init(&argc, argv);
105
106   /* load the platform file */
107   const char* platform = "../../platforms/cluster.xml";
108   if (argc == 2)
109     platform = argv[1];
110   MSG_create_environment(platform);
111
112   msg_host_t pm0 = MSG_host_by_name("node-0.acme.org");
113   xbt_assert(pm0, "Host 'node-0.acme.org' not found");
114   MSG_process_create("master", master_main, NULL, pm0);
115
116   return MSG_main() != MSG_OK;
117 }