From: Frederic Suter Date: Mon, 4 Apr 2016 11:49:09 +0000 (+0200) Subject: clean and simplify X-Git-Tag: v3_13~190 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7772ebc56f07f5c10cf1667d3f4ee2eb60f62bf4?hp=89ef52f7b2f57280e81f67d226b1052123e67596 clean and simplify --- diff --git a/examples/msg/cloud/bound.c b/examples/msg/cloud/bound.c index ffb7387505..aef36265ba 100644 --- a/examples/msg/cloud/bound.c +++ b/examples/msg/cloud/bound.c @@ -4,22 +4,13 @@ /* 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */ -#include "xbt/sysdep.h" /* calloc, printf */ +#include "simgrid/msg.h" -/* Create a log channel to have nice outputs. */ -#include "xbt/log.h" -#include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, - "Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); /** @addtogroup MSG_examples * - * - priority/priority.c: Demonstrates the use of @ref - * MSG_task_set_bound to change the computation priority of a - * given task. - * + * - cloud/bound.c: Demonstrates the use of @ref MSG_task_set_bound */ static int worker_main(int argc, char *argv[]) @@ -28,24 +19,22 @@ static int worker_main(int argc, char *argv[]) int use_bound = xbt_str_parse_int(argv[2], "Second parameter (use_bound) should be 0 or 1 but is: %s"); double bound = xbt_str_parse_double(argv[3], "Invalid bound: %s"); - { - double clock_sta = MSG_get_clock(); - - msg_task_t task = MSG_task_create("Task", computation_amount, 0, NULL); - if (use_bound) - MSG_task_set_bound(task, bound); - 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; - - if (use_bound) - XBT_INFO("bound to %f => duration %f (%f flops/s)", bound, duration, flops_per_sec); - else - XBT_INFO("not bound => duration %f (%f flops/s)", duration, flops_per_sec); - } + double clock_sta = MSG_get_clock(); + + msg_task_t task = MSG_task_create("Task", computation_amount, 0, NULL); + if (use_bound) + MSG_task_set_bound(task, bound); + 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; + + if (use_bound) + XBT_INFO("bound to %f => duration %f (%f flops/s)", bound, duration, flops_per_sec); + else + XBT_INFO("not bound => duration %f (%f flops/s)", duration, flops_per_sec); return 0; } @@ -62,13 +51,10 @@ static void launch_worker(msg_host_t host, const char *pr_name, double computati MSG_process_create_with_arguments(pr_name, worker_main, NULL, host, 4, argv); } - - static int worker_busy_loop_main(int argc, char *argv[]) { msg_task_t *task = MSG_process_get_data(MSG_process_self()); - for (;;) - MSG_task_execute(*task); + MSG_task_execute(*task); return 0; } @@ -88,9 +74,8 @@ static void test_dynamic_change(void) msg_task_t task0 = MSG_task_create("Task0", DOUBLE_MAX, 0, NULL); msg_task_t task1 = MSG_task_create("Task1", DOUBLE_MAX, 0, NULL); - msg_process_t pr0 = MSG_process_create("worker0", worker_busy_loop_main, &task0, vm0); - msg_process_t pr1 = MSG_process_create("worker1", worker_busy_loop_main, &task1, vm1); - + MSG_process_create("worker0", worker_busy_loop_main, &task0, vm0); + MSG_process_create("worker1", worker_busy_loop_main, &task1, vm1); double task0_remain_prev = MSG_task_get_flops_amount(task0); double task1_remain_prev = MSG_task_get_flops_amount(task1); @@ -117,16 +102,12 @@ static void test_dynamic_change(void) task1_remain_prev = task1_remain_now; } } + MSG_process_sleep(2000); // let the tasks end - MSG_process_kill(pr0); - MSG_process_kill(pr1); - MSG_vm_destroy(vm0); MSG_vm_destroy(vm1); } - - static void test_one_task(msg_host_t hostA) { const double cpu_speed = MSG_host_get_speed(hostA); @@ -135,43 +116,32 @@ static void test_one_task(msg_host_t hostA) XBT_INFO("### Test: with/without MSG_task_set_bound"); - { - XBT_INFO("### Test: no bound for Task1@%s", hostA_name); - launch_worker(hostA, "worker0", computation_amount, 0, 0); - } + XBT_INFO("### Test: no bound for Task1@%s", hostA_name); + launch_worker(hostA, "worker0", computation_amount, 0, 0); MSG_process_sleep(1000); - { - XBT_INFO("### Test: 50%% for Task1@%s", hostA_name); - launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 2); - } + XBT_INFO("### Test: 50%% for Task1@%s", hostA_name); + launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 2); MSG_process_sleep(1000); - { - XBT_INFO("### Test: 33%% for Task1@%s", hostA_name); - launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 3); - } + XBT_INFO("### Test: 33%% for Task1@%s", hostA_name); + launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 3); MSG_process_sleep(1000); - { - XBT_INFO("### Test: zero for Task1@%s (i.e., unlimited)", hostA_name); - launch_worker(hostA, "worker0", computation_amount, 1, 0); - } + XBT_INFO("### Test: zero for Task1@%s (i.e., unlimited)", hostA_name); + launch_worker(hostA, "worker0", computation_amount, 1, 0); MSG_process_sleep(1000); - { - XBT_INFO("### Test: 200%% for Task1@%s (i.e., meaningless)", hostA_name); - launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed * 2); - } + XBT_INFO("### Test: 200%% for Task1@%s (i.e., meaningless)", hostA_name); + launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed * 2); MSG_process_sleep(1000); } - static void test_two_tasks(msg_host_t hostA, msg_host_t hostB) { const double cpu_speed = MSG_host_get_speed(hostA); @@ -180,59 +150,45 @@ static void test_two_tasks(msg_host_t hostA, msg_host_t hostB) const char *hostA_name = MSG_host_get_name(hostA); const char *hostB_name = MSG_host_get_name(hostB); - { - XBT_INFO("### Test: no bound for Task1@%s, no bound for Task2@%s", hostA_name, hostB_name); - launch_worker(hostA, "worker0", computation_amount, 0, 0); - launch_worker(hostB, "worker1", computation_amount, 0, 0); - } + XBT_INFO("### Test: no bound for Task1@%s, no bound for Task2@%s", hostA_name, hostB_name); + launch_worker(hostA, "worker0", computation_amount, 0, 0); + launch_worker(hostB, "worker1", computation_amount, 0, 0); MSG_process_sleep(1000); - { - XBT_INFO("### Test: 0 for Task1@%s, 0 for Task2@%s (i.e., unlimited)", hostA_name, hostB_name); - launch_worker(hostA, "worker0", computation_amount, 1, 0); - launch_worker(hostB, "worker1", computation_amount, 1, 0); - } + XBT_INFO("### Test: 0 for Task1@%s, 0 for Task2@%s (i.e., unlimited)", hostA_name, hostB_name); + launch_worker(hostA, "worker0", computation_amount, 1, 0); + launch_worker(hostB, "worker1", computation_amount, 1, 0); MSG_process_sleep(1000); - { - XBT_INFO("### Test: 50%% for Task1@%s, 50%% for Task2@%s", hostA_name, hostB_name); - launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 2); - launch_worker(hostB, "worker1", computation_amount, 1, cpu_speed / 2); - } + XBT_INFO("### Test: 50%% for Task1@%s, 50%% for Task2@%s", hostA_name, hostB_name); + launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 2); + launch_worker(hostB, "worker1", computation_amount, 1, cpu_speed / 2); MSG_process_sleep(1000); - { - XBT_INFO("### Test: 25%% for Task1@%s, 25%% for Task2@%s", hostA_name, hostB_name); - launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 4); - launch_worker(hostB, "worker1", computation_amount, 1, cpu_speed / 4); - } + XBT_INFO("### Test: 25%% for Task1@%s, 25%% for Task2@%s", hostA_name, hostB_name); + launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 4); + launch_worker(hostB, "worker1", computation_amount, 1, cpu_speed / 4); MSG_process_sleep(1000); - { - XBT_INFO("### Test: 75%% for Task1@%s, 100%% for Task2@%s", hostA_name, hostB_name); - launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed * 0.75); - launch_worker(hostB, "worker1", computation_amount, 1, cpu_speed); - } + XBT_INFO("### Test: 75%% for Task1@%s, 100%% for Task2@%s", hostA_name, hostB_name); + launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed * 0.75); + launch_worker(hostB, "worker1", computation_amount, 1, cpu_speed); MSG_process_sleep(1000); - { - XBT_INFO("### Test: no bound for Task1@%s, 25%% for Task2@%s", hostA_name, hostB_name); - launch_worker(hostA, "worker0", computation_amount, 0, 0); - launch_worker(hostB, "worker1", computation_amount, 1, cpu_speed / 4); - } + XBT_INFO("### Test: no bound for Task1@%s, 25%% for Task2@%s", hostA_name, hostB_name); + launch_worker(hostA, "worker0", computation_amount, 0, 0); + launch_worker(hostB, "worker1", computation_amount, 1, cpu_speed / 4); MSG_process_sleep(1000); - { - XBT_INFO("### Test: 75%% for Task1@%s, 25%% for Task2@%s", hostA_name, hostB_name); - launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed * 0.75); - launch_worker(hostB, "worker1", computation_amount, 1, cpu_speed / 4); - } + XBT_INFO("### Test: 75%% for Task1@%s, 25%% for Task2@%s", hostA_name, hostB_name); + launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed * 0.75); + launch_worker(hostB, "worker1", computation_amount, 1, cpu_speed / 4); MSG_process_sleep(1000); } @@ -243,109 +199,90 @@ static int master_main(int argc, char *argv[]) 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); + XBT_INFO("# 1. Put a single task on a PM. "); + test_one_task(pm0); + XBT_INFO(" "); - { - XBT_INFO("# 1. Put a single task on a PM. "); - test_one_task(pm0); - XBT_INFO(" "); + XBT_INFO("# 2. Put two tasks on a PM."); + test_two_tasks(pm0, pm0); + XBT_INFO(" "); + msg_host_t vm0 = MSG_vm_create_core(pm0, "VM0"); + MSG_vm_start(vm0); - XBT_INFO("# 2. Put two tasks on a PM."); - test_two_tasks(pm0, pm0); - XBT_INFO(" "); - } - - - { - msg_host_t vm0 = MSG_vm_create_core(pm0, "VM0"); - MSG_vm_start(vm0); - - XBT_INFO("# 3. Put a single task on a VM. "); - test_one_task(vm0); - XBT_INFO(" "); - - XBT_INFO("# 4. Put two tasks on a VM."); - test_two_tasks(vm0, vm0); - XBT_INFO(" "); - - - MSG_vm_destroy(vm0); - } - - - { - msg_host_t vm0 = MSG_vm_create_core(pm0, "VM0"); - MSG_vm_start(vm0); - - XBT_INFO("# 6. Put a task on a PM and a task on a VM."); - test_two_tasks(pm0, vm0); - XBT_INFO(" "); + XBT_INFO("# 3. Put a single task on a VM. "); + test_one_task(vm0); + XBT_INFO(" "); + XBT_INFO("# 4. Put two tasks on a VM."); + test_two_tasks(vm0, vm0); + XBT_INFO(" "); - MSG_vm_destroy(vm0); - } + MSG_vm_destroy(vm0); + vm0 = MSG_vm_create_core(pm0, "VM0"); + MSG_vm_start(vm0); - { - msg_host_t vm0 = MSG_vm_create_core(pm0, "VM0"); - const double cpu_speed = MSG_host_get_speed(pm0); - MSG_vm_set_bound(vm0, cpu_speed / 10); - MSG_vm_start(vm0); + XBT_INFO("# 6. Put a task on a PM and a task on a VM."); + test_two_tasks(pm0, vm0); + XBT_INFO(" "); - XBT_INFO("# 7. Put a single task on the VM capped by 10%%."); - test_one_task(vm0); - XBT_INFO(" "); + MSG_vm_destroy(vm0); - XBT_INFO("# 8. Put two tasks on the VM capped by 10%%."); - test_two_tasks(vm0, vm0); - XBT_INFO(" "); + vm0 = MSG_vm_create_core(pm0, "VM0"); + double cpu_speed = MSG_host_get_speed(pm0); + MSG_vm_set_bound(vm0, cpu_speed / 10); + MSG_vm_start(vm0); - XBT_INFO("# 9. Put a task on a PM and a task on the VM capped by 10%%."); - test_two_tasks(pm0, vm0); - XBT_INFO(" "); + XBT_INFO("# 7. Put a single task on the VM capped by 10%%."); + test_one_task(vm0); + XBT_INFO(" "); - MSG_vm_destroy(vm0); - } + XBT_INFO("# 8. Put two tasks on the VM capped by 10%%."); + test_two_tasks(vm0, vm0); + XBT_INFO(" "); + XBT_INFO("# 9. Put a task on a PM and a task on the VM capped by 10%%."); + test_two_tasks(pm0, vm0); + XBT_INFO(" "); - { - msg_host_t vm0 = MSG_vm_create_core(pm0, "VM0"); + MSG_vm_destroy(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); + vm0 = MSG_vm_create_core(pm0, "VM0"); - const double cpu_speed = MSG_host_get_speed(pm0); - MSG_vm_start(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); - XBT_INFO("# 10. Test migration"); - const double computation_amount = cpu_speed * 10; + cpu_speed = MSG_host_get_speed(pm0); + MSG_vm_start(vm0); - 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. Test migration"); + const double computation_amount = cpu_speed * 10; - 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. (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. (c) migrate"); - MSG_vm_migrate(vm0, pm1); - 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. (d) Put a task again on the VM."); - 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(" "); - MSG_vm_destroy(vm0); - } + 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(); @@ -369,10 +306,7 @@ int main(int argc, char *argv[]) MSG_init(&argc, argv); /* load the platform file */ - if (argc != 2) { - printf("Usage: %s example/msg/cloud/simple_plat.xml\n", argv[0]); - return 1; - } + xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/small_platform.xml\n", argv[0], argv[0]); MSG_create_environment(argv[1]); @@ -383,6 +317,5 @@ int main(int argc, char *argv[]) int res = MSG_main(); XBT_INFO("Bye (simulation time %g)", MSG_get_clock()); - return !(res == MSG_OK); }