// FIXME: don't mess with MSG internals here, use MSG_process_create_with_arguments()
static void rb_process_create_with_args(VALUE fct_name, VALUE arguments,
                                        VALUE properties, VALUE ht_name)
{
  VALUE ruby_process =
      rb_process_instance(fct_name, arguments, properties);

  m_process_t process = NULL;          // Native Process to Create
  const char *name;             // Name of C Native Processs


  if (!fct_name)
    rb_raise(rb_eRuntimeError,
             "Internal error: Process name cannot be NULL");
  name = RSTRING_PTR(fct_name);
  XBT_DEBUG("Create native process %s", name);

  char **argv = xbt_new(char *, 2);
  argv[0] = bprintf("%s@%s", name, RSTRING_PTR(ht_name));
  argv[1] = NULL;

  // Allocate the data for the simulation
  process = MSG_process_create_with_arguments(name,
      (xbt_main_func_t) ruby_process,
      process,
      MSG_get_host_by_name(RSTRING_PTR(ht_name)),
      1, argv);
  // Bind The Ruby Process instance to The Native Process
  rb_process_bind(ruby_process, process);
}
Exemplo n.º 2
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]);
    }
}
Exemplo n.º 3
0
static void launch_master(msg_host_t host)
{
  const char *pr_name = "master_";
  char **argv = xbt_new(char *, 2);
  argv[0] = xbt_strdup(pr_name);
  argv[1] = NULL;

  MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
}
Exemplo n.º 4
0
static void launch_computation_worker(msg_host_t host)
{
  const char *pr_name = "compute";
  char **argv = xbt_new(char *, 2);
  argv[0] = xbt_strdup(pr_name);
  argv[1] = NULL;

  MSG_process_create_with_arguments(pr_name, computation_fun, NULL, host, 1, argv);
}
Exemplo n.º 5
0
static int dvfs(int argc, char *argv[])
{
  msg_host_t host = NULL;
  double task_time = 0;
  host = MSG_host_self();

  double current_peak = MSG_get_host_current_power_peak(host);

  XBT_INFO("Current power peak=%f", current_peak);
  double consumed_energy = MSG_get_host_consumed_energy(host);
  XBT_INFO("Total energy (Joules): %f", consumed_energy);

  // Process 1 - long CPU task
  int argc1 = 1;
  char** params1 = xbt_malloc0(sizeof(char *) * argc1);
  params1[0] = xbt_strdup("400.0E6");
  MSG_process_create_with_arguments("proc1", process_code, NULL, host, argc1, params1);

  // Process 2 - sleep 2 sec + CPU task
  int argc2 = 2;
  char** params2 = xbt_malloc0(sizeof(char *) * argc2);
  params2[0] = xbt_strdup("100.0E6");
  params2[1] = xbt_strdup("2");
  MSG_process_create_with_arguments("proc2", process_code, NULL, host, argc2, params2);

  // Process 3 - sleep 2 sec + CPU task
  int argc3 = 2;
  char** params3 = xbt_malloc0(sizeof(char *) * argc3);
  params3[0] = xbt_strdup("100.0E6");
  params3[1] = xbt_strdup("2");
  MSG_process_create_with_arguments("proc3", process_code, NULL, host, argc3, params3);


  // Main process
  MSG_process_sleep(8);

  task_time = MSG_get_clock() - task_time;
  XBT_INFO("Task simulation time: %e", task_time);
  consumed_energy = MSG_get_host_consumed_energy(host);
  XBT_INFO("Total energy (Joules): %f", consumed_energy);

  return 0;
}
Exemplo n.º 6
0
static void launch_worker(msg_host_t host, const char *pr_name, double computation_amount, int use_bound, double bound)
{
  char **argv = xbt_new(char *, 5);
  argv[0] = xbt_strdup(pr_name);
  argv[1] = bprintf("%f", computation_amount);
  argv[2] = bprintf("%d", use_bound);
  argv[3] = bprintf("%f", bound);
  argv[4] = NULL;

  MSG_process_create_with_arguments(pr_name, worker_main, NULL, host, 4, argv);
}
Exemplo n.º 7
0
int main(int argc, char* argv[])
{
  MSG_init(&argc, argv);
  MSG_create_environment(argv[1]);

  msg_host_t h = MSG_host_by_name("Fafard");

  sem = MSG_sem_init(1);
  char** aliceTimes = xbt_new(char*, 9);
  int nbAlice = 0;
  aliceTimes[nbAlice++] = xbt_strdup("0"); 
  aliceTimes[nbAlice++] = xbt_strdup("1");
  aliceTimes[nbAlice++] = xbt_strdup("3");
  aliceTimes[nbAlice++] = xbt_strdup("5");
  aliceTimes[nbAlice++] = xbt_strdup("1");
  aliceTimes[nbAlice++] = xbt_strdup("2");
  aliceTimes[nbAlice++] = xbt_strdup("5");
  aliceTimes[nbAlice++] = xbt_strdup("0");
  aliceTimes[nbAlice++] = NULL;

  char** bobTimes = xbt_new(char*, 9);
  int nbBob = 0;
  bobTimes[nbBob++] = xbt_strdup("0.9"); 
  bobTimes[nbBob++] = xbt_strdup("1");
  bobTimes[nbBob++] = xbt_strdup("1");
  bobTimes[nbBob++] = xbt_strdup("2");
  bobTimes[nbBob++] = xbt_strdup("2");
  bobTimes[nbBob++] = xbt_strdup("0");
  bobTimes[nbBob++] = xbt_strdup("0");
  bobTimes[nbBob++] = xbt_strdup("5");
  bobTimes[nbBob++] = NULL;

  MSG_process_create_with_arguments(xbt_strdup("Alice"), peer, NULL, h, 8, aliceTimes);
  MSG_process_create_with_arguments(xbt_strdup("Bob"), peer, NULL, h, 8, bobTimes);

  msg_error_t res = MSG_main();
  XBT_INFO("Finished\n");
  return (res != MSG_OK);
}
Exemplo n.º 8
0
static void vm_migrate_async(msg_vm_t vm, msg_host_t dst_pm)
{
  const char *vm_name = MSG_vm_get_name(vm);
  const char *dst_pm_name = MSG_host_get_name(dst_pm);
  msg_host_t host = MSG_host_self();

  const char *pr_name = "mig_wrk";
  char **argv = xbt_new(char *, 4);
  argv[0] = xbt_strdup(pr_name);
  argv[1] = xbt_strdup(vm_name);
  argv[2] = xbt_strdup(dst_pm_name);
  argv[3] = NULL;

  MSG_process_create_with_arguments(pr_name, migration_worker_main, NULL, host, 3, argv);
}
Exemplo n.º 9
0
int test_launcher(int argc, char *argv[])
{
  int test = 0;
  char **argvF;
  argvF = xbt_new(char*, 2);
  argvF[0] = xbt_strdup("process_daemon");
  msg_host_t jupiter = MSG_get_host_by_name("Jupiter");

  test = 1;
  // Create a process running a simple task on a host and turn the host off during the execution of the process.
  if (xbt_dynar_search_or_negative(tests, &test)!=-1){
    XBT_INFO("Test 1:");
    XBT_INFO("  Create a process on Jupiter");
    argvF = xbt_new(char*, 2);
    argvF[0] = xbt_strdup("process_daemon");
    MSG_process_create_with_arguments("process_daemon", process_daemon, NULL, jupiter, 1, argvF);
    MSG_process_sleep(3);
    XBT_INFO("  Turn off Jupiter");
    MSG_host_off(jupiter);
    MSG_process_sleep(10);
    XBT_INFO("Test 1 seems ok, cool !(number of Process : %d, it should be 1 (i.e. the Test one))", MSG_process_get_number());
  }
Exemplo n.º 10
0
int broker_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("broker");
	int i;
    
    for(i=2;i<argc;i++){
	arg[i-1]= strdup(argv[i]);
    }
    //create a number of process
    for(i=0;i<process_number;i++){
	process_list[i] = MSG_process_create_with_arguments(arg[0],broker,NULL,MSG_host_self(),count,arg);
	if ((i+1) >= atoi(argv[2])  && (((i+1) % (atoi(argv[2]))) == 0))
	    MSG_process_sleep(1);
    }
    MSG_process_sleep(MAX_TIME_SIMULATION);    
    //kill all process
    for(i=0;i<process_number;i++){
//	MSG_process_kill(process_list[i]);
    }
}