Exemple #1
0
Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
		 lmm_constraint_t constraint, int core, double powerPeak, double powerScale)
 : Resource(model, name, props, constraint)
 , m_core(core)
 , m_powerPeak(powerPeak)
 , m_powerScale(powerScale)
{
  surf_callback_emit(cpuCreatedCallbacks, this);
  /* At now, we assume that a VM does not have a multicore CPU. */
  if (core > 1)
    xbt_assert(model == surf_cpu_model_pm);

  p_constraintCore = NULL;
  p_constraintCoreId = NULL;
  if (model->getUpdateMechanism() != UM_UNDEFINED) {
	p_constraintCore = xbt_new(lmm_constraint_t, core);
	p_constraintCoreId = xbt_new(void*, core);

    int i;
    for (i = 0; i < core; i++) {
      /* just for a unique id, never used as a string. */
      p_constraintCoreId[i] = bprintf("%s:%i", name, i);
      p_constraintCore[i] = lmm_constraint_new(model->getMaxminSystem(), p_constraintCoreId[i], m_powerScale * m_powerPeak);
    }
  }
Cpu::Cpu(Model *model, simgrid::s4u::Host *host, lmm_constraint_t constraint,
    xbt_dynar_t speedPeakList, int core, double speedPeak)
 : Resource(model, host->name().c_str(), constraint)
 , m_core(core)
 , m_host(host)
{
  p_speed.peak = speedPeak;
  p_speed.scale = 1;
  host->pimpl_cpu = this;
  xbt_assert(p_speed.scale > 0, "Available speed has to be >0");

  // Copy the power peak array:
  p_speedPeakList = xbt_dynar_new(sizeof(double), nullptr);
  unsigned long n = xbt_dynar_length(speedPeakList);
  for (unsigned long i = 0; i != n; ++i) {
    double value = xbt_dynar_get_as(speedPeakList, i, double);
    xbt_dynar_push(p_speedPeakList, &value);
  }

  /* Currently, we assume that a VM does not have a multicore CPU. */
  if (core > 1)
    xbt_assert(model == surf_cpu_model_pm);

  if (model->getUpdateMechanism() != UM_UNDEFINED) {
  p_constraintCore = xbt_new(lmm_constraint_t, core);
  p_constraintCoreId = xbt_new(void*, core);

    int i;
    for (i = 0; i < core; i++) {
      /* just for a unique id, never used as a string. */
      p_constraintCoreId[i] = bprintf("%s:%i", host->name().c_str(), i);
      p_constraintCore[i] = lmm_constraint_new(model->getMaxminSystem(), p_constraintCoreId[i], p_speed.scale * p_speed.peak);
    }
  }
Storage::Storage(Model *model, const char *name, xbt_dict_t props,
                 lmm_system_t maxminSystem, double bread, double bwrite,
                 double bconnection, const char* type_id, char *content_name,
                 char *content_type, sg_size_t size, char *attach)
 :  Resource(model, name, props, lmm_constraint_new(maxminSystem, this, bconnection))
 , p_contentType(content_type)
 , m_size(size), m_usedSize(0)
 , p_typeId(xbt_strdup(type_id))
 , p_writeActions(xbt_dynar_new(sizeof(Action*),NULL)) {
  surf_callback_emit(storageCreatedCallbacks, this);
  p_content = parseContent(content_name);
  p_attach = xbt_strdup(attach);
  setState(SURF_RESOURCE_ON);
  XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%llu'", bconnection, bread, bwrite, size);
  p_constraintRead  = lmm_constraint_new(maxminSystem, this, bread);
  p_constraintWrite = lmm_constraint_new(maxminSystem, this, bwrite);
}
Exemple #4
0
void test(int nb_cnst, int nb_var, int nb_elem)
{
  lmm_system_t Sys = NULL;
  lmm_constraint_t *cnst = xbt_new0(lmm_constraint_t, nb_cnst);
  lmm_variable_t *var = xbt_new0(lmm_variable_t, nb_var);
  int *used = xbt_new0(int, nb_cnst);
  int i, j, k;

  Sys = lmm_system_new(1);

  for (i = 0; i < nb_cnst; i++) {
    cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0));
  }

  for (i = 0; i < nb_var; i++) {
    var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem);
    for (j = 0; j < nb_cnst; j++)
      used[j] = 0;
    for (j = 0; j < nb_elem; j++) {
      k = int_random(nb_cnst);
      if (used[k]) {
        j--;
        continue;
      }
      lmm_expand(Sys, cnst[k], var[i], float_random(1.0));
      used[k] = 1;
    }
  }

  printf("Starting to solve\n");
  date = xbt_os_time() * 1000000;
  lmm_solve(Sys);
  date = xbt_os_time() * 1000000 - date;

  for (i = 0; i < nb_var; i++)
    lmm_variable_free(Sys, var[i]);
  lmm_system_free(Sys);
  free(cnst);
  free(var);
  free(used);
}
Exemple #5
0
static void *cpu_create_resource(const char *name, double power_peak,
                                 double power_scale,
                                 tmgr_trace_t power_trace,
                                 int core,
                                 e_surf_resource_state_t state_initial,
                                 tmgr_trace_t state_trace,
                                 xbt_dict_t cpu_properties)
{
  cpu_Cas01_t cpu = NULL;

  xbt_assert(!surf_cpu_resource_by_name(name),
             "Host '%s' declared several times in the platform file",
             name);
  cpu = (cpu_Cas01_t) surf_resource_new(sizeof(s_cpu_Cas01_t),
                                        surf_cpu_model, name,
                                        cpu_properties);
  cpu->power_peak = power_peak;
  xbt_assert(cpu->power_peak > 0, "Power has to be >0");
  cpu->power_scale = power_scale;
  cpu->core = core;
  xbt_assert(core > 0, "Invalid number of cores %d", core);

  if (power_trace)
    cpu->power_event =
        tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);

  cpu->state_current = state_initial;
  if (state_trace)
    cpu->state_event =
        tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);

  cpu->constraint =
      lmm_constraint_new(surf_cpu_model->model_private->maxmin_system, cpu,
                         cpu->core * cpu->power_scale * cpu->power_peak);

  xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu);

  return cpu;
}
Exemple #6
0
/************
 * Resource *
 ************/
CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core)
: Cpu(model, host, lmm_constraint_new(model->getMaxminSystem(), this, core * speedPerPstate->front()),
    speedPerPstate, core)
{
}
static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limit, unsigned int pw_max_limit,
                 float rate_no_limit, int max_share, int mode)
{
  lmm_system_t Sys = NULL;
  lmm_constraint_t *cnst = xbt_new0(lmm_constraint_t, nb_cnst);
  lmm_variable_t *var = xbt_new0(lmm_variable_t, nb_var);
  int *used = xbt_new0(int, nb_cnst);
  int i;
  int j;
  int k;
  int l;
  int concurrency_share;

  Sys = lmm_system_new(1);

  for (i = 0; i < nb_cnst; i++) {
    cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0));
    if(rate_no_limit>float_random(1.0))
      //Look at what happens when there is no concurrency limit 
      l=-1;
    else
      //Badly logarithmically random concurrency limit in [2^pw_base_limit+1,2^pw_base_limit+2^pw_max_limit]
      l=(1<<pw_base_limit)+(1<<int_random(pw_max_limit));

    lmm_constraint_concurrency_limit_set(cnst[i],l );
  }

  for (i = 0; i < nb_var; i++) {
    var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem);
    //Have a few variables with a concurrency share of two (e.g. cross-traffic in some cases)
    concurrency_share=1+int_random(max_share);
    lmm_variable_concurrency_share_set(var[i],concurrency_share);

    for (j = 0; j < nb_cnst; j++)
      used[j] = 0;
    for (j = 0; j < nb_elem; j++) {
      k = int_random(nb_cnst);
      if (used[k]>=concurrency_share) {
        j--;
        continue;
      }
      lmm_expand(Sys, cnst[k], var[i], float_random(1.5));
      lmm_expand_add(Sys, cnst[k], var[i], float_random(1.5));
      used[k]++;
    }
  }

  fprintf(stderr,"Starting to solve(%i)\n",myrand()%1000);
  date = xbt_os_time() * 1000000;
  lmm_solve(Sys);
  date = xbt_os_time() * 1000000 - date;

  if(mode==2){
    fprintf(stderr,"Max concurrency:\n");
    l=0;
    for (i = 0; i < nb_cnst; i++) {
      j=lmm_constraint_concurrency_maximum_get(cnst[i]);
      k=lmm_constraint_concurrency_limit_get(cnst[i]);
      xbt_assert(k<0 || j<=k);
      if(j>l)
        l=j;
      fprintf(stderr,"(%i):%i/%i ",i,j,k);
      lmm_constraint_concurrency_maximum_reset(cnst[i]);
      xbt_assert(!lmm_constraint_concurrency_maximum_get(cnst[i]));
      if(i%10==9)
        fprintf(stderr,"\n");
    }
    fprintf(stderr,"\nTotal maximum concurrency is %i\n",l);

    lmm_print(Sys);
  }

  for (i = 0; i < nb_var; i++)
    lmm_variable_free(Sys, var[i]);
  lmm_system_free(Sys);
  free(cnst);
  free(var);
  free(used);
}