本文整理汇总了C++中MSG_process_sleep函数的典型用法代码示例。如果您正苦于以下问题:C++ MSG_process_sleep函数的具体用法?C++ MSG_process_sleep怎么用?C++ MSG_process_sleep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MSG_process_sleep函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dream_master
/* The Dream master: */
static int dream_master(int argc, char *argv[])
{
msg_process_t lazy = NULL;
XBT_INFO("Let's create a lazy guy."); /* - Create a lazy_guy process */
lazy = MSG_process_create("Lazy", lazy_guy, NULL, MSG_host_self());
XBT_INFO("Let's wait a little bit...");
MSG_process_sleep(10.0); /* - Wait for 10 seconds */
XBT_INFO("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!");
MSG_process_resume(lazy); /* - Then wake up the lazy_guy */
MSG_process_sleep(5.0); /* Repeat two times: */
XBT_INFO("Suspend the lazy guy while he's sleeping...");
MSG_process_suspend(lazy); /* - Suspend the lazy_guy while he's asleep */
XBT_INFO("Let him finish his siesta.");
MSG_process_sleep(10.0); /* - Wait for 10 seconds */
XBT_INFO("Wake up, lazy guy!");
MSG_process_resume(lazy); /* - Then wake up the lazy_guy again */
MSG_process_sleep(5.0);
XBT_INFO("Suspend again the lazy guy while he's sleeping...");
MSG_process_suspend(lazy);
XBT_INFO("This time, don't let him finish his siesta.");
MSG_process_sleep(2.0);
XBT_INFO("Wake up, lazy guy!");
MSG_process_resume(lazy);
XBT_INFO("OK, goodbye now.");
return 0;
}
示例2: 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 */
示例3: terrorist
/** Terrorist. This process sends a bunch of exceptions to the victim. */
static int terrorist(int argc, char *argv[])
{
msg_process_t victim_process = NULL;
XBT_INFO("Let's create a victim.");
victim_process = MSG_process_create("victim", victim, NULL, MSG_host_self());
XBT_INFO("Going to sleep for 1 second");
if (MSG_process_sleep(1) != MSG_OK)
xbt_die("What's going on??? I failed to sleep!");
XBT_INFO("Send a first exception (host failure)");
SIMIX_process_throw(victim_process, host_error, 0, "First Trick: Let's pretend that the host failed");
XBT_INFO("Sweet, let's prepare a second trick!");
XBT_INFO("Going to sleep for 2 seconds");
if (MSG_process_sleep(2) != MSG_OK)
xbt_die("What's going on??? I failed to sleep!");
XBT_INFO("Send a second exception (host failure)");
SIMIX_process_throw(victim_process, host_error, 0, "Second Trick: Let's pretend again that the host failed");
XBT_INFO("Sweet, let's prepare a third trick!");
XBT_INFO("Going to sleep for 3 seconds");
if (MSG_process_sleep(3) != MSG_OK)
xbt_die("What's going on??? I failed to sleep!");
XBT_INFO("Send a third exception (cancellation)");
SIMIX_process_throw(victim_process, cancel_error, 0, "Third Trick: Let's pretend this time that someone canceled something");
XBT_INFO("OK, goodbye now.");
return 0;
}
示例4: onoff
static int onoff(int argc, char *argv[]) {
msg_host_t host1 = MSG_host_by_name("MyHost1");
XBT_INFO("Energetic profile: %s", MSG_host_get_property_value(host1,"watt_per_state"));
XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J",
MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
XBT_INFO("Sleep for 10 seconds");
MSG_process_sleep(10);
XBT_INFO("Done sleeping. Current peak speed=%.0E; Energy dissipated=%.2f J",
MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
simulate_shutdown(host1);
XBT_INFO("Host1 is now OFF. Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
XBT_INFO("Sleep for 10 seconds");
MSG_process_sleep(10);
XBT_INFO("Done sleeping. Current peak speed=%.0E; Energy dissipated=%.2f J",
MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
simulate_bootup(host1);
XBT_INFO("Host1 is now ON again. Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
return 0;
}
示例5: test_one_task
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 [email protected]%s", hostA_name);
launch_worker(hostA, "worker0", computation_amount, 0, 0);
MSG_process_sleep(1000);
XBT_INFO("### Test: 50%% for [email protected]%s", hostA_name);
launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 2);
MSG_process_sleep(1000);
XBT_INFO("### Test: 33%% for [email protected]%s", hostA_name);
launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 3);
MSG_process_sleep(1000);
XBT_INFO("### Test: zero for [email protected]%s (i.e., unlimited)", hostA_name);
launch_worker(hostA, "worker0", computation_amount, 1, 0);
MSG_process_sleep(1000);
XBT_INFO("### Test: 200%% for [email protected]%s (i.e., meaningless)", hostA_name);
launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed * 2);
MSG_process_sleep(1000);
}
示例6: host
static int host(int argc, char *argv[])
{
char name[2048];
int id = MSG_process_self_PID();
snprintf(name,2048,"%s%i", FILENAME1, id);
msg_file_t file = MSG_file_open(name, NULL);
XBT_INFO("process %d is writing!", id);
MSG_file_write(file, 3000000);
XBT_INFO("process %d goes to sleep for %d seconds", id, id);
MSG_process_sleep(id);
XBT_INFO("process %d is writing again!", id);
MSG_file_write(file, 3000000);
XBT_INFO("process %d goes to sleep for %d seconds", id, 6 - id);
MSG_process_sleep(6-id);
XBT_INFO("process %d is reading!", id);
MSG_file_seek(file, 0, SEEK_SET);
MSG_file_read(file, 3000000);
XBT_INFO("process %d goes to sleep for %d seconds", id, id);
MSG_process_sleep(id);
XBT_INFO("process %d is reading again!", id);
MSG_file_seek(file, 0, SEEK_SET);
MSG_file_read(file, 3000000);
XBT_INFO("process %d => Size of %s: %llu", id, MSG_file_get_name(file), MSG_file_get_size(file));
MSG_file_close(file);
return 0;
}
示例7: test
int test(int argc, char **argv){
MSG_process_sleep(1);
XBT_INFO("**** Start test ****");
XBT_INFO("Free after first snapshot");
char *toto = xbt_malloc(5);
XBT_INFO("Toto allocated");
void *snap1 = MC_snapshot();
MSG_process_sleep(1);
XBT_INFO("First snapshot");
xbt_free(toto);
XBT_INFO("Toto free");
void *snap2 = MC_snapshot();
XBT_INFO("Second snapshot");
MSG_process_sleep(1);
MC_ignore_stack("snap2", "test");
MC_ignore_stack("snap1", "test");
XBT_INFO("Test result : %d (0 = state equality, 1 = different states)", MC_compare_snapshots(snap1, snap2));
XBT_INFO("**** End test ****");
xbt_abort();
}
示例8: 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;
}
示例9: emigrant
/** The guy we will move from host to host. It move alone and then is moved by policeman back */
static int emigrant(int argc, char *argv[])
{
msg_task_t task;
XBT_INFO
("I'll look for a new job on another machine where the grass is greener.");
MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin"));
XBT_INFO("Yeah, found something to do");
task = MSG_task_create("job", 98095000, 0, NULL);
MSG_task_execute(task);
MSG_task_destroy(task);
MSG_process_sleep(2);
XBT_INFO("Moving back home after work");
MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Jacquelin"));
MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin"));
MSG_process_sleep(4);
xbt_mutex_acquire(mutex);
process_to_migrate = MSG_process_self();
xbt_cond_broadcast(cond);
xbt_mutex_release(mutex);
MSG_process_suspend(MSG_process_self());
msg_host_t h = MSG_process_get_host(MSG_process_self());
XBT_INFO("I've been moved on this new host: %s", MSG_host_get_name(h));
XBT_INFO("Uh, nothing to do here. Stopping now");
return 0;
} /* end_of_emigrant */
示例10: job_requester
int job_requester(int argc, char* argv[]){
/**
@type simgrid process (run on all tiers)
Every @timeout checks amount of free (non running) cores.
If this amount is greater than some N then it sends a job request
to scheduler to get new batch of jobs.
Simgrid process parameters:
--------------------------
None
*/
std::string host_name = MSG_host_get_name(MSG_host_self());
std::string CERN = "CERN";
msg_task_t task = NULL;
double timeout = 1000;
long freeCoreAmount;
int fullCoreAmount = MSG_host_get_core_number(MSG_host_self());
MSG_process_sleep(0.01);
while (1){
freeCoreAmount = fullCoreAmount - xbt_str_parse_int(MSG_host_get_property_value(MSG_host_self(), "activeCore"), "error") -
xbt_str_parse_int(MSG_host_get_property_value(MSG_host_self(), "corruptedCore"), "error");
MSG_sem_acquire(sem_requester);
if (GLOBAL_QUEUE->empty()){
MSG_sem_release(sem_requester);
break;
}
if (freeCoreAmount > 0){
JobBatchRequest* jobRequest = new JobBatchRequest;
jobRequest->coreAmount = freeCoreAmount;
task = MSG_task_create("request", 0.0, MESSAGES_SIZE, jobRequest);
plusLinkCounter(host_name, CERN);
msg_error_t err = MSG_task_send(task, "scheduler");
switch(err){
case MSG_OK:
minusLinkCounter(host_name, CERN);
break;
case MSG_TRANSFER_FAILURE:
minusLinkCounter(host_name, CERN);
MSG_task_destroy(task);
task = NULL;
break;
case MSG_HOST_FAILURE:
MSG_task_destroy(task);
task = NULL;
break;
}
}else MSG_sem_release(sem_requester);
MSG_process_sleep(timeout);
}
return 0;
}
示例11: victim
/** Victim. This process gets a lot of remote exceptions */
static int victim(int argc, char *argv[]) {
xbt_ex_t e;
msg_error_t res = MSG_OK;
XBT_INFO("Let's work.");
TRY {
res = MSG_task_execute(MSG_task_create("Task", 1e14, 0, NULL));
if (res != MSG_OK) {
XBT_INFO("The MSG_task_execute caught the exception for me and returned %d)",res);
} else {
xbt_die("I was expecting an exception during my execution!");
}
} CATCH(e) {
XBT_INFO("The received exception resumed my execution. Good. Here is it: ----------------------->8----");
xbt_ex_display(&e);
XBT_INFO("(end of the first exception) ----8<------------------------");
xbt_ex_free(e);
}
XBT_INFO("Let's get suspended.");
int gotit = 0;
TRY {
MSG_process_suspend(MSG_process_self());
} CATCH(e) {
XBT_INFO("The received exception resumed my suspension. Good. Here is it: ----------------------->8----");
xbt_ex_display(&e);
XBT_INFO("(end of the second exception) ----8<------------------------");
gotit = 1;
xbt_ex_free(e);
}
if(!gotit) {
xbt_die("I was expecting an exception during my suspension!");
}
XBT_INFO("Let's sleep for 10 seconds.");
TRY {
res = MSG_process_sleep(10);
if (res != MSG_OK) {
XBT_INFO("The MSG_process_sleep caught the exception for me and returned %d)",res);
} else {
xbt_die("I was expecting to get an exception during my nap.");
}
} CATCH(e) {
XBT_INFO("Got the second exception: ----------------------->8----");
xbt_ex_display(&e);
XBT_INFO("(end of the third exception) ----8<------------------------");
xbt_ex_free(e);
}
XBT_INFO("Let's try a last time to do something on something");
MSG_process_sleep(10);
XBT_INFO("That's enough now. I quit.");
return 0;
}
示例12: master_main
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("Tremblay");
msg_host_t pm2 = MSG_host_by_name("Bourassa");
msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0");
MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes
MSG_vm_start(vm0);
XBT_INFO("Test: Migrate a VM with %zu Mbytes RAM", MSG_vm_get_ramsize(vm0) / 1000 / 1000);
vm_migrate(vm0, pm1);
MSG_vm_destroy(vm0);
vm0 = MSG_vm_create_core(pm0, "VM0");
MSG_vm_set_ramsize(vm0, 1e8); // 100Mbytes
MSG_vm_start(vm0);
XBT_INFO("Test: Migrate a VM with %zu Mbytes RAM", MSG_vm_get_ramsize(vm0) / 1000 / 1000);
vm_migrate(vm0, pm1);
MSG_vm_destroy(vm0);
vm0 = MSG_vm_create_core(pm0, "VM0");
msg_vm_t vm1 = MSG_vm_create_core(pm0, "VM1");
MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes
MSG_vm_set_ramsize(vm1, 1e9); // 1Gbytes
MSG_vm_start(vm0);
MSG_vm_start(vm1);
XBT_INFO("Test: Migrate two VMs at once from PM0 to PM1");
vm_migrate_async(vm0, pm1);
vm_migrate_async(vm1, pm1);
MSG_process_sleep(10000);
MSG_vm_destroy(vm0);
MSG_vm_destroy(vm1);
vm0 = MSG_vm_create_core(pm0, "VM0");
vm1 = MSG_vm_create_core(pm0, "VM1");
MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes
MSG_vm_set_ramsize(vm1, 1e9); // 1Gbytes
MSG_vm_start(vm0);
MSG_vm_start(vm1);
XBT_INFO("Test: Migrate two VMs at once to different PMs");
vm_migrate_async(vm0, pm1);
vm_migrate_async(vm1, pm2);
MSG_process_sleep(10000);
MSG_vm_destroy(vm0);
MSG_vm_destroy(vm1);
return 0;
}
示例13: 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;
}
示例14: slave
static int slave(int argc, char *argv[])
{
MSG_process_sleep(.5);
XBT_INFO("Slave started (PID:%d, PPID:%d)", MSG_process_self_PID(), MSG_process_self_PPID());
while(1) {
XBT_INFO("Plop i am %ssuspended", (MSG_process_is_suspended(MSG_process_self())) ? "" : "not ");
MSG_process_sleep(1);
}
XBT_INFO("I'm done. See you!");
return 0;
}
示例15: client
static int client(int argc, char *argv[])
{
int my_pid = MSG_process_get_PID(MSG_process_self());
char *my_mailbox = xbt_strdup(argv[1]);
msg_task_t grant = NULL, release = NULL;
while(1){
XBT_INFO("Ask the request");
MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
if(strcmp(my_mailbox, "1") == 0){
r = 1;
cs = 0;
XBT_INFO("Propositions changed : r=1, cs=0");
}
MSG_task_receive(&grant, my_mailbox);
const char *kind = MSG_task_get_name(grant);
if((strcmp(my_mailbox, "1") == 0) && (strcmp("grant", kind) == 0)){
cs = 1;
r = 0;
XBT_INFO("Propositions changed : r=0, cs=1");
}
MSG_task_destroy(grant);
grant = NULL;
kind = NULL;
XBT_INFO("%s got the answer. Sleep a bit and release it", argv[1]);
MSG_process_sleep(1);
release = MSG_task_create("release", 0, 1000, NULL);
MSG_task_send(release, "coordinator");
release = NULL;
MSG_process_sleep(my_pid);
if(strcmp(my_mailbox, "1") == 0){
cs=0;
r=0;
XBT_INFO("Propositions changed : r=0, cs=0");
}
}
return 0;
}