X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f2c47a1c3e6ad80e8db71169aee7edaa709b0748..6a42d0b4d34e2b9777922430ef85646dabbefa20:/examples/msg/cloud/bound.c diff --git a/examples/msg/cloud/bound.c b/examples/msg/cloud/bound.c index 20d081c40b..8316bb5eb8 100644 --- a/examples/msg/cloud/bound.c +++ b/examples/msg/cloud/bound.c @@ -1,10 +1,11 @@ -/* Copyright (c) 2007-2013. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-2015. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ #include -#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ +#include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */ #include "xbt/sysdep.h" /* calloc, printf */ /* Create a log channel to have nice outputs. */ @@ -53,9 +54,9 @@ static void launch_worker(msg_host_t host, const char *pr_name, double computati { char **argv = xbt_new(char *, 5); argv[0] = xbt_strdup(pr_name); - argv[1] = bprintf("%lf", computation_amount); + argv[1] = bprintf("%f", computation_amount); argv[2] = bprintf("%d", use_bound); - argv[3] = bprintf("%lf", bound); + argv[3] = bprintf("%f", bound); argv[4] = NULL; MSG_process_create_with_arguments(pr_name, worker_main, NULL, host, 4, argv); @@ -72,7 +73,8 @@ static int worker_busy_loop_main(int argc, char *argv[]) return 0; } -#define DOUBLE_MAX 100000000000L +/* FIXME: */ +#define DOUBLE_MAX 1e11 static void test_dynamic_change(void) { @@ -90,8 +92,8 @@ static void test_dynamic_change(void) msg_process_t pr1 = MSG_process_create("worker1", worker_busy_loop_main, &task1, vm1); - double task0_remain_prev = MSG_task_get_remaining_computation(task0); - double task1_remain_prev = MSG_task_get_remaining_computation(task1); + double task0_remain_prev = MSG_task_get_flops_amount(task0); + double task1_remain_prev = MSG_task_get_flops_amount(task1); { const double cpu_speed = MSG_get_host_speed(pm0); @@ -102,14 +104,14 @@ static void test_dynamic_change(void) MSG_vm_set_bound(vm1, new_bound); MSG_process_sleep(100); - double task0_remain_now = MSG_task_get_remaining_computation(task0); - double task1_remain_now = MSG_task_get_remaining_computation(task1); + double task0_remain_now = MSG_task_get_flops_amount(task0); + double task1_remain_now = MSG_task_get_flops_amount(task1); double task0_flops_per_sec = task0_remain_prev - task0_remain_now; double task1_flops_per_sec = task1_remain_prev - task1_remain_now; - XBT_INFO("VM0: %f flops/s", task0_flops_per_sec / 100); - XBT_INFO("VM1: %f flops/s", task1_flops_per_sec / 100); + XBT_INFO("Task0@VM0: %f flops/s", task0_flops_per_sec / 100); + XBT_INFO("Task1@VM1: %f flops/s", task1_flops_per_sec / 100); task0_remain_prev = task0_remain_now; task1_remain_prev = task1_remain_now; @@ -133,39 +135,6 @@ static void test_one_task(msg_host_t hostA) XBT_INFO("### Test: with/without MSG_task_set_bound"); -#if 0 - /* Easy-to-understand code (without calling MSG_task_set_bound) */ - { - double clock_sta = MSG_get_clock(); - - msg_task_t task = MSG_task_create("Task", computation_amount, 0, NULL); - MSG_task_execute(task); - MSG_task_destroy(task); - - double clock_end = MSG_get_clock(); - double duration = clock_end - clock_sta; - double flops_per_sec = computation_amount / duration; - - XBT_INFO("not bound => duration %f (%f flops/s)", duration, flops_per_sec); - } - - /* Easy-to-understand code (with calling MSG_task_set_bound) */ - { - double clock_sta = MSG_get_clock(); - - msg_task_t task = MSG_task_create("Task", computation_amount, 0, NULL); - MSG_task_set_bound(task, cpu_speed / 2); - MSG_task_execute(task); - MSG_task_destroy(task); - - double clock_end = MSG_get_clock(); - double duration = clock_end - clock_sta; - double flops_per_sec = computation_amount / duration; - - XBT_INFO("bound to 0.5 => duration %f (%f flops/s)", duration, flops_per_sec); - } -#endif - { XBT_INFO("### Test: no bound for Task1@%s", hostA_name); launch_worker(hostA, "worker0", computation_amount, 0, 0); @@ -272,6 +241,7 @@ static int master_main(int argc, char *argv[]) { xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar(); msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t); + msg_host_t pm1 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t); { @@ -338,7 +308,46 @@ static int master_main(int argc, char *argv[]) } - XBT_INFO("# 10. Change a bound dynamically"); + { + msg_host_t vm0 = MSG_vm_create_core(pm0, "VM0"); + + s_vm_params_t params; + memset(¶ms, 0, sizeof(params)); + params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes + MSG_host_set_params(vm0, ¶ms); + MSG_vm_start(vm0); + + const double cpu_speed = MSG_get_host_speed(pm0); + MSG_vm_start(vm0); + + XBT_INFO("# 10. Test migration"); + const double computation_amount = cpu_speed * 10; + + XBT_INFO("# 10. (a) Put a task on a VM without any bound."); + launch_worker(vm0, "worker0", computation_amount, 0, 0); + MSG_process_sleep(1000); + XBT_INFO(" "); + + XBT_INFO("# 10. (b) set 10%% bound to the VM, and then put a task on the VM."); + MSG_vm_set_bound(vm0, cpu_speed / 10); + launch_worker(vm0, "worker0", computation_amount, 0, 0); + MSG_process_sleep(1000); + XBT_INFO(" "); + + XBT_INFO("# 10. (c) migrate"); + MSG_vm_migrate(vm0, pm1); + XBT_INFO(" "); + + XBT_INFO("# 10. (d) Put a task again on the VM."); + launch_worker(vm0, "worker0", computation_amount, 0, 0); + MSG_process_sleep(1000); + XBT_INFO(" "); + + MSG_vm_destroy(vm0); + } + + + XBT_INFO("# 11. Change a bound dynamically."); test_dynamic_change(); return 0; @@ -360,7 +369,11 @@ int main(int argc, char *argv[]) MSG_init(&argc, argv); /* load the platform file */ - xbt_assert(argc == 2); + if (argc != 2) { + printf("Usage: %s example/msg/cloud/simple_plat.xml\n", argv[0]); + return 1; + } + MSG_create_environment(argv[1]); xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();