Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
35aace043792d5b9baa4ebdd54bca91e58eb270e
[simgrid.git] / examples / msg / energy / vm / energy_vm.c
1 /* Copyright (c) 2007-2010, 2013-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<stdio.h>
8
9 #include "simgrid/msg.h"
10 #include "xbt/sysdep.h"         /* calloc */
11 #include "simgrid/plugins.h"
12
13 /* Create a log channel to have nice outputs. */
14 #include "xbt/log.h"
15 #include "xbt/asserts.h"
16
17 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
18                              "Messages specific for this msg example");
19
20 static msg_host_t host1 = NULL;
21 static msg_host_t host2 = NULL;
22 static msg_vm_t vm1 = NULL;
23
24 int dvfs(int argc, char *argv[]);
25
26 static int worker_func() {
27         //MSG_process_on_exit(shutdown_vm, NULL);
28
29         msg_task_t task1 = MSG_task_create("t1", 300E6, 0, NULL);
30   MSG_task_execute (task1);
31   MSG_task_destroy(task1);
32   XBT_INFO("Worker fun done");
33         return 0;
34 }
35
36 int dvfs(int argc, char *argv[])
37 {
38   host1 = MSG_host_by_name("MyHost1");
39   host2 = MSG_host_by_name("MyHost2");
40
41   /* Host 1 */
42   XBT_INFO("Creating and starting a VM");
43         vm1 = MSG_vm_create(host1,
44                       "vm1", /* name */
45                       4, /* number of cpus */
46                       2048, /* ram size */
47                       100, /* net cap */
48                       NULL, /* disk path */
49                       1024 * 20, /* disk size */
50                       10, /* mig netspeed */
51                       50 /* dp intensity */
52                       );
53
54   // on Host1 create two tasks, one inside a VM  the other one  directly on the host 
55         MSG_vm_start(vm1);
56   MSG_process_create("p11", worker_func, NULL, vm1);
57   MSG_process_create("p12", worker_func, NULL, host1);
58   //XBT_INFO("Task on Host started");
59
60
61   // on Host2, create two tasks directly on the host: Energy of host 1 and host 2 should be the same.
62   MSG_process_create("p21", worker_func, NULL, host2);
63   MSG_process_create("p22", worker_func, NULL, host2);
64
65   /* Wait and see */
66         MSG_process_sleep(5);
67         MSG_process_sleep(5);
68         MSG_vm_shutdown(vm1);
69
70   return 0;
71 }
72
73 int main(int argc, char *argv[])
74 {
75   msg_error_t res = MSG_OK;
76   sg_energy_plugin_init();
77   MSG_init(&argc, argv);
78
79   if (argc != 3) {
80     XBT_CRITICAL("Usage: %s platform_file deployment_file\n",
81               argv[0]);
82     XBT_CRITICAL
83         ("example: %s msg_platform.xml msg_deployment.xml\n",
84          argv[0]);
85     exit(1);
86   }
87
88   MSG_create_environment(argv[1]);
89
90   /*   Application deployment */
91   MSG_function_register("dvfs_test", dvfs);
92
93   MSG_launch_application(argv[2]);
94
95   res = MSG_main();
96
97   XBT_INFO("Total simulation time: %.2f", MSG_get_clock());
98
99   if (res == MSG_OK)
100     return 0;
101   else
102     return 1;
103 }
104