static void test_two_tasks(msg_host_t hostA, msg_host_t hostB) { const double cpu_speed = MSG_host_get_speed(hostA); xbt_assert(cpu_speed == MSG_host_get_speed(hostB)); const double computation_amount = cpu_speed * 10; 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); 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); 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); 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); 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); 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); 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); MSG_process_sleep(1000); }
static int dvfs(int argc, char* argv[]) { double workload = 100E6; msg_host_t host = MSG_host_self(); int nb = MSG_host_get_nb_pstates(host); XBT_INFO("Count of Processor states=%d", nb); double current_peak = MSG_host_get_speed(host); XBT_INFO("Current power peak=%f", current_peak); // Run a task msg_task_t task1 = MSG_task_create("t1", workload, 0, NULL); MSG_task_execute(task1); MSG_task_destroy(task1); double task_time = MSG_get_clock(); XBT_INFO("Task1 simulation time: %e", task_time); // Change power peak int new_pstate = 2; xbt_assert(new_pstate < nb, "Cannot set the host %s at pstate %d because it only provides %d pstates.", MSG_host_get_name(host), new_pstate, nb); double peak_at = MSG_host_get_power_peak_at(host, new_pstate); XBT_INFO("Changing power peak value to %f (at index %d)", peak_at, new_pstate); MSG_host_set_pstate(host, new_pstate); current_peak = MSG_host_get_speed(host); XBT_INFO("Current power peak=%f", current_peak); // Run a second task task1 = MSG_task_create("t1", workload, 0, NULL); MSG_task_execute(task1); MSG_task_destroy(task1); task_time = MSG_get_clock() - task_time; XBT_INFO("Task2 simulation time: %e", task_time); // Verify the default pstate is set to 0 host = MSG_host_by_name("MyHost2"); int nb2 = MSG_host_get_nb_pstates(host); XBT_INFO("Count of Processor states=%d", nb2); double current_peak2 = MSG_host_get_speed(host); XBT_INFO("Current power peak=%f", current_peak2); return 0; }
static void test_one_task(msg_host_t hostA) { const double cpu_speed = MSG_host_get_speed(hostA); const double computation_amount = cpu_speed * 10; const char *hostA_name = MSG_host_get_name(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); MSG_process_sleep(1000); 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); MSG_process_sleep(1000); 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); MSG_process_sleep(1000); }
static int execute_load_test(int argc, char* argv[]) { msg_host_t host = MSG_host_by_name("MyHost1"); XBT_INFO("Initial peak speed: %.0E flop/s; number of flops computed so far: %.0E (should be 0)", MSG_host_get_speed(host), sg_host_get_computed_flops(host)); double start = MSG_get_clock(); XBT_INFO("Sleep for 10 seconds"); MSG_process_sleep(10); XBT_INFO("Done sleeping %.2fs; peak speed: %.0E flop/s; number of flops computed so far: %.0E (nothing should have " "changed)", MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host)); // Run a task start = MSG_get_clock(); msg_task_t task1 = MSG_task_create("t1", 100E6, 0, NULL); XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1)); MSG_task_execute(task1); MSG_task_destroy(task1); XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so " "far: %.0E", MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host)); // ========= Change power peak ========= int pstate = 2; sg_host_set_pstate(host, pstate); XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate, MSG_host_get_power_peak_at(host, pstate), MSG_host_get_speed(host)); // Run a second task start = MSG_get_clock(); task1 = MSG_task_create("t2", 100E6, 0, NULL); XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1)); MSG_task_execute(task1); MSG_task_destroy(task1); XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so " "far: %.0E", MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host)); start = MSG_get_clock(); XBT_INFO("========= Requesting a reset of the computation counter"); sg_host_load_reset(host); XBT_INFO("Sleep for 4 seconds"); MSG_process_sleep(4); XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E", MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host)); // =========== Turn the other host off ========== XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed %.0f flops so far.", MSG_host_get_computed_flops(MSG_host_by_name("MyHost2"))); MSG_host_off(MSG_host_by_name("MyHost2")); start = MSG_get_clock(); MSG_process_sleep(10); XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E", MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host)); return 0; }
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, jobject jhost) { msg_host_t host = jhost_get_native(env, jhost); if (!host) { jxbt_throw_notbound(env, "host", jhost); return -1; } return (jdouble) MSG_host_get_speed(host); }
static void test_dynamic_change(void) { msg_host_t pm0 = MSG_host_by_name("Fafard"); msg_host_t vm0 = MSG_vm_create_core(pm0, "VM0"); msg_host_t vm1 = MSG_vm_create_core(pm0, "VM1"); MSG_vm_start(vm0); MSG_vm_start(vm1); 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_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); const double cpu_speed = MSG_host_get_speed(pm0); for (int i = 0; i < 10; i++) { double new_bound = (cpu_speed / 10) * i; XBT_INFO("set bound of VM1 to %f", new_bound); MSG_vm_set_bound(vm1, new_bound); MSG_process_sleep(100); 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("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; } MSG_process_sleep(2000); // let the tasks end MSG_vm_destroy(vm0); MSG_vm_destroy(vm1); }
static int master_main(int argc, char *argv[]) { msg_host_t pm0 = MSG_host_by_name("Fafard"); msg_host_t pm1 = MSG_host_by_name("Fafard"); 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("# 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); 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(" "); MSG_vm_destroy(vm0); 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("# 7. Put a single task on the VM capped by 10%%."); test_one_task(vm0); XBT_INFO(" "); 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_vm_destroy(vm0); 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); cpu_speed = MSG_host_get_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; }
/** \ingroup m_host_management * \brief Return the speed of the processor (in flop/s), regardless of the current load on the machine. * Deprecated: use MSG_host_get_speed */ double MSG_get_host_speed(msg_host_t host) { XBT_WARN("MSG_get_host_speed is deprecated: use MSG_host_get_speed"); return MSG_host_get_speed(host); }