void rb_application_handler_on_end_document(void) { /* * Check if Ruby Threads has been completely instantiated * by Comparing with native Process */ int check = MSG_get_host_number() - NUM2INT(rb_process_number(function_name)); while(check) { check = MSG_get_host_number() - NUM2INT(rb_process_number(function_name)); } args = Qnil; prop = Qnil; function_name = Qnil; host_name = Qnil; }
static int surf_parse_bypass_application(void) { int i; static int AX_ptr; static int surfxml_bufferstack_size = 2048; static int surfxml_buffer_stack_stack_ptr = 0; static int surfxml_buffer_stack_stack[1024]; /* allocating memory to the buffer, I think 2MB should be enough */ surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size); totalHosts = MSG_get_host_number(); hosts = MSG_get_host_table(); /* <platform> */ SURFXML_BUFFER_SET(platform_version, "3"); SURFXML_START_TAG(platform); XBT_DEBUG("process : %s en master",MSG_host_get_name(hosts[0])); /* <process host="host A" function="master"> */ SURFXML_BUFFER_SET(process_host, MSG_host_get_name(hosts[0])); SURFXML_BUFFER_SET(process_function, "master"); SURFXML_BUFFER_SET(process_start_time, "-1.0"); SURFXML_BUFFER_SET(process_kill_time, "-1.0"); SURFXML_START_TAG(process); /* <argument value="0"/> */ SURFXML_BUFFER_SET(argument_value, "0"); SURFXML_START_TAG(argument); SURFXML_END_TAG(argument); SURFXML_END_TAG(process); for(i=1;i<totalHosts;i++) { XBT_DEBUG("process : %s en slave",MSG_host_get_name(hosts[i])); /* <process host="host A" function="slave"> */ SURFXML_BUFFER_SET(process_host,MSG_host_get_name(hosts[i]) ); SURFXML_BUFFER_SET(process_function, "slave"); SURFXML_BUFFER_SET(process_start_time, "-1.0"); SURFXML_BUFFER_SET(process_kill_time, "-1.0"); SURFXML_START_TAG(process); /* <argument value="num"/> */ SURFXML_BUFFER_SET(argument_value, bprintf("%d",i)); SURFXML_START_TAG(argument); SURFXML_END_TAG(argument); SURFXML_END_TAG(process); } /* </platform> */ SURFXML_END_TAG(platform); free(surfxml_bufferstack); return 0; }
static int runner(int argc, char *argv[]) { /* Retrieve the list of all hosts as an array of hosts */ int hosts_count = MSG_get_host_number(); msg_host_t *hosts = xbt_dynar_to_array(MSG_hosts_as_dynar()); XBT_INFO("First, build a classical parallel task, with 1 Gflop to execute on each node, " "and 10MB to exchange between each pair"); double *computation_amounts = xbt_new0(double, hosts_count); double *communication_amounts = xbt_new0(double, hosts_count * hosts_count); for (int i = 0; i < hosts_count; i++) computation_amounts[i] = 1e9; // 1 Gflop for (int i = 0; i < hosts_count; i++) for (int j = i + 1; j < hosts_count; j++) communication_amounts[i * hosts_count + j] = 1e7; // 10 MB msg_task_t ptask = MSG_parallel_task_create("parallel task", hosts_count, hosts, computation_amounts, communication_amounts, NULL); MSG_parallel_task_execute(ptask); MSG_task_destroy(ptask); /* The arrays communication_amounts and computation_amounts are not to be freed manually */ XBT_INFO("Then, build a parallel task involving only computations and no communication (1 Gflop per node)"); computation_amounts = xbt_new0(double, hosts_count); for (int i = 0; i < hosts_count; i++) computation_amounts[i] = 1e9; // 1 Gflop ptask = MSG_parallel_task_create("parallel exec", hosts_count, hosts, computation_amounts, NULL/* no comm */, NULL); MSG_parallel_task_execute(ptask); MSG_task_destroy(ptask); XBT_INFO("Then, build a parallel task with no computation nor communication (synchro only)"); computation_amounts = xbt_new0(double, hosts_count); communication_amounts = xbt_new0(double, hosts_count * hosts_count); /* memset to 0 by xbt_new0 */ ptask = MSG_parallel_task_create("parallel sync", hosts_count, hosts, computation_amounts, communication_amounts, NULL); MSG_parallel_task_execute(ptask); MSG_task_destroy(ptask); XBT_INFO("Finally, trick the ptask to do a 'remote execution', on host %s", MSG_host_get_name(hosts[1])); computation_amounts = xbt_new0(double, 1); computation_amounts[0] = 1e9; // 1 Gflop msg_host_t *remote = xbt_new(msg_host_t,1); remote[0] = hosts[1]; ptask = MSG_parallel_task_create("remote exec", 1, remote, computation_amounts, NULL/* no comm */, NULL); MSG_parallel_task_execute(ptask); MSG_task_destroy(ptask); free(remote); XBT_INFO("Goodbye now!"); free(hosts); return 0; }
int main(int argc, char *argv[]) { MSG_init(&argc, argv); xbt_assert(argc>1, "Usage: %s platform.xml\n",argv[0]); MSG_create_environment(argv[1]); /* - Load the platform description */ xbt_dynar_t hosts = MSG_hosts_as_dynar(); XBT_INFO("Number of hosts '%d'", MSG_get_host_number()); unsigned int i; msg_host_t h; xbt_dynar_foreach (hosts, i, h) { /* - Give a unique rank to each host and create a @ref relay_runner process on each */ char* name_host = bprintf("%u",i); MSG_process_create(name_host, relay_runner, NULL, h); free(name_host); }
/* Main function of all processes used in this example */ static int relay_runner(int argc, char* argv[]) { xbt_assert(argc == 0, "The relay_runner function does not accept any parameter from the XML deployment file"); int rank = xbt_str_parse_int(MSG_process_get_name(MSG_process_self()), "Any process of this example must have a numerical name, not %s"); char mailbox[256]; if (rank == 0) { /* The root process (rank 0) first sends the token then waits to receive it back */ snprintf(mailbox, 255, "%d", rank + 1); unsigned int task_comm_size = 1000000; /* The token is 1MB long*/ msg_task_t task = MSG_task_create("Token", 0, task_comm_size, NULL); XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"", rank, task->name, mailbox); MSG_task_send(task, mailbox); task = NULL; int res = MSG_task_receive(&task, MSG_process_get_name(MSG_process_self())); xbt_assert(res == MSG_OK, "MSG_task_get failed"); XBT_INFO("Host \"%d\" received \"%s\"", rank, MSG_task_get_name(task)); MSG_task_destroy(task); } else { /* The others processes receive from their left neighbor (rank-1) and send to their right neighbor (rank+1) */ msg_task_t task = NULL; int res = MSG_task_receive(&task, MSG_process_get_name(MSG_process_self())); xbt_assert(res == MSG_OK, "MSG_task_get failed"); XBT_INFO("Host \"%d\" received \"%s\"", rank, MSG_task_get_name(task)); if (rank + 1 == MSG_get_host_number()) /* But the last process, which sends the token back to rank 0 */ snprintf(mailbox, 255, "0"); else snprintf(mailbox, 255, "%d", rank + 1); XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"", rank, task->name, mailbox); MSG_task_send(task, mailbox); } return 0; }
/** Emitter function */ int master(int argc, char *argv[]) { int workers_count = 0; msg_host_t *workers = NULL; msg_task_t *todo = NULL; msg_host_t host_self = MSG_host_self(); char *master_name = (char *) MSG_host_get_name(host_self); double task_comp_size = 0; double task_comm_size = 0; char channel[1024]; double timeout = -1; int i; TRACE_category(master_name); _XBT_GNUC_UNUSED int res = sscanf(argv[1], "%lg", &timeout); xbt_assert(res,"Invalid argument %s\n", argv[1]); res = sscanf(argv[2], "%lg", &task_comp_size); xbt_assert(res, "Invalid argument %s\n", argv[2]); res = sscanf(argv[3], "%lg", &task_comm_size); xbt_assert(res, "Invalid argument %s\n", argv[3]); { /* Process organisation */ workers_count = MSG_get_host_number(); workers = xbt_dynar_to_array(MSG_hosts_as_dynar()); for (i = 0; i < workers_count; i++) if(host_self == workers[i]) { workers[i] = workers[workers_count-1]; workers_count--; break; } for (i = 0; i < workers_count; i++) MSG_process_create("worker", worker, master_name, workers[i]); } XBT_INFO("Got %d workers and will send tasks for %g seconds!", workers_count, timeout); for (i = 0; 1; i++) { char sprintf_buffer[64]; msg_task_t task = NULL; if(MSG_get_clock()>timeout) break; sprintf(sprintf_buffer, "Task_%d", i); task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); MSG_task_set_category(task, master_name); build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count])); XBT_DEBUG("Sending \"%s\" to channel \"%s\"", task->name, channel); MSG_task_send(task, channel); XBT_DEBUG("Sent"); } int task_num = i; XBT_DEBUG ("All tasks have been dispatched. Let's tell everybody the computation is over."); for (i = 0; i < workers_count; i++) { msg_task_t finalize = MSG_task_create("finalize", 0, 0, FINALIZE); MSG_task_send(finalize, build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count]))); } XBT_INFO("Sent %d tasks in total!", task_num); free(workers); free(todo); return 0; } /* end_of_master */
/** Emitter function */ int master(int argc, char *argv[]) { int workers_count = 0; msg_host_t *workers = NULL; msg_task_t *todo = NULL; msg_host_t host_self = MSG_host_self(); char *master_name = (char *) MSG_host_get_name(host_self); double task_comp_size = 0; double task_comm_size = 0; char channel[1024]; double timeout = -1; int i; TRACE_category(master_name); _XBT_GNUC_UNUSED int res = sscanf(argv[1], "%lg", &timeout); xbt_assert(res,"Invalid argument %s\n", argv[1]); res = sscanf(argv[2], "%lg", &task_comp_size); xbt_assert(res, "Invalid argument %s\n", argv[2]); res = sscanf(argv[3], "%lg", &task_comm_size); xbt_assert(res, "Invalid argument %s\n", argv[3]); { /* Process organisation */ workers_count = MSG_get_host_number(); workers = xbt_dynar_to_array(MSG_hosts_as_dynar()); for (i = 0; i < workers_count; i++) if(host_self == workers[i]) { workers[i] = workers[workers_count-1]; workers_count--; break; } for (i = 0; i < workers_count; i++) MSG_process_create("worker", worker, master_name, workers[i]); } XBT_INFO("Got %d workers and will send tasks for %g seconds!", workers_count, timeout); xbt_dynar_t idle_hosts = xbt_dynar_new(sizeof(msg_host_t), NULL); msg_host_t request_host = NULL; for (i = 0; 1;) { char sprintf_buffer[64]; msg_task_t task = NULL; msg_task_t request = NULL; while(MSG_task_listen(master_name)) { res = MSG_task_receive(&(request),master_name); xbt_assert(res == MSG_OK, "MSG_task_receive failed"); request_host = MSG_task_get_data(request); xbt_dynar_push(idle_hosts, &request_host); MSG_task_destroy(request); request = NULL; } if(MSG_get_clock()>timeout) { if(xbt_dynar_length(idle_hosts) == workers_count) break; else { MSG_process_sleep(.1); continue; } } if(xbt_dynar_length(idle_hosts)<=0) { /* No request. Let's wait... */ MSG_process_sleep(.1); continue; } sprintf(sprintf_buffer, "Task_%d", i); task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); MSG_task_set_category(task, master_name); xbt_dynar_shift(idle_hosts, &request_host); build_channel_name(channel,master_name, MSG_host_get_name(request_host)); XBT_DEBUG("Sending \"%s\" to channel \"%s\"", task->name, channel); MSG_task_send(task, channel); XBT_DEBUG("Sent"); i++; } int task_num = i; XBT_DEBUG ("All tasks have been dispatched. Let's tell everybody the computation is over."); for (i = 0; i < workers_count; i++) { msg_task_t finalize = MSG_task_create("finalize", 0, 0, FINALIZE); MSG_task_send(finalize, build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count]))); } XBT_INFO("Sent %d tasks in total!", task_num); free(workers); free(todo); return 0; } /* end_of_master */
/** Emitter function */ static int master(int argc, char *argv[]) { int workers_count = 0; msg_host_t *workers = NULL; msg_task_t *todo = NULL; msg_host_t host_self = MSG_host_self(); char *master_name = (char *) MSG_host_get_name(host_self); char channel[1024]; int i; long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s"); /** - Number of tasks */ double comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s"); /** - Task compute cost */ double comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s"); /** - Task communication size */ { /* Task creation */ char sprintf_buffer[64]; todo = xbt_new0(msg_task_t, number_of_tasks); for (i = 0; i < number_of_tasks; i++) { sprintf(sprintf_buffer, "Task_%d", i); todo[i] = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); } } { /* Process organization */ workers_count = MSG_get_host_number(); workers = xbt_dynar_to_array(MSG_hosts_as_dynar()); for (i = 0; i < workers_count; i++) if(host_self == workers[i]) { workers[i] = workers[workers_count-1]; workers_count--; break; } for (i = 0; i < workers_count; i++) MSG_process_create("worker", worker, master_name, workers[i]); } XBT_INFO("Got %d workers and %Ld tasks to process", workers_count, number_of_tasks); for (i = 0; i < number_of_tasks; i++) { build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count])); XBT_INFO("Sending \"%s\" to channel \"%s\"", todo[i]->name, channel); MSG_task_send(todo[i], channel); XBT_INFO("Sent"); } XBT_INFO ("All tasks have been dispatched. Let's tell everybody the computation is over."); for (i = 0; i < workers_count; i++) { msg_task_t finalize = MSG_task_create("finalize", 0, 0, FINALIZE); MSG_task_send(finalize, build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count]))); } XBT_INFO("Goodbye now!"); free(workers); free(todo); return 0; } /* end_of_master */
/** Emitter function */ int master(int argc, char *argv[]) { int workers_count = 0; msg_host_t *workers = NULL; msg_task_t *todo = NULL; msg_host_t host_self = MSG_host_self(); char *master_name = (char *) MSG_host_get_name(host_self); int number_of_tasks = 0; double task_comp_size = 0; double task_comm_size = 0; char channel[1024]; int i; _XBT_GNUC_UNUSED int res = sscanf(argv[1], "%d", &number_of_tasks); xbt_assert(res,"Invalid argument %s\n", argv[1]); res = sscanf(argv[2], "%lg", &task_comp_size); xbt_assert(res, "Invalid argument %s\n", argv[2]); res = sscanf(argv[3], "%lg", &task_comm_size); xbt_assert(res, "Invalid argument %s\n", argv[3]); { /* Task creation */ char sprintf_buffer[64]; todo = xbt_new0(msg_task_t, number_of_tasks); for (i = 0; i < number_of_tasks; i++) { sprintf(sprintf_buffer, "Task_%d", i); todo[i] = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); } } { /* Process organisation */ workers_count = MSG_get_host_number(); workers = xbt_dynar_to_array(MSG_hosts_as_dynar()); for (i = 0; i < workers_count; i++) if(host_self == workers[i]) { workers[i] = workers[workers_count-1]; workers_count--; break; } for (i = 0; i < workers_count; i++) MSG_process_create("worker", worker, master_name, workers[i]); } XBT_INFO("Got %d workers and %d tasks to process", workers_count, number_of_tasks); for (i = 0; i < number_of_tasks; i++) { build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count])); XBT_INFO("Sending \"%s\" to channel \"%s\"", todo[i]->name, channel); MSG_task_send(todo[i], channel); XBT_INFO("Sent"); } XBT_INFO ("All tasks have been dispatched. Let's tell everybody the computation is over."); for (i = 0; i < workers_count; i++) { msg_task_t finalize = MSG_task_create("finalize", 0, 0, FINALIZE); MSG_task_send(finalize, build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count]))); } XBT_INFO("Goodbye now!"); free(workers); free(todo); return 0; } /* end_of_master */