1 /* Copyright (c) 2007-2010, 2013-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 */
11 #include "simgrid/plugins.h"
13 /* Create a log channel to have nice outputs. */
15 #include "xbt/asserts.h"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
18 "Messages specific for this msg example");
20 static msg_host_t host1 = NULL;
21 static msg_host_t host2 = NULL;
22 static msg_vm_t vm1 = NULL;
25 int dvfs(int argc, char *argv[]);
26 int shutdown_vm(void *ignored1, void *ignored2);
29 //MSG_process_on_exit(shutdown_vm, NULL);
31 msg_task_t task1 = MSG_task_create("t1", 300E6, 0, NULL);
32 MSG_task_execute (task1);
33 MSG_task_destroy(task1);
34 XBT_INFO("Worker fun done");
39 int shutdown_vm(void *ignored1, void *ignored2) {
40 start = MSG_get_clock();
41 XBT_INFO("Shutting down the VM");
45 XBT_INFO("VM is now down (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
46 MSG_get_clock()-start,
47 MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
53 int dvfs(int argc, char *argv[])
55 host1 = MSG_host_by_name("MyHost1");
56 host2 = MSG_host_by_name("MyHost2");
58 double start = MSG_get_clock();
61 XBT_INFO("Creating and starting a VM");
62 vm1 = MSG_vm_create(host1,
64 4, /* number of cpus */
68 1024 * 20, /* disk size */
69 10, /* mig netspeed */
73 // on Host1 create two tasks, one inside a VM the other one directly on the host
75 msg_process_t p11 = MSG_process_create("p11", worker_func, NULL, vm1);
76 msg_process_t p12 = MSG_process_create("p12", worker_func, NULL, host1);
77 //XBT_INFO("Task on Host started");
80 // on Host2, create two tasks directlu on the host: Energy of host 1 and host 2 should be the same.
81 msg_process_t p21 = MSG_process_create("p21", worker_func, NULL, host2);
82 msg_process_t p22 = MSG_process_create("p22", worker_func, NULL, host2);
92 int main(int argc, char *argv[])
94 msg_error_t res = MSG_OK;
95 sg_energy_plugin_init();
96 MSG_init(&argc, argv);
99 XBT_CRITICAL("Usage: %s platform_file deployment_file\n",
102 ("example: %s msg_platform.xml msg_deployment.xml\n",
107 MSG_create_environment(argv[1]);
109 /* Application deployment */
110 MSG_function_register("dvfs_test", dvfs);
112 MSG_launch_application(argv[2]);
116 XBT_INFO("Total simulation time: %.2f", MSG_get_clock());