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; }
static int worker(int argc, char *argv[]) { while (1) { msg_task_t task = NULL; XBT_ATTRIB_UNUSED int res = MSG_task_receive(&(task), "worker_mailbox"); xbt_assert(res == MSG_OK, "MSG_task_get failed"); XBT_INFO("Handling task \"%s\"", MSG_task_get_name(task)); if (!strcmp(MSG_task_get_name(task), "finalize")) { XBT_INFO("Destroying task \"%s\"", task->name); MSG_task_destroy(task); break; } if (!strcmp(MSG_task_get_name(task), "cancel")) { MSG_process_create("worker1", worker_main, task, MSG_host_self()); MSG_process_sleep(0.1); XBT_INFO("Canceling task \"%s\"", task->name); MSG_task_cancel(task); continue; } double start = MSG_get_clock(); MSG_task_execute(task); double end = MSG_get_clock(); XBT_INFO("Task \"%s\" done in %f (amount %f)", MSG_task_get_name(task), end - start, MSG_task_get_flops_amount(task)); MSG_task_destroy(task); } XBT_INFO("I'm done. See you!"); return 0; }
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[]) { xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar(); msg_host_t pm0 = MSG_host_by_name("Fafard"); msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0"); MSG_vm_start(vm0); launch_computation_worker(vm0); while(MSG_get_clock()<100) { if (atask != NULL) XBT_INFO("aTask remaining duration: %g", MSG_task_get_flops_amount(atask)); MSG_process_sleep(1); } MSG_process_sleep(10000); MSG_vm_destroy(vm0); xbt_dynar_free(&hosts_dynar); return 1; }
static int worker(int argc, char *argv[]) { msg_task_t task = NULL; TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "is_worker", 1); TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "task_computation", 0); while (1) { MSG_task_receive(&(task), "master_mailbox"); if (strcmp(MSG_task_get_name(task), "finalize") == 0) { MSG_task_destroy(task); break; } //adding the value returned by MSG_task_get_compute_duration(task) //to the variable "task_computation" TRACE_host_variable_add(MSG_host_get_name(MSG_host_self()), "task_computation", MSG_task_get_flops_amount(task)); MSG_task_execute(task); MSG_task_destroy(task); task = NULL; } return 0; }