Exemplo n.º 1
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;
}
Exemplo n.º 2
0
/** Main function */
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;
  long i;

  MSG_init(&argc, argv);
  if (argc < 4) {
    printf("Usage: %s platform_file number_of_jobs number_of_slaves\n", argv[0]);
    printf("example: %s msg_platform.xml 10 5\n", argv[0]);
    exit(1);
  }

  MSG_function_register("master", master);
  MSG_function_register("slave", slave);

  MSG_create_environment(argv[1]);

  number_of_jobs = atol(argv[2]);
  number_of_slaves = atol(argv[3]);
  xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
  long number_max = xbt_dynar_length(host_dynar);
  XBT_INFO("Got %ld slaves, %ld tasks to process, and %ld hosts", number_of_slaves, number_of_jobs,number_max);

  msg_host_t *host_table =  xbt_dynar_to_array(host_dynar);
  //xbt_dynar_free(&host_dynar);

  MSG_process_create( "master",
                      master,
                      NULL,
                      host_table[my_random(number_max)]
                      );

  for(i = 0 ; i<number_of_slaves; i++)
  {
    char* name_host = bprintf("slave-%ld",i);
      MSG_process_create( name_host,
                          slave,
                          NULL,
                          host_table[my_random(number_max)]
                          );
      free(name_host);
  }
  xbt_free(host_table);

  res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());

  if (res == MSG_OK)
    return 0;
  else
    return 1;
}                               /* end_of_main */
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);
  MSG_process_create("simple_func", process_function, NULL, MSG_get_host_by_name("Tremblay"));
  MSG_process_create("simple_func", process_function, NULL, MSG_get_host_by_name("Fafard"));

  MSG_main();
  return 0;
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;

  MSG_init(&argc, argv);

  MSG_create_environment(argv[1]);

  MSG_process_create("send", sender_fun, NULL, MSG_get_host_by_name("Tremblay"));
  MSG_process_create("receive", receiver_fun, NULL, MSG_get_host_by_name("Tremblay"));

  res = MSG_main();
  return res != MSG_OK;
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
  int i,res;
  MSG_init(&argc, argv);
  MSG_create_environment(argv[1]);
  xbt_dynar_t hosts =  MSG_hosts_as_dynar();
  MSG_function_register("host", host);
  unsigned long nb_hosts = xbt_dynar_length(hosts);
  XBT_INFO("Number of host '%lu'",nb_hosts);
  for(i = 0 ; i<nb_hosts; i++)
  {
    char* name_host = bprintf("%d",i);
    MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,msg_host_t) );
    free(name_host);
  }
  xbt_dynar_free(&hosts);

  res = MSG_main();
  XBT_INFO("Simulation time %g", MSG_get_clock());
  if (res == MSG_OK)
    return 0;
  else
    return 1;

}
Exemplo n.º 6
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;
}
Exemplo n.º 7
0
int main(int argc, char **argv)
{
  int i;
  msg_error_t res = MSG_OK;

  MSG_init(&argc, argv);
  surf_parse = surf_parse_bypass_platform;
  MSG_create_environment(NULL);

  MSG_function_register("host", host);

  xbt_dynar_t hosts = MSG_hosts_as_dynar();
  nb_hosts =  xbt_dynar_length(hosts);

  XBT_INFO("Number of host '%d'",nb_hosts);
  for(i = 0 ; i<nb_hosts; i++)
  {
    char* name_host = bprintf("%d",i);
    MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,msg_host_t) );
    free(name_host);
  }
  xbt_dynar_free(&hosts);

  res = MSG_main();
  XBT_INFO("Simulation time %g", MSG_get_clock());

  if (res == MSG_OK)
    return 0;
  else
    return 1;

}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
/** 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 @ref lazy_guy process */
  lazy = MSG_process_create("Lazy", lazy_guy, NULL, MSG_host_self());
  XBT_INFO("Let's wait a little bit...");
  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 @ref lazy_guy */

  SLEEP(5.0);                           /** Repeat two times: */
  XBT_INFO("Suspend the lazy guy while he's sleeping...");
  MSG_process_suspend(lazy);            /** - Suspend the @ref lazy_guy while he's asleep */
  XBT_INFO("Let him finish his siesta.");
  SLEEP(10.0);                          /** - Wait for 10 seconds */
  XBT_INFO("Wake up, lazy guy!");
  MSG_process_resume(lazy);             /** - Then wake up the @ref lazy_guy again */

  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.");
  SLEEP(2.0);
  XBT_INFO("Wake up, lazy guy!");
  MSG_process_resume(lazy);

  XBT_INFO("OK, goodbye now.");
  return 0;
}
Exemplo n.º 10
0
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);

  MSG_process_create("master", master, NULL, MSG_get_host_by_name("Tremblay"));
  MSG_process_create("worker", worker, NULL, MSG_get_host_by_name("Jupiter"));

  msg_error_t res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());

  return res != MSG_OK;
}
Exemplo n.º 11
0
int main(int argc, char* argv[])
{
  MSG_init(&argc, argv);

  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);

  MSG_process_create("dvfs_test", dvfs, NULL, MSG_get_host_by_name("MyHost1"));
  MSG_process_create("dvfs_test", dvfs, NULL, MSG_get_host_by_name("MyHost2"));

  msg_error_t res = MSG_main();

  XBT_INFO("Total simulation time: %e", MSG_get_clock());

  return res != MSG_OK;
}
Exemplo n.º 12
0
/** Main function */
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  MSG_function_register("app", &app);
  MSG_create_environment(argv[1]);
  MSG_process_create("app", app, NULL, MSG_get_host_by_name("Tremblay"));
  return MSG_main();
}
Exemplo n.º 13
0
/**
 * Main function
 * Create the platform, list the available hosts and give them some work
 */
int main(int argc, char **argv) {

  unsigned long seed[] = {134, 233445, 865, 2634, 424242, 876543};
  int connected;
  int max_tries = 10;

  //MSG initialization
  MSG_init(&argc, argv);

  //Set up the seed for the platform generation
  platf_random_seed(seed);

  XBT_INFO("creating nodes...");
  platf_graph_uniform(50);
  do {
    max_tries--;
    XBT_INFO("creating links...");
    platf_graph_clear_links();
    platf_graph_interconnect_uniform(0.07); //Unrealistic, but simple
    XBT_INFO("done. Check connectedness...");
    connected = platf_graph_is_connected();
    XBT_INFO("Is it connected : %s", connected ? "yes" : (max_tries ? "no, retrying" : "no"));
  } while(!connected && max_tries);

  if(!connected && !max_tries) {
    xbt_die("Impossible to connect the graph, aborting.");
  }

  XBT_INFO("registering callbacks...");
  platf_graph_promoter(promoter_1);
  platf_graph_labeler(labeler_1);

  XBT_INFO("protmoting...");
  platf_do_promote();

  XBT_INFO("labeling...");
  platf_do_label();

  XBT_INFO("Putting it in surf...");
  platf_generate();

  XBT_INFO("Let's get the available hosts and dispatch work:");

  unsigned int i;
  msg_host_t host = NULL;
  msg_host_t host_master = NULL;
  xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
  char** hostname_list = xbt_malloc(sizeof(char*) * xbt_dynar_length(host_dynar));

  xbt_dynar_foreach(host_dynar, i, host) {
    MSG_process_create("slave", slave, NULL, host);
    if(i==0) {
      //The first node will also be the master
      XBT_INFO("%s will be the master", MSG_host_get_name(host));
      host_master = host;
    }
    hostname_list[i] = (char*) MSG_host_get_name(host);
  }
Exemplo n.º 14
0
int master_fun(int argc, char *argv[])
{
  msg_vm_t vm;
  unsigned int i;

  xbt_dynar_t worker_pms = MSG_process_get_data(MSG_process_self());
  int nb_workers = xbt_dynar_length(worker_pms);

  xbt_dynar_t vms = xbt_dynar_new(sizeof(msg_vm_t), NULL);


  /* Launch VMs and worker processes. One VM per PM, and one worker process per VM. */

  XBT_INFO("# Launch %d VMs", nb_workers);
  for (i = 0; i< nb_workers; i++) {
    char *vm_name = bprintf("VM%02d", i);
    char *pr_name = bprintf("WRK%02d", i);

    msg_host_t pm = xbt_dynar_get_as(worker_pms, i, msg_host_t);

    XBT_INFO("create %s on PM(%s)", vm_name, MSG_host_get_name(pm));
    msg_vm_t vm = MSG_vm_create_core(pm, vm_name);

    s_vm_params_t params;
    memset(&params, 0, sizeof(params));
    params.ramsize = 1L * 1024 * 1024 * 1024; // 1Gbytes
    MSG_host_set_params(vm, &params);

    MSG_vm_start(vm);
    xbt_dynar_push(vms, &vm);

    XBT_INFO("put a process (%s) on %s", pr_name, vm_name);
    MSG_process_create(pr_name, worker_fun, NULL, vm);

    xbt_free(vm_name);
    xbt_free(pr_name);
  }


  /* Send a bunch of work to every one */
  XBT_INFO("# Send a task to %d worker process", nb_workers);
  send_tasks(nb_workers);

  XBT_INFO("# Suspend all VMs");
  xbt_dynar_foreach(vms, i, vm) {
    const char *vm_name = MSG_host_get_name(vm);
    XBT_INFO("suspend %s", vm_name);
    MSG_vm_suspend(vm);
  }

  XBT_INFO("# Wait a while");
  MSG_process_sleep(2);

  XBT_INFO("# Resume all VMs");
  xbt_dynar_foreach(vms, i, vm) {
    MSG_vm_resume(vm);
  }
Exemplo n.º 15
0
int main(int argc, char *argv[])
{
   MSG_init(&argc, argv);
   xbt_assert(argc==2);
   MSG_create_environment(argv[1]);
   MSG_process_create("test", server, NULL, MSG_host_by_name("Tremblay"));
   MSG_main();

   return 0;
}
Exemplo n.º 16
0
static void test_dynamic_change(void)
{
  msg_host_t pm0 = MSG_host_by_name("Fafard");

  msg_host_t vm0 = MSG_vm_create_core(pm0, "VM0");
  msg_host_t vm1 = MSG_vm_create_core(pm0, "VM1");
  MSG_vm_start(vm0);
  MSG_vm_start(vm1);

  msg_task_t task0 = MSG_task_create("Task0", DOUBLE_MAX, 0, NULL);
  msg_task_t task1 = MSG_task_create("Task1", DOUBLE_MAX, 0, NULL);
  MSG_process_create("worker0", worker_busy_loop_main, &task0, vm0);
  MSG_process_create("worker1", worker_busy_loop_main, &task1, vm1);

  double task0_remain_prev = MSG_task_get_flops_amount(task0);
  double task1_remain_prev = MSG_task_get_flops_amount(task1);

  const double cpu_speed = MSG_host_get_speed(pm0);
  for (int i = 0; i < 10; i++) {
    double new_bound = (cpu_speed / 10) * i;
    XBT_INFO("set bound of VM1 to %f", new_bound);
    MSG_vm_set_bound(vm1, new_bound);
    MSG_process_sleep(100);

    double task0_remain_now = MSG_task_get_flops_amount(task0);
    double task1_remain_now = MSG_task_get_flops_amount(task1);

    double task0_flops_per_sec = task0_remain_prev - task0_remain_now;
    double task1_flops_per_sec = task1_remain_prev - task1_remain_now;

    XBT_INFO("Task0@VM0: %f flops/s", task0_flops_per_sec / 100);
    XBT_INFO("Task1@VM1: %f flops/s", task1_flops_per_sec / 100);

    task0_remain_prev = task0_remain_now;
    task1_remain_prev = task1_remain_now;
  }

  MSG_process_sleep(2000); // let the tasks end

  MSG_vm_destroy(vm0);
  MSG_vm_destroy(vm1);
}
Exemplo n.º 17
0
  xbt_dynar_foreach(vms, i, vm) {
    unsigned int index = i + xbt_dynar_length(vms);
    char *vm_name = bprintf("VM%02d", i);
    char *pr_name = bprintf("WRK%02d", index);

    XBT_INFO("put a process (%s) on %s", pr_name, vm_name);
    MSG_process_create(pr_name, worker_fun, NULL, vm);

    xbt_free(vm_name);
    xbt_free(pr_name);
  }
Exemplo n.º 18
0
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  MSG_config("host/model", "ptask_L07");
  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../examples/platforms/two_hosts.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);

  MSG_process_create("sequential", seq_task, NULL, MSG_get_host_by_name("Tremblay"));

  MSG_process_create("parallel", par_task, NULL, MSG_get_host_by_name("Tremblay"));

  // Create a process to test in progress task
  MSG_process_create("get_progress", get_progress, NULL, MSG_get_host_by_name("Tremblay"));

  msg_error_t res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());

  return res != MSG_OK;
}
Exemplo n.º 19
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);
  }
Exemplo n.º 20
0
int main(int argc, char **argv)
{
  MSG_init(&argc, argv);
  MSG_create_environment(argv[1]);

  MSG_function_register("host", host);
  for(int i = 0 ; i < 5; i++){
    MSG_process_create("bob", host, NULL, MSG_host_by_name(xbt_strdup("bob")));
  }

  int res = MSG_main();
  XBT_INFO("Simulation time %g", MSG_get_clock());

  return res != MSG_OK;
}
Exemplo n.º 21
0
static int killer(int argc, char *argv[])
{
  XBT_INFO("Hello!");         /* - First start a victim process */
  msg_process_t poor_victim = MSG_process_create("victim", victim, NULL, MSG_host_by_name("Fafard"));
  MSG_process_sleep(10.0);

  XBT_INFO("Resume process"); /* - Resume it from its suspended state */
  MSG_process_resume(poor_victim);

  XBT_INFO("Kill process");   /* - and then kill it */
  MSG_process_kill(poor_victim);

  XBT_INFO("OK, goodbye now.");
  return 0;
}
Exemplo n.º 22
0
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;

  MSG_init(&argc, argv);
  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);   /* - Load the platform description */
  /* - Create and deploy killer process, that will create the victim process  */
  MSG_process_create("killer", killer, NULL, MSG_host_by_name("Tremblay"));

  res = MSG_main();                 /* - Run the simulation */

  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res != MSG_OK;
}
Exemplo n.º 23
0
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;

  MSG_init(&argc, argv);
  xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);  /** - Load the platform description */
  MSG_function_register("dream_master", dream_master); /** - Create and deploy the @ref dream_master */
  xbt_dynar_t hosts = MSG_hosts_as_dynar();
  MSG_process_create("dream_master", dream_master, NULL, xbt_dynar_getfirst_as(hosts, msg_host_t));
  xbt_dynar_free(&hosts);
  res = MSG_main();                 /** - Run the simulation */

  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res != MSG_OK;
}
Exemplo n.º 24
0
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;
  sg_energy_plugin_init();
  MSG_init(&argc, argv);

  xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);

  MSG_process_create("dvfs",dvfs,NULL,MSG_host_by_name("MyHost1"));

  res = MSG_main();

  XBT_INFO("Total simulation time: %.2f; All hosts must have the exact same energy consumption.", MSG_get_clock());

  return res != MSG_OK;
}
Exemplo n.º 25
0
/** Test function */
msg_error_t test_all(const char *platform_file)
{
  msg_error_t res = MSG_OK;
  xbt_dynar_t all_hosts;
  msg_host_t first_host;

  MSG_config("host/model", "ptask_L07");
  MSG_create_environment(platform_file);

  all_hosts = MSG_hosts_as_dynar();
  first_host = xbt_dynar_getfirst_as(all_hosts,msg_host_t);
  MSG_process_create("test", test, NULL, first_host);
  res = MSG_main();
  xbt_dynar_free(&all_hosts);

  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res;
}
Exemplo n.º 26
0
int main(int argc, char **argv)
{
  int res;
  xbt_dynar_t all_hosts;
  msg_host_t first_host;
  MSG_init(&argc, argv);
  MSG_create_environment(argv[1]);
  MSG_function_register("host", host);
  all_hosts = MSG_hosts_as_dynar();
  first_host = xbt_dynar_pop_as(all_hosts,msg_host_t);
  MSG_process_create( "host", host, NULL, first_host);
  xbt_dynar_free(&all_hosts);

  res = MSG_main();
  XBT_INFO("Simulation time %g", MSG_get_clock());

  if (res == MSG_OK)
    return 0;
  else
    return 1;
}
Exemplo n.º 27
0
int data_replicator(int argc, char* argv[]){
	/**
		@type simgrid process
		Launches `uploader` processes to replicate output files. 

		Simgrid process parameters
		--------------------------
		Job* replica (job descriptor) -- contains all information about
		job parameters (type, size, etc.)
	*/

    Job* replica = (Job*) MSG_process_get_data(MSG_process_self());
    size_t output_files = replica->OutputFiles.size();

    for (size_t k = 0; k < output_files; ++k) {

        InputFile* infl;
        try {
            infl = FILES_DATABASE->at(replica->OutputFiles.at(k));
        }catch (std::out_of_range& e){
            continue;
        }

        const std::vector<std::string>& replica_locations = infl->Storages;

        for (size_t i = 0; i < replica_locations.size(); ++i) {
            UploadData* data = new UploadData;
            data->filename = replica->OutputFiles.at(k);
            data->dest = replica_locations.at(i);

            MSG_process_create("upload", uploader, data, MSG_host_self());
        }
    }

    MSG_process_sleep(1.1);
    delete replica;
    return 0;
}
Exemplo n.º 28
0
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  MSG_config("host/model", "ptask_L07");

  xbt_assert(argc <= 3, "1Usage: %s <platform file> [--energy]", argv[0]);
  xbt_assert(argc >= 2, "2Usage: %s <platform file> [--energy]", argv[0]);

  if(argc == 3 && argv[2][2] == 'e')
    sg_energy_plugin_init();

  MSG_create_environment(argv[1]);

  /* Pick a process, no matter which, from the platform file */
  xbt_dynar_t all_hosts = MSG_hosts_as_dynar();
  msg_host_t first_host = xbt_dynar_getfirst_as(all_hosts,msg_host_t);
  xbt_dynar_free(&all_hosts);

  MSG_process_create("test", runner, NULL, first_host);
  msg_error_t res = MSG_main();
  XBT_INFO("Simulation done.");

  return res != MSG_OK;
}
Exemplo n.º 29
0
static int dvfs(int argc, char *argv[])
{
  msg_host_t host1 = MSG_host_by_name("MyHost1");
  msg_host_t host2 = MSG_host_by_name("MyHost2");
  msg_host_t host3 = MSG_host_by_name("MyHost3");

  /* Host 1 */
  XBT_INFO("Creating and starting two VMs");
  msg_vm_t vm_host1 = MSG_vm_create(host1, "vm_host1", 4, 2048, 100, NULL, 1024 * 20, 10,50);
  MSG_vm_start(vm_host1);
  msg_vm_t vm_host3 = MSG_vm_create(host3, "vm_host3", 4, 2048, 100, NULL, 1024 * 20, 10,50);
  MSG_vm_start(vm_host3);

  XBT_INFO("Create two tasks on Host1: one inside a VM, the other directly on the host");
  MSG_process_create("p11", worker_func, NULL, vm_host1);
  MSG_process_create("p12", worker_func, NULL, host1);

  XBT_INFO("Create two tasks on Host2: both directly on the host");
  MSG_process_create("p21", worker_func, NULL, host2);
  MSG_process_create("p22", worker_func, NULL, host2);

  XBT_INFO("Create two tasks on Host3: both inside a VM");
  MSG_process_create("p31", worker_func, NULL, vm_host3);
  MSG_process_create("p32", worker_func, NULL, vm_host3);

  XBT_INFO("Wait 5 seconds. The tasks are still running (they run for 3 seconds, but 2 tasks are co-located, "
           "so they run for 6 seconds)");
  MSG_process_sleep(5);
  XBT_INFO("Wait another 5 seconds. The tasks stop at some point in between");
  MSG_process_sleep(5);

  MSG_vm_shutdown(vm_host1);
  MSG_vm_shutdown(vm_host3);
  MSG_vm_destroy(vm_host1);
  MSG_vm_destroy(vm_host3);

  return 0;
}
Exemplo n.º 30
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 */