/** Emitter function */ int master(int argc, char *argv[]) { double task_comp_size = 5E7; double task_comm_size = 1E6; char mailbox[256]; msg_task_t task = NULL; msg_host_t jupiter = MSG_get_host_by_name("Jupiter"); sprintf(mailbox, "jupi"); task = MSG_task_create("task on", task_comp_size, task_comm_size, NULL); XBT_INFO("Sending \"%s\"", task->name); if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK) MSG_task_destroy(task); MSG_process_sleep(1); MSG_host_off(jupiter); task = MSG_task_create("task off", task_comp_size, task_comm_size, NULL); XBT_INFO("Sending \"%s\"", task->name); if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK) MSG_task_destroy(task); MSG_host_on(jupiter); xbt_swag_t jupi_processes = MSG_host_get_process_list(jupiter); void *process; xbt_swag_foreach(process, jupi_processes) { MSG_process_kill(process); }
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 master(int argc, char *argv[]) { xbt_ex_t e; TRY { msg_host_t jupiter = MSG_host_by_name("Jupiter"); XBT_INFO("Master waiting"); MSG_process_sleep(1); XBT_INFO("Turning off the slave host"); MSG_host_off(jupiter); XBT_INFO("Master has finished"); } CATCH(e) { xbt_die("Exception caught in the master"); return 1; } return 0; }
static void simulate_shutdown(msg_host_t host) { int previous_pstate = MSG_host_get_pstate(host); XBT_INFO("Switch to virtual pstate 4, that encodes the shutting down state in the XML file of that example"); MSG_host_set_pstate(host,4); msg_host_t host_list[1] = {host}; double flops_amount[1] = {1}; double bytes_amount[1] = {0}; XBT_INFO("Simulate the shutdown by executing one flop on that remote host (using a parallel task)"); msg_task_t shutdown = MSG_parallel_task_create("shutdown", 1, host_list, flops_amount, bytes_amount, NULL); MSG_task_execute(shutdown); MSG_task_destroy(shutdown); XBT_INFO("Switch back to previously selected pstate %d", previous_pstate); MSG_host_set_pstate(host, previous_pstate); XBT_INFO("Actually shutdown the host"); MSG_host_off(host); }
int test_launcher(int argc, char *argv[]) { int test = 0; char **argvF; argvF = xbt_new(char*, 2); argvF[0] = xbt_strdup("process_daemon"); msg_host_t jupiter = MSG_get_host_by_name("Jupiter"); test = 1; // Create a process running a simple task on a host and turn the host off during the execution of the process. if (xbt_dynar_search_or_negative(tests, &test)!=-1){ XBT_INFO("Test 1:"); XBT_INFO(" Create a process on Jupiter"); argvF = xbt_new(char*, 2); argvF[0] = xbt_strdup("process_daemon"); MSG_process_create_with_arguments("process_daemon", process_daemon, NULL, jupiter, 1, argvF); MSG_process_sleep(3); XBT_INFO(" Turn off Jupiter"); MSG_host_off(jupiter); MSG_process_sleep(10); XBT_INFO("Test 1 seems ok, cool !(number of Process : %d, it should be 1 (i.e. the Test one))", MSG_process_get_number()); }
JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_off(JNIEnv *env, jobject jhost) { msg_host_t host = jhost_get_native(env, jhost); MSG_host_off(host); }