/* 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;
}
Example #2
0
/** 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 */
Example #3
0
/** 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;
}
Example #4
0
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;
}
Example #5
0
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 Task1@%s", hostA_name);
  launch_worker(hostA, "worker0", computation_amount, 0, 0);

  MSG_process_sleep(1000);

  XBT_INFO("### Test: 50%% for Task1@%s", hostA_name);
  launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 2);

  MSG_process_sleep(1000);

  XBT_INFO("### Test: 33%% for Task1@%s", hostA_name);
  launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed / 3);

  MSG_process_sleep(1000);

  XBT_INFO("### Test: zero for Task1@%s (i.e., unlimited)", hostA_name);
  launch_worker(hostA, "worker0", computation_amount, 1, 0);

  MSG_process_sleep(1000);

  XBT_INFO("### Test: 200%% for Task1@%s (i.e., meaningless)", hostA_name);
  launch_worker(hostA, "worker0", computation_amount, 1, cpu_speed * 2);

  MSG_process_sleep(1000);
}
Example #6
0
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;
}
Example #7
0
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();
}
Example #8
0
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;
}
Example #9
0
/** 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 */
Example #10
0
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;
}
Example #11
0
/** 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;
}
Example #12
0
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;
}
Example #13
0
/* 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;
}
Example #14
0
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;
}
Example #15
0
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;
}
Example #16
0
/** Receiver function  */
int receiver(int argc, char *argv[])
{
  m_task_t task = NULL;
  MSG_error_t res;
  int id = -1;
  char mailbox[80];
  msg_comm_t res_irecv;
  double sleep_start_time = atof(argv[2]);
  double sleep_test_time = atof(argv[3]);
  XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time,
        sleep_test_time);

  int read;
  read = sscanf(argv[1], "%d", &id);
  xbt_assert(read,
              "Invalid argument %s\n", argv[1]);

  MSG_process_sleep(sleep_start_time);

  sprintf(mailbox, "receiver-%d", id);
  while (1) {
    res_irecv = MSG_task_irecv(&(task), mailbox);
    XBT_INFO("Wait to receive a task");

    if (sleep_test_time == 0) {
      res = MSG_comm_wait(res_irecv, -1);
      xbt_assert(res == MSG_OK, "MSG_task_get failed");
    } else {
      while (MSG_comm_test(res_irecv) == 0) {
        MSG_process_sleep(sleep_test_time);
      };
      MSG_comm_destroy(res_irecv);
    }

    XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
    if (!strcmp(MSG_task_get_name(task), "finalize")) {
      MSG_task_destroy(task);
      break;
    }

    XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
    MSG_task_execute(task);
    XBT_INFO("\"%s\" done", MSG_task_get_name(task));
    MSG_task_destroy(task);
    task = NULL;
  }
  XBT_INFO("I'm done. See you!");
  return 0;
}                               /* end_of_receiver */
Example #17
0
static int master(int argc, char *argv[])
{
  msg_process_t process;

  XBT_INFO("Start slave");
  process =  MSG_process_create("slave from master", slave, NULL, MSG_host_self());
  XBT_INFO("Join the slave (timeout 2)");
  MSG_process_join(process, 2);

  XBT_INFO("Start slave");
  process =  MSG_process_create("slave from master", slave, NULL, MSG_host_self());
  XBT_INFO("Join the slave (timeout 4)");
  MSG_process_join(process, 4);

  XBT_INFO("Start slave");
  process =  MSG_process_create("slave from master", slave, NULL, MSG_host_self());
  XBT_INFO("Join the slave (timeout 2)");
  MSG_process_join(process, 2);

  XBT_INFO("Goodbye now!");

  MSG_process_sleep(1);

  XBT_INFO("Goodbye now!");
  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;
}
Example #19
0
static void simcreat(const char *const *action) {
  const char *processid = action[0];
  const char *worktime = action[3];
  double sleeptime;
  const char *index = action[4];
  char full_name[1024];
  msg_file_t file = NULL;
  double clock = MSG_get_clock();       /* this "call" is free thanks to inlining */
  sleeptime = atof(worktime);
  MSG_process_sleep(sleeptime);
  //open slow file
  const char *file_name = action[2];
  char fn[200];
   strcpy(fn,file_name);
  ReplaceStr(fn,"/home","/slow");
  sprintf(full_name, "%s:%s:%s:%s","slow",file_name,MSG_process_get_name(MSG_process_self()), index);
  ACT_DEBUG("Entering Creat: %s (filename: %s)", NAME, file_name);
  file = MSG_file_open(fn, NULL);
  xbt_dict_set(opened_files, full_name, file, NULL);
  //open fast version of file
  strcpy(fn,file_name);
  ReplaceStr(fn,"/home","/fast");
  sprintf(full_name, "%s:%s:%s:%s","fast",file_name,MSG_process_get_name(MSG_process_self()), index);
  ACT_DEBUG("Entering Creat: %s (filename: %s)", NAME, file_name);
  file = MSG_file_open(fn, NULL);
  xbt_dict_set(opened_files, full_name, file, NULL);
  
  log_action(action, MSG_get_clock() - clock);
  XBT_INFO("creat worker %s %s is done",processid,index);
}
Example #20
0
static int master(int argc, char *argv[])
{
  XBT_INFO("Hello!");
  MSG_process_sleep(10.0);
  XBT_INFO("OK, goodbye now.");
  return 0;
}                               /* end_of_dram_master */
Example #21
0
/** Lazy guy function. This process suspends itself asap.  */
static int slave(int argc, char *argv[])
{
  XBT_INFO("Hello!");
  MSG_process_sleep(10.0);
  XBT_INFO("OK, goodbye now.");
  return 0;
}                               /* end_of_lazy_guy */
Example #22
0
static int client(int argc, char *argv[])
{
  int my_pid = MSG_process_get_PID(MSG_process_self());
  char *my_mailbox = xbt_strdup(argv[1]);

  while(1){
    XBT_INFO("Client (%s) asks the request", my_mailbox);
    MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");

    msg_task_t answer = NULL;
    MSG_task_receive(&answer, my_mailbox);

    const char* kind = MSG_task_get_name(answer);

    if (!strcmp(kind, "grant")) {
      XBT_INFO("Client (%s) got the answer (grant). Sleep a bit and release it", my_mailbox);
      if(!strcmp(my_mailbox, "1"))
        cs = 1;
    }else{
      XBT_INFO("Client (%s) got the answer (not grant). Try again", my_mailbox);
    }

    MSG_task_destroy(answer);
    kind = NULL;

    MSG_process_sleep(my_pid);
  }
  return 0;
}
Example #23
0
static void simopen(const char *const *action) {
  const char *processid = action[0];
  const char *worktime = action[3];
  double sleeptime;
  const char *index = action[4];
  char full_name[1024];
  msg_file_t file = NULL;
  double clock = MSG_get_clock();       /* this "call" is free thanks to inlining */
  //Because the action open is too fast ,to catch up with the clock of the simulator, we let it to sleep for a while.
  sleeptime = atof(worktime);
  MSG_process_sleep(sleeptime);
  //open slow filename
  const char *file_name = action[2];
  char fn[200];
   strcpy(fn,file_name);
  ReplaceStr(fn,"/home","/slow");
  sprintf(full_name, "%s:%s:%s:%s","slow",file_name,MSG_process_get_name(MSG_process_self()),index);
  ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name);
  file = MSG_file_open(fn, NULL);
  xbt_dict_set(opened_files, full_name, file, NULL);
  //open fast filename
   strcpy(fn,file_name);
  ReplaceStr(fn,"/home","/fast");
  sprintf(full_name, "%s:%s:%s:%s","fast",file_name,MSG_process_get_name(MSG_process_self()),index);
  ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name);
  file = MSG_file_open(fn, NULL);
  xbt_dict_set(opened_files, full_name, file, NULL);
 
  log_action(action, MSG_get_clock() - clock);
  XBT_INFO("open worker %s%s is done",processid,index);
}
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;
}
Example #25
0
int service_controller(int argc,char *argv[]){
    int count = argc-1;
    char **arg=(char **)calloc(count,sizeof(char*));
    int process_number = atoi(argv[1]);
    m_process_t process_list[process_number];
    arg[0] = strdup("service");
    int i;
    for(i=2;i<argc;i++){
	arg[i-1] = strdup(argv[i]);
    }
    
    XBT_INFO("initializing service: %s",arg[1]);
    for(i=2;i<count;i=i+3)
	XBT_INFO("method:%s,time to exec:  %s,output size: %s",arg[i],arg[i+1],arg[i+2]);

    //create a number of process
    for(i=0;i<process_number;i++){
	process_list[i] = MSG_process_create_with_arguments(arg[0],service,NULL,MSG_host_self(),count,arg);
    }
    MSG_process_sleep(MAX_TIME_SIMULATION);    
    //kill all process in process_list
    for(i=0;i<process_number;i++){
	MSG_process_kill(process_list[i]);
    }
}
Example #26
0
static int slave(int argc, char *argv[])
{
  XBT_INFO("Slave started");
  MSG_process_sleep(3);
  XBT_INFO("I'm done. See you!");
  return 0;
}
Example #27
0
static int process_code(int argc, char *argv[])
{
  msg_task_t task1 = NULL;
  double cpu_task = 0;
  double task_time = MSG_get_clock();

  if (argc == 2)
  {
	  /* Run a sleep task */
	  double sleep_task = atof(argv[1]);

	  MSG_process_sleep(sleep_task);
	  task_time = MSG_get_clock() - task_time;
	  XBT_INFO("Process %s executed task sleep cpu=%f, duration = %f",
			  MSG_process_get_name(MSG_process_self()), 0.0, task_time);
	  XBT_INFO("==================================================");
 }


  // Run a task
  cpu_task = atof(argv[0]);
  task1 = MSG_task_create ("task", cpu_task, 0, NULL);
  MSG_task_execute (task1);
  MSG_task_destroy(task1);

  task_time = MSG_get_clock() - task_time;
  XBT_INFO("Process %s executed task cpu=%f, duration = %f",
		  MSG_process_get_name(MSG_process_self()), cpu_task, task_time);
  XBT_INFO("==================================================");
  return 0;
}
Example #28
0
/** 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);
  }
Example #29
0
int client (int argc, char * argv[]) {
	//printf("starting client\n");
	int i;
	unsigned long int id;
	char myMailbox[MAILBOX_SIZE];
	char primary[MAILBOX_SIZE]; // when we use the decentrlized solution, the client send its request to the first-primary. (However the code is the same, we just change in the xml file the identity of the primary by the identity of the first-primary)

	if (argc != 3) {
		//printf("here in the client\n");
		exit(1);
	}

	id = atoi(argv[1]);
	sprintf(myMailbox, "client-%ld", id);
	// the name of the primary is known by the client
	strcpy(primary, argv[2]);

	srand(time(NULL) * id + MSG_get_clock());

	for (i = 0; i < nb_requests; i++) {
		MSG_process_sleep(((double)(rand () % 1000001)) / 1000.0);
		
		//send a request to the primary
		send_task(i, primary, myMailbox);		

		// wait for the result of the request before sending an other one
		receive_answer(myMailbox);
	}
	
	// signal to the primary that there is no more tasks to treat for that client
	//printf("%s: I send finalize\n", myMailbox);
	send_finalize(primary);

	return 0;
}
/** Receiver function  */
int slave(int argc, char *argv[])
{
  m_task_t task = NULL;
  int res;
  int id = -1;

  xbt_assert1(sscanf(argv[1],"%d", &id),
	 "Invalid argument %s\n",argv[1]);

  MSG_process_sleep(1); /* Make sure the master is done creating the mailboxes */
   
  while(1) {
    res = MSG_mailbox_get_task_ext(mb[id], &(task), NULL, -1);
    xbt_assert0(res == MSG_OK, "MSG_task_get failed");

    INFO1("Received \"%s\"", MSG_task_get_name(task));
    if (!strcmp(MSG_task_get_name(task),"finalize")) {
	MSG_task_destroy(task);
	break;
    }
     
    INFO1("Processing \"%s\"", MSG_task_get_name(task));
    MSG_task_execute(task);
    INFO1("\"%s\" done", MSG_task_get_name(task));
    MSG_task_destroy(task);
    task = NULL;
  }
  INFO0("I'm done. See you!");
  return 0;
} /* end_of_slave */