本文整理汇总了C++中MSG_task_create函数的典型用法代码示例。如果您正苦于以下问题:C++ MSG_task_create函数的具体用法?C++ MSG_task_create怎么用?C++ MSG_task_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MSG_task_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: master
/** 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);
}
示例2: master
int master(int argc, char *argv[])
{
const char *hostname = MSG_host_get_name(MSG_host_self());
int i;
//the hostname has an empty HDD with a capacity of 100000 (bytes)
TRACE_host_variable_set(hostname, "HDD_capacity", 100000);
TRACE_host_variable_set(hostname, "HDD_utilization", 0);
for (i = 0; i < 10; i++) {
//create and execute a task just to make the simulated time advance
msg_task_t task = MSG_task_create("task", 10000, 0, NULL);
MSG_task_execute (task);
MSG_task_destroy (task);
//ADD: after the execution of this task, the HDD utilization increases by 100 (bytes)
TRACE_host_variable_add(hostname, "HDD_utilization", 100);
}
for (i = 0; i < 10; i++) {
//create and execute a task just to make the simulated time advance
msg_task_t task = MSG_task_create("task", 10000, 0, NULL);
MSG_task_execute (task);
MSG_task_destroy (task);
//SUB: after the execution of this task, the HDD utilization decreases by 100 (bytes)
TRACE_host_variable_sub(hostname, "HDD_utilization", 100);
}
return 0;
}
示例3: master
/** Emitter function */
int master(int argc, char *argv[])
{
long number_of_tasks = atol(argv[1]);
long slaves_count = atol(argv[4]);
int i;
for (i = 0; i < number_of_tasks; i++) {
m_task_t task = NULL;
//creating task and setting its category
if (i % 2) {
task = MSG_task_create("task_compute", 10000000, 0, NULL);
TRACE_msg_set_task_category(task, "compute");
} else if (i % 3) {
task = MSG_task_create("task_request", 10, 10, NULL);
TRACE_msg_set_task_category(task, "request");
} else {
task = MSG_task_create("task_data", 10, 10000000, NULL);
TRACE_msg_set_task_category(task, "data");
}
MSG_task_send(task, "master_mailbox");
}
for (i = 0; i < slaves_count; i++) {
m_task_t finalize = MSG_task_create("finalize", 0, 1000, 0);
TRACE_msg_set_task_category(finalize, "finalize");
MSG_task_send(finalize, "master_mailbox");
}
return 0;
}
示例4: master
static int master(int argc, char *argv[])
{
long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
long workers_count = xbt_str_parse_int(argv[4], "Invalid amount of workers: %s");
for (int i = 0; i < number_of_tasks; i++) {
msg_task_t task = NULL;
/* creating task and setting its category */
if (i % 2) {
task = MSG_task_create("task_compute", 10000000, 0, NULL);
MSG_task_set_category(task, "compute");
} else if (i % 3) {
task = MSG_task_create("task_request", 10, 10, NULL);
MSG_task_set_category(task, "request");
} else {
task = MSG_task_create("task_data", 10, 10000000, NULL);
MSG_task_set_category(task, "data");
}
MSG_task_send(task, "master_mailbox");
}
for (int i = 0; i < workers_count; i++) {
msg_task_t finalize = MSG_task_create("finalize", 0, 1000, 0);
MSG_task_set_category(finalize, "finalize");
MSG_task_send(finalize, "master_mailbox");
}
return 0;
}
示例5: execute_load_test
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;
}
示例6: computation_fun
int computation_fun(int argc, char *argv[])
{
const char *pr_name = MSG_process_get_name(MSG_process_self());
const char *host_name = MSG_host_get_name(MSG_host_self());
double clock_sta, clock_end;
atask = MSG_task_create("Task1", 1e9, 1e9, NULL);
clock_sta = MSG_get_clock();
XBT_INFO("%s:%s task 1 created %g", host_name, pr_name, clock_sta);
MSG_task_execute(atask);
clock_end = MSG_get_clock();
XBT_INFO("%s:%s task 1 executed %g", host_name, pr_name, clock_end - clock_sta);
MSG_task_destroy(atask);
atask = NULL;
MSG_process_sleep(1);
atask = MSG_task_create("Task2", 1e10, 1e10, NULL);
clock_sta = MSG_get_clock();
XBT_INFO("%s:%s task 2 created %g", host_name, pr_name, clock_sta);
MSG_task_execute(atask);
clock_end = MSG_get_clock();
XBT_INFO("%s:%s task 2 executed %g", host_name, pr_name, clock_end - clock_sta);
MSG_task_destroy(atask);
atask = NULL;
return 0;
}
示例7: master
/** Emitter function */
int master(int argc, char *argv[])
{
long number_of_tasks = atol(argv[1]);
double task_comp_size = atof(argv[2]);
double task_comm_size = atof(argv[3]);
long slaves_count = atol(argv[4]);
XBT_INFO("master %ld %f %f %ld", number_of_tasks, task_comp_size,
task_comm_size, slaves_count);
int i;
for (i = 0; i < number_of_tasks; i++) {
char task_name[100];
snprintf (task_name, 100, "task-%d", i);
m_task_t task = NULL;
task = MSG_task_create(task_name, task_comp_size, task_comm_size, NULL);
//setting the category of task to "compute"
//the category of a task must be defined before it is sent or executed
TRACE_msg_set_task_category(task, "compute");
MSG_task_send(task, "master_mailbox");
}
for (i = 0; i < slaves_count; i++) {
char task_name[100];
snprintf (task_name, 100, "task-%d", i);
m_task_t finalize = MSG_task_create(task_name, 0, 0, xbt_strdup("finalize"));
TRACE_msg_set_task_category(finalize, "finalize");
MSG_task_send(finalize, "master_mailbox");
}
return 0;
}
示例8: master
static int master(int argc, char *argv[])
{
long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");
long workers_count = xbt_str_parse_int(argv[4], "Invalid amount of workers: %s");
//setting the variable "is_master" (previously declared) to value 1
TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "is_master", 1);
TRACE_mark("msmark", "start_send_tasks");
for (int i = 0; i < number_of_tasks; i++) {
msg_task_t task = NULL;
task = MSG_task_create("task", task_comp_size, task_comm_size, NULL);
//setting the variable "task_creation" to value i
TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "task_creation", i);
//setting the category of task to "compute"
//the category of a task must be defined before it is sent or executed
MSG_task_set_category(task, "compute");
MSG_task_send(task, "master_mailbox");
}
TRACE_mark("msmark", "finish_send_tasks");
for (int i = 0; i < workers_count; i++) {
msg_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
MSG_task_set_category(finalize, "finalize");
MSG_task_send(finalize, "master_mailbox");
}
return 0;
}
示例9: master
/** Emitter function */
int master(int argc, char *argv[])
{
long number_of_tasks = atol(argv[1]);
double task_comp_size = atof(argv[2]);
double task_comm_size = atof(argv[3]);
long slaves_count = atol(argv[4]);
//setting the variable "is_master" (previously declared) to value 1
TRACE_host_variable_set("is_master", 1);
TRACE_mark("msmark", "start_send_tasks");
int i;
for (i = 0; i < number_of_tasks; i++) {
m_task_t task = NULL;
task = MSG_task_create("task", task_comp_size, task_comm_size, NULL);
//setting the variable "task_creation" to value i
TRACE_host_variable_set("task_creation", i);
//setting the category of task to "compute"
//the category of a task must be defined before it is sent or executed
TRACE_msg_set_task_category(task, "compute");
MSG_task_send(task, "master_mailbox");
}
TRACE_mark("msmark", "finish_send_tasks");
for (i = 0; i < slaves_count; i++) {
m_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
TRACE_msg_set_task_category(finalize, "finalize");
MSG_task_send(finalize, "master_mailbox");
}
return 0;
}
示例10: coordinator
static int coordinator(int argc, char *argv[])
{
int CS_used = 0; // initially the CS is idle
while (1) {
msg_task_t task = NULL;
MSG_task_receive(&task, "coordinator");
const char *kind = MSG_task_get_name(task); //is it a request or a release?
if (!strcmp(kind, "request")) { // that's a request
char *req = MSG_task_get_data(task);
if (CS_used) {
XBT_INFO("CS already used.");
msg_task_t answer = MSG_task_create("not grant", 0, 1000, NULL);
MSG_task_send(answer, req);
} else { // can serve it immediately
XBT_INFO("CS idle. Grant immediately");
msg_task_t answer = MSG_task_create("grant", 0, 1000, NULL);
MSG_task_send(answer, req);
CS_used = 1;
}
} else { // that's a release. Check if someone was waiting for the lock
XBT_INFO("CS release. resource now idle");
CS_used = 0;
}
MSG_task_destroy(task);
kind = NULL;
}
return 0;
}
示例11: master
/** Emitter function */
int master(int argc, char *argv[])
{
int i;
for (i = 1; i <= number_of_jobs; i++) {
char mailbox[256];
char sprintf_buffer[256];
msg_task_t task = NULL;
sprintf(mailbox, "slave-%ld", i % number_of_slaves);
sprintf(sprintf_buffer, "Task_%d", i);
task =
MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size,
NULL);
XBT_DEBUG("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name,
number_of_jobs, mailbox);
MSG_task_send(task, mailbox);
}
XBT_DEBUG
("All tasks have been dispatched. Let's tell everybody the computation is over.");
for (i = 0; i < number_of_slaves; i++) {
char mailbox[80];
sprintf(mailbox, "slave-%ld", i % number_of_slaves);
msg_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
MSG_task_send(finalize, mailbox);
}
XBT_DEBUG("Goodbye now!");
return 0;
} /* end_of_master */
示例12: server
static int server(int argc, char *argv[])
{
msg_task_t task = MSG_task_create("a", 0, 0, (char*)"Some data");
MSG_task_isend(task, "mailbox");
xbt_assert(MSG_task_listen("mailbox")); // True (1)
XBT_INFO("Task listen works on regular mailboxes");
task = NULL;
MSG_task_receive(&task, "mailbox");
xbt_assert(!strcmp("Some data", MSG_task_get_data(task)), "Data received: %s", (char*)MSG_task_get_data(task));
MSG_task_destroy(task);
XBT_INFO("Data successfully received from regular mailbox");
MSG_mailbox_set_async("mailbox2");
task = MSG_task_create("b", 0, 0, (char*)"More data");
MSG_task_isend(task, "mailbox2");
xbt_assert(MSG_task_listen("mailbox2")); // used to break.
XBT_INFO("Task listen works on asynchronous mailboxes");
task = NULL;
MSG_task_receive(&task, "mailbox2");
xbt_assert(!strcmp("More data", MSG_task_get_data(task)));
MSG_task_destroy(task);
XBT_INFO("Data successfully received from asynchronous mailbox");
return 0;
}
示例13: sender
/** Sender function */
int sender(int argc, char *argv[])
{
long number_of_tasks = atol(argv[1]);
double task_comp_size = atof(argv[2]);
double task_comm_size = atof(argv[3]);
long receivers_count = atol(argv[4]);
double sleep_start_time = atof(argv[5]);
double sleep_test_time = atof(argv[6]);
XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time,
sleep_test_time);
msg_comm_t comm = NULL;
int i;
m_task_t task = NULL;
MSG_process_sleep(sleep_start_time);
for (i = 0; i < number_of_tasks; i++) {
char mailbox[256];
char sprintf_buffer[256];
sprintf(mailbox, "receiver-%ld", i % receivers_count);
sprintf(sprintf_buffer, "Task_%d", i);
task =
MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size,
NULL);
comm = MSG_task_isend(task, mailbox);
XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);
if (sleep_test_time == 0) {
MSG_comm_wait(comm, -1);
} else {
while (MSG_comm_test(comm) == 0) {
MSG_process_sleep(sleep_test_time);
};
MSG_comm_destroy(comm);
}
}
for (i = 0; i < receivers_count; i++) {
char mailbox[80];
sprintf(mailbox, "receiver-%ld", i % receivers_count);
task = MSG_task_create("finalize", 0, 0, 0);
comm = MSG_task_isend(task, mailbox);
XBT_INFO("Send to receiver-%ld finalize", i % receivers_count);
if (sleep_test_time == 0) {
MSG_comm_wait(comm, -1);
} else {
while (MSG_comm_test(comm) == 0) {
MSG_process_sleep(sleep_test_time);
};
MSG_comm_destroy(comm);
}
}
XBT_INFO("Goodbye now!");
return 0;
} /* end_of_sender */
示例14: sender
/* Sender process expects 6 arguments: */
static int sender(int argc, char *argv[])
{
long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s"); /* - number of tasks */
double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s"); /* - computational cost */
double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s"); /* - communication cost */
long receivers_count = xbt_str_parse_int(argv[4], "Invalid amount of receivers: %s"); /* - number of receivers */
double sleep_start_time = xbt_str_parse_double(argv[5], "Invalid sleep start time: %s"); /* - start time */
double sleep_test_time = xbt_str_parse_double(argv[6], "Invalid test time: %s"); /* - test time */
XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);
int i;
msg_task_t task = NULL;
msg_comm_t comm = NULL;
MSG_process_sleep(sleep_start_time);
for (i = 0; i < number_of_tasks; i++) {
char mailbox[256];
char snprintf_buffer[256];
snprintf(mailbox,255, "receiver-%ld", i % receivers_count);
snprintf(snprintf_buffer,255, "Task_%d", i);
/* This process first creates a task and send it asynchronously with @ref MSG_task_isend. Then, if: */
task = MSG_task_create(snprintf_buffer, task_comp_size, task_comm_size, NULL);
comm = MSG_task_isend(task, mailbox);
XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);
if (sleep_test_time > 0) { /* - "test_time" is set to 0, wait on @ref MSG_comm_wait */
while (MSG_comm_test(comm) == 0) { /* - Call @ref MSG_comm_test every "test_time" otherwise */
MSG_process_sleep(sleep_test_time);
};
} else {
MSG_comm_wait(comm, -1);
}
MSG_comm_destroy(comm);
}
for (i = 0; i < receivers_count; i++) {
char mailbox[80];
snprintf(mailbox,79, "receiver-%ld", i % receivers_count);
task = MSG_task_create("finalize", 0, 0, 0);
comm = MSG_task_isend(task, mailbox);
XBT_INFO("Send to receiver-%ld finalize", i % receivers_count);
if (sleep_test_time > 0) {
while (MSG_comm_test(comm) == 0) {
MSG_process_sleep(sleep_test_time);
}
} else {
MSG_comm_wait(comm, -1);
}
MSG_comm_destroy(comm);
}
XBT_INFO("Goodbye now!");
return 0;
}
示例15: action_reduce
static void action_reduce(const char *const *action)
{
int i;
char *reduce_identifier;
char mailbox[80];
double comm_size = parse_double(action[2]);
double comp_size = parse_double(action[3]);
msg_task_t comp_task = NULL;
const char *process_name;
double clock = MSG_get_clock();
process_globals_t counters =
(process_globals_t) MSG_process_get_data(MSG_process_self());
xbt_assert(communicator_size, "Size of Communicator is not defined, "
"can't use collective operations");
process_name = MSG_process_get_name(MSG_process_self());
reduce_identifier = bprintf("reduce_%d", counters->reduce_counter++);
if (!strcmp(process_name, "p0")) {
XBT_DEBUG("%s: %s is the Root", reduce_identifier, process_name);
msg_comm_t *comms = xbt_new0(msg_comm_t, communicator_size - 1);
msg_task_t *tasks = xbt_new0(msg_task_t, communicator_size - 1);
for (i = 1; i < communicator_size; i++) {
sprintf(mailbox, "%s_p%d_p0", reduce_identifier, i);
comms[i - 1] = MSG_task_irecv(&(tasks[i - 1]), mailbox);
}
MSG_comm_waitall(comms, communicator_size - 1, -1);
for (i = 1; i < communicator_size; i++) {
MSG_comm_destroy(comms[i - 1]);
MSG_task_destroy(tasks[i - 1]);
}
xbt_free(comms);
xbt_free(tasks);
comp_task = MSG_task_create("reduce_comp", comp_size, 0, NULL);
XBT_DEBUG("%s: computing 'reduce_comp'", reduce_identifier);
MSG_task_execute(comp_task);
MSG_task_destroy(comp_task);
XBT_DEBUG("%s: computed", reduce_identifier);
} else {
XBT_DEBUG("%s: %s sends", reduce_identifier, process_name);
sprintf(mailbox, "%s_%s_p0", reduce_identifier, process_name);
XBT_DEBUG("put on %s", mailbox);
MSG_task_send(MSG_task_create(reduce_identifier, 0, comm_size, NULL),
mailbox);
}
log_action(action, MSG_get_clock() - clock);
xbt_free(reduce_identifier);
}