Beispiel #1
0
BT_info
BT_Info (int mh, int mn)
{
  int j;
  BT_info p = checkedMalloc (sizeof(*p));
  p->fathers = checkedMalloc ((mh + 1) * sizeof(*p->fathers));
  p->size = mh;
  mn = DIV2(mn);
  for (j = 0; j <= mh; j++)
    {
      p->fathers[j] = checkedMalloc (mn * sizeof(int));
      mn = DIV2(mn);
    }
  return (p);
}
Beispiel #2
0
QA_quantizerState
QA_QuantizerState ()
{
  QA_quantizerState p = checkedMalloc (sizeof(*p));
  p->order = 0;
  p->xOrder = 0;
  p->dq = NULL;
  p->a = NULL;
  p->oldDx = NULL;
  p->qAux = NULL;
  p->u0 = NULL;
  p->u1 = NULL;
  p->u2 = NULL;
  p->lt = NULL;
  p->ltq = NULL;
  p->lquOld = NULL;
  p->qinf = NULL;
  p->qsup = NULL;
  p->simTime = NULL;
  p->minStep = 0;
  p->finTime = 0;
  p->flag2 = NULL;
  p->flag3 = NULL;
  p->flag4 = NULL;
  p->lSimTime = NULL;
  p->qMap = NULL;
  return (p);
}
Beispiel #3
0
FRW_frameworkState
FRW_FrameworkState ()
{
  FRW_frameworkState p = checkedMalloc (sizeof(*p));
  p->delta = 0;
  p->dxnOld = 0;
  return (p);
}
Beispiel #4
0
INT_integratorOps
INT_IntegratorOps ()
{
  INT_integratorOps p = checkedMalloc (sizeof(*p));
  p->initiliaze = NULL;
  p->integrate = NULL;
  return (p);
}
Beispiel #5
0
static ocrScheduler_t* newSchedulerHc(ocrSchedulerFactory_t * factory, ocrParamList_t *perInstance) {
    ocrSchedulerHc_t* derived = (ocrSchedulerHc_t*) checkedMalloc(derived, sizeof(ocrSchedulerHc_t));
    ocrScheduler_t* base = (ocrScheduler_t*)derived;
    base->fctPtrs = &(factory->schedulerFcts);
    paramListSchedulerHcInst_t *mapper = (paramListSchedulerHcInst_t*)perInstance;
    derived->workerIdFirst = mapper->workerIdFirst;
    return base;
}
Beispiel #6
0
BT_node
BT_Node ()
{
  BT_node p = checkedMalloc (sizeof(*p));
  p->value = 0;
  p->father = 0;
  p->size = 0;
  return (p);
}
Beispiel #7
0
BT_tree
BT_Tree (int dim, leave leaves, int leavesNumber, int *map)
{
  BT_tree p = checkedMalloc (sizeof(*p));
  if (dim == 0)
    {
      p->nodes = checkedMalloc (sizeof(BT_node*));
      p->nodes[0] = checkedMalloc (sizeof(struct BT_node_));
      p->height = 0;
      p->father = checkedMalloc (sizeof(int));
      p->size = 1;
      p->leaves = leaves;
      p->map = map;
      return (p);
    }
  int height = (int) LOG2(dim);
  if (height)
    {
      int j, size = DIV2(dim);
      p->nodes = checkedMalloc (height * sizeof(BT_node*));
      for (j = 0; j < height; j++)
	{
	  p->nodes[j] = checkedMalloc (size * sizeof(struct BT_node_));
	  size = DIV2(size);
	}
      p->height = height - 1;
      p->father = checkedMalloc (leavesNumber * sizeof(int));
      for (j = 0; j < leavesNumber; j++)
	{
	  p->father[j] = NOT_ASSIGNED;
	}
    }
  else
    {
      p->nodes = checkedMalloc (sizeof(BT_node*));
      p->nodes[0] = checkedMalloc (sizeof(struct BT_node_));
      p->height = 0;
      p->father = checkedMalloc (sizeof(int));
    }
  p->size = dim;
  p->leaves = leaves;
  p->map = map;
  return (p);
}
Beispiel #8
0
QA_quantizerOps
QA_QuantizerOps ()
{
  QA_quantizerOps p = checkedMalloc (sizeof(*p));
  p->recomputeNextTimes = NULL;
  p->recomputeNextTime = NULL;
  p->nextTime = NULL;
  p->updateQuantizedState = NULL;
  return (p);
}
Beispiel #9
0
FRW_frameworkOps
FRW_FrameworkOps ()
{
  FRW_frameworkOps p = checkedMalloc (sizeof(*p));
  p->nextEventTime = NULL;
  p->nextInputTime = NULL;
  p->recomputeDerivative = NULL;
  p->recomputeDerivatives = NULL;
  return (p);
}
Beispiel #10
0
void
QSS_PAR_allocRootSimulatorData (QSS_simulator simulator)
{
  QSS_data data = simulator->data;
  int lps = data->params->lps;
  simulator->lpTime = (double*) checkedMalloc (lps * sizeof(double));
  simulator->mailbox = MLB_Mailbox (lps);
  simulator->stats = SD_Statistics (lps);
  simulator->lps = QSS_LP_DataArray (lps);
  simulator->simulationLog = SD_SimulationLog (simulator->output->name);
}
Beispiel #11
0
BTR_node
BTR_Node ()
{
  BTR_node p = checkedMalloc (sizeof(*p));
  p->value = 0;
  p->father = 0;
  p->size = 0;
  p->visit[0] = NOT_EQUAL;
  p->visit[1] = NOT_EQUAL;
  p->visit[2] = NOT_EQUAL;
  return (p);
}
Beispiel #12
0
/**
 * Builds an instance of a HC worker
 */
ocrWorker_t* newWorkerHc (ocrWorkerFactory_t * factory, ocrParamList_t * perInstance) {
    ocrWorkerHc_t * worker = checkedMalloc(worker, sizeof(ocrWorkerHc_t));
    worker->run = false;
    worker->id = ((paramListWorkerHcInst_t*)perInstance)->workerId;
    worker->currentEDTGuid = NULL_GUID;
    ocrWorker_t * base = (ocrWorker_t *) worker;
    base->guid = UNINITIALIZED_GUID;
    guidify(getCurrentPD(), (u64)base, &(base->guid), OCR_GUID_WORKER);
    base->routine = worker_computation_routine;
    base->fctPtrs = &(factory->workerFcts);
    return base;
}
Beispiel #13
0
ocrSchedulerFactory_t * newOcrSchedulerFactoryHc(ocrParamList_t *perType) {
    ocrSchedulerFactoryHc_t* derived = (ocrSchedulerFactoryHc_t*) checkedMalloc(derived, sizeof(ocrSchedulerFactoryHc_t));
    ocrSchedulerFactory_t* base = (ocrSchedulerFactory_t*) derived;
    base->instantiate = newSchedulerHc;
    base->destruct = destructSchedulerFactoryHc;
    base->schedulerFcts.start = hcSchedulerStart;
    base->schedulerFcts.stop = hcSchedulerStop;
    base->schedulerFcts.yield = hcSchedulerYield;
    base->schedulerFcts.destruct = destructSchedulerHc;
    base->schedulerFcts.takeEdt = hcSchedulerTake;
    base->schedulerFcts.giveEdt = hcSchedulerGive;
    return base;
}
Beispiel #14
0
INT_integrator
INT_Integrator (SIM_simulator simulator)
{
  INT_integrator p = checkedMalloc (sizeof(*p));
  p->ops = INT_IntegratorOps ();
  switch (simulator->state->settings->method)
    {
    case SD_DOPRI:
      {
	p->ops->initiliaze = CLC_initialize;
	p->ops->integrate = DOPRI_integrate;
      }
      break;
    case SD_DASSL:
      {
	p->ops->initiliaze = CLC_initialize;
	p->ops->integrate = DASSL_integrate;
      }
      break;
    default:
      {
	if (simulator->state->settings->hybrid == TRUE
	    && simulator->state->settings->parallel == TRUE)
	  {
	    p->ops->initiliaze = QSS_PAR_initialize;
	    p->ops->integrate = QSS_PARH_integrate;
	  }
	else if (simulator->state->settings->hybrid == TRUE
	    && simulator->state->settings->parallel == FALSE)
	  {
	    p->ops->initiliaze = QSS_SEQ_initialize;
	    p->ops->integrate = QSS_SEQH_integrate;
	  }
	else if (simulator->state->settings->hybrid == FALSE
	    && simulator->state->settings->parallel == TRUE)
	  {
	    p->ops->initiliaze = QSS_PAR_initialize;
	    p->ops->integrate = QSS_PARC_integrate;
	  }
	else if (simulator->state->settings->hybrid == FALSE
	    && simulator->state->settings->parallel == FALSE)
	  {
	    p->ops->initiliaze = QSS_SEQ_initialize;
	    p->ops->integrate = QSS_SEQC_integrate;
	  }
      }
    }
  return (p);
}
Beispiel #15
0
static void hcSchedulerStart(ocrScheduler_t * self, ocrPolicyDomain_t * PD) {
    ocrSchedulerHc_t * derived = (ocrSchedulerHc_t *) self;
    u64 workpileCount = self->workpileCount;
    ocrWorkpile_t ** workpiles = self->workpiles;
    // allocate steal iterator cache
    ocrWorkpileIterator_t ** stealIteratorsCache = checkedMalloc(stealIteratorsCache, sizeof(ocrWorkpileIterator_t *)*workpileCount);
    // Initialize steal iterator cache
    u64 i = 0;
    while(i < workpileCount) {
        // Note: here we assume workpile 'i' will match worker 'i' => Not great
        stealIteratorsCache[i] = newWorkpileIterator(i, workpileCount, workpiles);
        i++;
    }
    derived->stealIterators = stealIteratorsCache;
}
Beispiel #16
0
ocrWorkerFactory_t * newOcrWorkerFactoryHc(ocrParamList_t * perType) {
    ocrWorkerFactoryHc_t* derived = (ocrWorkerFactoryHc_t*) checkedMalloc(derived, sizeof(ocrWorkerFactoryHc_t));
    ocrWorkerFactory_t* base = (ocrWorkerFactory_t*) derived;
    base->instantiate = newWorkerHc;
    base->destruct =  destructWorkerFactoryHc;
    base->workerFcts.destruct = destructWorkerHc;
    base->workerFcts.start = hcStartWorker;
    base->workerFcts.execute = hcExecuteWorker;
    base->workerFcts.finish = hcFinishWorker;
    base->workerFcts.stop = hcStopWorker;
    base->workerFcts.isRunning = hc_is_running_worker;
    base->workerFcts.getCurrentEDT = hc_getCurrentEDT;
    base->workerFcts.setCurrentEDT = hc_setCurrentEDT;
    return base;
}
Beispiel #17
0
BTR_tree
BTR_Tree (int dim, leave leaves, double *weights)
{
  int i;
  int height = (int) LOG2(dim);
  BTR_tree p = checkedMalloc (sizeof(*p));
  if (height)
    {
      int j, size = DIV2(dim);
      p->nodes = checkedMalloc (height * sizeof(BTR_node*));
      for (j = 0; j < height; j++)
	{
	  p->nodes[j] = checkedMalloc (size * sizeof(struct BTR_node_));
	  size = DIV2(size);
	}
      p->height = height - 1;
      p->father = checkedMalloc (dim * sizeof(int));
    }
  else
    {
      p->nodes = checkedMalloc (sizeof(BTR_node*));
      p->nodes[0] = checkedMalloc (sizeof(struct BTR_node_));
      p->height = 0;
      p->father = checkedMalloc (sizeof(int));
    }
  p->size = dim;
  p->leaves = leaves;
  p->equals = (int*) malloc (dim * sizeof(int));
  p->weights = (double*) malloc (dim * sizeof(double));
  int totalWeights = 0;
  if (weights == NULL)
    {
      for (i = 0; i < dim; i++)
	{
	  p->weights[i] = 1;
	  totalWeights += p->weights[i];
	}
    }
  else
    {
      for (i = 0; i < dim; i++)
	{
	  p->weights[i] = weights[i];
	  totalWeights += p->weights[i];
	}
    }
  p->weightedEquals = (int*) malloc (totalWeights * sizeof(int));
  p->numEquals = 0;
  return (p);
}
Beispiel #18
0
int
PAR_createLPTasks (QSS_sim simulate, QSS_simulator simulator)
{
    int i, lps = simulator->data->params->lps;
    tasks = checkedMalloc (lps * sizeof(*tasks));
    pthread_barrier_init (&b, NULL, lps);
    QSS_simulatorInstance si[lps];
    for (i = 0; i < lps; i++)
    {
        si[i].root = simulator;
        si[i].id = i;
        if (pthread_create (&tasks[i], NULL, simulate, &(si[i])) != 0)
        {
            return (PAR_ERR_CREATE_THREAD);
        }
    }
    for (i = 0; i < lps; i++)
    {
        pthread_join (tasks[i], NULL);
    }
    return (PAR_NO_ERROR);
}
LIQSS2_quantizerState LIQSS2_QuantizerState (){
  LIQSS2_quantizerState p = checkedMalloc (sizeof(*p));
  p->order = 2;
  p->events = 1;
  // printf("p->order: %d\n", p->order);
  p->x = NULL;
  p->diffxq = NULL;
  p->q = NULL;
  p->SD =NULL;
  p->tx = NULL;
  p->a = NULL;
  p->mpr =NULL;
  p->u0 =NULL;
  p->u1 =NULL;
  p->lqu =NULL;
  p->qAux =NULL;
  p->oldDx =NULL;
  p->lquOld =NULL;
  p->dx =NULL;
  p->flag2=NULL;
  p->flag3=NULL;
  p->flag4=NULL;
  p->dq =NULL;
  p->lt =NULL;
  p->tq =NULL;
  p->ltq =NULL;
  p->nTime =NULL;
  p->nSD =NULL;
  p->x =NULL;
  p->q =NULL;
  p->diffxq =NULL;
  p->SD =NULL;
  p->ZS =NULL;
  p->nZS =NULL;
  p->nextEventTime = NULL;
  p->zcSign = NULL;
  return (p);
};
Beispiel #20
0
QA_quantizer
QA_Quantizer (QSS_data simData, QSS_time simTime)
{
  QA_quantizer p = checkedMalloc (sizeof(*p));
  p->state = QA_QuantizerState ();
  p->ops = QA_QuantizerOps ();
  switch (simData->solver)
    {
    case SD_QSS:
      if (simData->params->lps > 0)
	{
	  QSS_PAR_init (p, simData, simTime);
	}
      else
	{
	  QSS_init (p, simData, simTime);
	}
      break;
    case SD_CQSS:
      if (simData->params->lps > 0)
	{
	  CQSS_PAR_init (p, simData, simTime);
	}
      else
	{
	  CQSS_init (p, simData, simTime);
	}
      break;
    case SD_LIQSS:
      if (simData->params->lps > 0)
	{
	  LIQSS_PAR_init (p, simData, simTime);
	}
      else
	{
	  LIQSS_init (p, simData, simTime);
	}
      break;
    case SD_QSS2:
      if (simData->params->lps > 0)
	{
	  QSS2_PAR_init (p, simData, simTime);
	}
      else
	{
	  QSS2_init (p, simData, simTime);
	}
      break;
    case SD_LIQSS2:
      if (simData->params->lps > 0)
	{
	  LIQSS2_PAR_init (p, simData, simTime);
	}
      else
	{
	  LIQSS2_init (p, simData, simTime);
	}
      break;
    case SD_QSS3:
      if (simData->params->lps > 0)
	{
	  QSS3_PAR_init (p, simData, simTime);
	}
      else
	{
	  QSS3_init (p, simData, simTime);
	}
      break;
    case SD_LIQSS3:
      if (simData->params->lps > 0)
	{
	  LIQSS3_PAR_init (p, simData, simTime);
	}
      else
	{
	  LIQSS3_init (p, simData, simTime);
	}
      break;
    case SD_QSS4:
      if (simData->params->lps > 0)
	{
	  QSS4_PAR_init (p, simData, simTime);
	}
      else
	{
	  QSS4_init (p, simData, simTime);
	}
      break;
    default:
      return (NULL);
    }
  return (p);
}
char* TestMemoryAllocator::alloc_memory(size_t size, const char*, int)
{
    return checkedMalloc(size);
}
Beispiel #22
0
SET_settings
SET_Settings (char *fname)
{
  config_t cfg, *cf;
  const config_setting_t *lists;
  int count, n, ires;
  double dres;
  const char *sol;
  cf = &cfg;
  config_init (cf);
  if (!config_read_file (cf, fname))
    {
      config_destroy (cf);
      fprintf(stderr,"Initial configuration file %s not found!\n",fname);
      abort();
      return (NULL);
    }
  SET_settings p = checkedMalloc (sizeof(*p));
  p->minstep = 0;
  p->zchyst = 0;
  p->derdelta = 0;
  p->it = 0;
  p->ft = 0;
  p->dt = 0;
  p->dqmin = NULL;
  p->dqrel = NULL;
  p->symdiff = 1;
  p->lps = 1;
  p->nodesize = 0;
  p->order = 1;
  p->solver = SD_QSS3;
  p->nDQMin = 0;
  p->nDQRel = 0;
  p->pm = SD_MetisCut;
  if (config_lookup_float (cf, "minstep", &dres))
    {
      if (dres == 0)
	{
	  p->minstep = MIN_STEP;
	}
      else
	{
	  p->minstep = dres;
	}
    }
  if (config_lookup_float (cf, "dt", &dres))
      {
        p->dt = dres;
      }
  if (config_lookup_float (cf, "zchyst", &dres))
    {
      if (dres == 0)
	{
	  p->zchyst = ZC_HYST;
	}
      else
	{
	  p->zchyst = dres;
	}
    }
  if (config_lookup_float (cf, "derdelta", &dres))
    {
      if (dres == 0)
	{
	  p->derdelta = DER_DELTA;
	}
      else
	{
	  p->derdelta = dres;
	}
    }
  if (config_lookup_float (cf, "it", &dres))
    {
      p->it = dres;
    }
  if (config_lookup_float (cf, "ft", &dres))
    {
      p->ft = dres;
    }
  if (config_lookup_int (cf, "symdiff", &ires))
    {
      p->symdiff = ires;
    }
  if (config_lookup_int (cf, "lps", &ires))
    {
      if (ires == 0)
	{
	  p->lps = LPS;
	}
      else
	{
	  p->lps = ires;
	}
    }
  if (config_lookup_int (cf, "nodesize", &ires))
    {
      if (ires == 0)
	{
	  p->nodesize = NODE_SIZE;
	}
      else
	{
	  p->nodesize = ires;
	}
    }
  if (config_lookup_string (cf, "sol", &sol))
    {
      p->solver = _getSolver (sol);
      p->order = _getOrder (p->solver);
    }
  if (config_lookup_string (cf, "partitionMethod", &sol))
    {
      p->pm = _getPartitionMethod (sol);
    }
  lists = config_lookup (cf, "dqmin");
  count = config_setting_length (lists);
  p->dqmin = checkedMalloc (count * sizeof(double));
  for (n = 0; n < count; n++)
    {
      p->dqmin[n] = config_setting_get_float_elem (lists, n);
    }
  p->nDQMin = count;
  lists = config_lookup (cf, "dqrel");
  count = config_setting_length (lists);
  p->dqrel = checkedMalloc (count * sizeof(double));
  for (n = 0; n < count; n++)
    {
      p->dqrel[n] = config_setting_get_float_elem (lists, n);
    }
  p->nDQRel = count;
  config_destroy (cf);
  return ((p));
}
void
BTR_initTree (SC_scheduler scheduler, BTR_tree tree)
{
  if (tree->size == 1)
    {
      tree->nodes[0][0].value = 0;
      tree->nodes[0][0].father = 0;
      tree->nodes[0][0].size = 1;
      tree->nodes[0][0].visit[0] = NOT_EQUAL;
      tree->nodes[0][0].visit[1] = NOT_EQUAL;
      tree->nodes[0][0].visit[2] = NOT_EQUAL;
      tree->father[0] = 0;
      return;
    }
  unsigned int j, i, size, rightChild, leftChild;
  int k;
  int *numberOfNodes;
  if (tree->size == 2 || tree->size == 3)
    {
      numberOfNodes = checkedMalloc (sizeof(int));
      numberOfNodes[0] = 0;
    }
  else
    {
      numberOfNodes = checkedMalloc ((tree->height + 1) * sizeof(int));
    }
  size = DIV2(tree->size);
  for (j = 0; j < tree->size; j++)
    {
      tree->father[j] = DIV2(j);
    }
  if (tree->size & ODD)
    {
      tree->father[tree->size - 1]--;
    }
  if (tree->height)
    {
      for (j = 0; j <= tree->height; j++)
	{
	  numberOfNodes[j] = size - 1;
	  size = DIV2(size);
	}
    }
  for (j = 0; j <= numberOfNodes[0]; j++)
    {
      leftChild = MUL2(j);
      rightChild = MUL2(j) + 1;
      tree->nodes[0][j].size = 2;
      tree->nodes[0][j].father = DIV2(j);
      tree->nodes[0][j].value = MIN(tree->leaves[leftChild], leftChild,
				    tree->leaves[rightChild], rightChild);
      tree->nodes[0][j].visit[0] = tree->nodes[0][j].value;
      if (tree->leaves[leftChild] == tree->leaves[rightChild])
	{
	  tree->nodes[0][j].visit[1] = rightChild;
	}
      else
	{
	  tree->nodes[0][j].visit[1] = NOT_EQUAL;
	}
    }
  if ((numberOfNodes[0] + 1) & ODD)
    {
      tree->nodes[0][numberOfNodes[0]].father--;
    }
  if (tree->size & ODD)
    {
      j = numberOfNodes[0];
      tree->nodes[0][numberOfNodes[0]].size++;
      rightChild = MUL2(numberOfNodes[0]) + 2;
      k = tree->nodes[0][numberOfNodes[0]].value;
      if (tree->leaves[k] == tree->leaves[rightChild])
	{
	  if (tree->nodes[0][j].visit[1] != NOT_EQUAL)
	    {
	      tree->nodes[0][j].visit[2] = rightChild;
	    }
	  else
	    {
	      tree->nodes[0][j].visit[1] = rightChild;
	      tree->nodes[0][j].visit[2] = NOT_EQUAL;
	    }
	}
      else
	{
	  tree->nodes[0][j].visit[2] = NOT_EQUAL;
	  tree->nodes[0][numberOfNodes[0]].value = MIN(tree->leaves[k], k,
						       tree->leaves[rightChild],
						       rightChild);
	  if (tree->nodes[0][numberOfNodes[0]].value == rightChild)
	    {
	      tree->nodes[0][j].visit[0] = rightChild;
	      tree->nodes[0][j].visit[1] = NOT_EQUAL;
	    }
	}
    }
  if (tree->height)
    {
      for (i = 1; i <= tree->height; i++)
	{
	  for (j = 0; j <= numberOfNodes[i]; j++)
	    {
	      leftChild = tree->nodes[i - 1][MUL2(j)].value;
	      rightChild = tree->nodes[i - 1][MUL2(j) + 1].value;
	      tree->nodes[i][j].size = 2;
	      tree->nodes[i][j].father = DIV2(j);
	      tree->nodes[i][j].value = MIN(tree->leaves[leftChild], leftChild,
					    tree->leaves[rightChild],
					    rightChild);
	      tree->nodes[i][j].visit[0] = MIN(tree->leaves[leftChild], MUL2(j),
					       tree->leaves[rightChild],
					       MUL2(j)+1);
	      if (tree->leaves[leftChild] == tree->leaves[rightChild])
		{
		  tree->nodes[i][j].visit[1] = MUL2(j) + 1;
		}
	      else
		{
		  tree->nodes[i][j].visit[1] = NOT_EQUAL;
		}
	    }
	  if ((numberOfNodes[i] + 1) & ODD)
	    {
	      tree->nodes[i][numberOfNodes[i]].father--;
	    }
	  if ((numberOfNodes[i - 1] + 1) & ODD)
	    {
	      j = numberOfNodes[i];
	      tree->nodes[i][numberOfNodes[i]].size++;
	      rightChild = tree->nodes[i - 1][MUL2(numberOfNodes[i]) + 2].value;
	      k = tree->nodes[i][numberOfNodes[i]].value;
	      if (tree->leaves[k] == tree->leaves[rightChild])
		{
		  if (tree->nodes[i][j].visit[1] != NOT_EQUAL)
		    {
		      tree->nodes[i][j].visit[2] = MUL2(numberOfNodes[i]) + 2;
		    }
		  else
		    {
		      tree->nodes[i][j].visit[1] = MUL2(numberOfNodes[i]) + 2;
		      tree->nodes[i][j].visit[2] = NOT_EQUAL;
		    }
		}
	      else
		{
		  tree->nodes[i][j].visit[2] = NOT_EQUAL;
		  tree->nodes[i][numberOfNodes[i]].value = MIN(
		      tree->leaves[k], k, tree->leaves[rightChild], rightChild);
		  if (tree->nodes[i][numberOfNodes[i]].value == rightChild)
		    {
		      tree->nodes[i][j].visit[0] = MUL2(numberOfNodes[i]) + 2;
		      tree->nodes[i][j].visit[1] = NOT_EQUAL;
		    }
		}
	    }
	}
      tree->numEquals = 0;
      tree->randomRange = 0;
      scheduler->state->visit->fathers[tree->height][0] = 0;
      int visitNodes = 1;
      for (i = tree->height; i >= 1; i--)
	{
	  int nNodes = visitNodes;
	  visitNodes = 0;
	  for (j = 0; j < nNodes; j++)
	    {
	      int upd = scheduler->state->visit->fathers[i][j];
	      int cChilds = tree->nodes[i][upd].size;
	      for (k = 0; k < cChilds; k++)
		{
		  int add = tree->nodes[i][upd].visit[k];
		  if (add != NOT_EQUAL)
		    {
		      scheduler->state->visit->fathers[i - 1][visitNodes++] = add;
		    }
		  else
		    {
		      break;
		    }
		}
	    }
	}
      for (i = 0; i < visitNodes; i++)
	{
	  int upd = scheduler->state->visit->fathers[0][i];
	  int cChilds = tree->nodes[0][upd].size;
	  for (j = 0; j < cChilds; j++)
	    {
	      int add = tree->nodes[0][upd].visit[j];
	      if (add != NOT_EQUAL)
		{
		  tree->equals[add] = add;
		  tree->numEquals++;
		  int g, w = tree->randomRange + tree->weights[add];
		  for (g = tree->randomRange; g < w; g++)
		    {
		      tree->weightedEquals[g] = add;
		    }
		  tree->randomRange += tree->weights[add];
		}
	    }
	}
      if (tree->numEquals > 1)
	{
	  shuffle (tree->weightedEquals, tree->randomRange);
	  int selected = tree->weightedEquals[0];
	  tree->nodes[tree->height][0].value = selected;
	  tree->equals[selected] = NOT_ASSIGNED;
	  tree->num = 1;
	  tree->numEquals--;
	}
      else
	{
	  tree->numEquals = 0;
	}
    }
  free (numberOfNodes);
}
Beispiel #24
0
void * operator new[](size_t iSize)
{
   return checkedMalloc(iSize);
}
Beispiel #25
0
static void setupServerSockets(
  const struct LinkedList* serverAddrInfoList,
  struct PollState* pollState)
{
  struct LinkedListNode* nodePtr;

  for (nodePtr = serverAddrInfoList->head;
       nodePtr;
       nodePtr = nodePtr->next)
  {
    const struct addrinfo* listenAddrInfo = nodePtr->data;
    struct AddrPortStrings serverAddrPortStrings;
    struct ServerSocketInfo* serverSocketInfo =
      checkedMalloc(sizeof(struct ServerSocketInfo));

    if (addressToNameAndPort(listenAddrInfo->ai_addr,
                             listenAddrInfo->ai_addrlen,
                             &serverAddrPortStrings) < 0)
    {
      proxyLog("error resolving server listen address");
      exit(1);
    }

    serverSocketInfo->socket = socket(listenAddrInfo->ai_family,
                                      listenAddrInfo->ai_socktype,
                                      listenAddrInfo->ai_protocol);
    if (serverSocketInfo->socket < 0)
    {
      proxyLog("error creating server socket %s:%s",
               serverAddrPortStrings.addrString,
               serverAddrPortStrings.portString);
      exit(1);
    }

    if (setSocketReuseAddress(serverSocketInfo->socket) < 0)
    {
      proxyLog("setSocketReuseAddress error on server socket %s:%s",
               serverAddrPortStrings.addrString,
               serverAddrPortStrings.portString);
      exit(1);
    }

    if (bind(serverSocketInfo->socket,
             listenAddrInfo->ai_addr,
             listenAddrInfo->ai_addrlen) < 0)
    {
      proxyLog("bind error on server socket %s:%s",
               serverAddrPortStrings.addrString,
               serverAddrPortStrings.portString);
      exit(1);
    }

    if (setSocketListening(serverSocketInfo->socket) < 0)
    {
      proxyLog("listen error on server socket %s:%s",
               serverAddrPortStrings.addrString,
               serverAddrPortStrings.portString);
      exit(1);
    }

    if (setFDNonBlocking(serverSocketInfo->socket) < 0)
    {
      proxyLog("error setting non-blocking on server socket %s:%s",
               serverAddrPortStrings.addrString,
               serverAddrPortStrings.portString);
      exit(1);
    }

    proxyLog("listening on %s:%s (fd=%d)", 
             serverAddrPortStrings.addrString,
             serverAddrPortStrings.portString,
             serverSocketInfo->socket);

    addPollFDToPollState(
      pollState,
      serverSocketInfo->socket,
      serverSocketInfo,
      INTERESTED_IN_READ_EVENTS,
      NOT_INTERESTED_IN_WRITE_EVENTS);
  }
}
void
DASSL_integrate (SIM_simulator simulate)
{
  CLC_simulator simulator = (CLC_simulator) simulate->state->sim;
  clcData = simulator->data;
  clcModel = simulator->model;
  simOutput = simulator->output;
  int i;
  double t = clcData->it;
  double tout;
  const double _ft = clcData->ft;
  double dQRel = clcData->dQRel[0];
  double dQMin = clcData->dQMin[0];
  double *_x = clcData->x;
  double *rwork;
  int is_sampled = simOutput->commInterval != CI_Step;
  double step_size;
  if (is_sampled)
    {
      step_size = simOutput->sampled->period[0];
    }
  const int num_steps = (
      is_sampled ? ceil (_ft / step_size) + 2 : MAX_OUTPUT_POINTS);
  double **solution = checkedMalloc (sizeof(double*) * simOutput->outputs);
  double *solution_time = checkedMalloc (sizeof(double) * num_steps);
  double **outvar = checkedMalloc (sizeof(double) * simOutput->outputs);

  int info[20], lrw, liw, *iwork;
  double *x, *dx, rel_tol = dQRel, abs_tol = dQMin;
  int numofconstr = clcData->events, method_info = 0;
  int *root_output;
  int size = clcData->states;
  int event_detected = 0;

  x = checkedMalloc (sizeof(double) * clcData->states);
  dx = checkedMalloc (sizeof(double) * clcData->states);
  root_output = checkedMalloc (sizeof(int) * clcData->events);
  lrw = 5000 + 15000 * clcData->states
      + /*clcData->states * clcData->states +*/8 * clcData->events;
  rwork = checkedMalloc (sizeof(double) * lrw);
  CLC_compute_outputs (simOutput, solution, num_steps);
  for (i = 0; i < clcData->states; i++)
    x[i] = _x[i];
  cleanDoubleVector (dx, 0, clcData->states);
  cleanVector (root_output, 0, clcData->events);
  cleanVector (info, 0, 20);
  if (!is_sampled)
    {
      info[2] = 1;
    }
  liw = 60040;
  iwork = checkedMalloc (sizeof(int) * liw);
  int percentage = 0;
  // Save first step
  CLC_save_step (simOutput, solution, solution_time, t,
		 clcData->totalOutputSteps, x, clcData->d, clcData->alg);
  clcData->totalOutputSteps++;
  getTime (simulator->sTime);
#ifdef SYNC_RT
  setInitRealTime();
#endif
  while (t < _ft)
    {
      if (!is_sampled)
	{
	  tout = _ft;
	}
      else
	{
	  if (!event_detected)
	    {
	      tout = t + step_size;
	    }
	  else
	    {
	      if (fabs (tout - t) < 1e-12)
		{
		  CLC_save_step (simOutput, solution, solution_time, tout,
				 clcData->totalOutputSteps, x, clcData->d,
				 clcData->alg);
		  clcData->totalOutputSteps++;
		  tout = t + step_size;
		}
	    }
	  event_detected = 0;
	}
      if (tout > _ft)
	tout = _ft;
      ddaskr_ (DASSL_model, &size, &t, x, dx, &tout, info, &rel_tol, &abs_tol,
	       &method_info, rwork, &lrw, iwork, &liw,
	       NULL,
	       NULL, NULL, NULL, DASSL_events, &numofconstr, root_output);
      if (method_info < 0)
	{
	  printf (
	      "Error: DASSL returned IDID = %d. Check DASSL documentation\n",
	      method_info);
	  exit (-1);
	}
#ifdef SYNC_RT
      /* Sync */
      waitUntil(t);
#endif

      if (method_info == 5)
	{
	  CLC_handle_event (clcData, clcModel, x, root_output, t, iwork);
	  if (is_sampled)
	    event_detected = 1;
	  info[0] = 0;
	}
      if (!is_sampled)
	{
	  CLC_save_step (simOutput, solution, solution_time, t,
			 clcData->totalOutputSteps, x, clcData->d,
			 clcData->alg);
	  clcData->totalOutputSteps++;
	}
      else
	{
	  if (!event_detected)
	    {
	      if (fabs (tout - solution_time[clcData->totalOutputSteps - 1])
		  > step_size / 10)
		{
		  CLC_save_step (simOutput, solution, solution_time, tout,
				 clcData->totalOutputSteps, x, clcData->d,
				 clcData->alg);
		  clcData->totalOutputSteps++;
		}
	    }
	  else
	    {
	    }
	}

      if ((int) (t * 100 / _ft) > percentage)
	{
	  percentage = 100 * t / _ft;
	  fprintf (stderr, "*%g", t);
	  fflush (stderr);
	}
    }
  /*
   if (!event_detected && is_sampled) {
   if (solution_time[totalOutputSteps]<t) {
   CLC_save_step(simOutput,solution,solution_time,t,totalOutputSteps,x, clcData->d);
   totalOutputSteps++;
   }
   }
   */
  clcData->totalSteps += iwork[10];
  clcData->totalStepsDASSL += iwork[11];
  clcData->totalJacobians += iwork[12];
  clcData->totalCrossingEvaluations += iwork[35];
  getTime (simulator->sTime);
  subTime (simulator->sTime, simulator->iTime);
  if (simulator->settings->debug == 0 || simulator->settings->debug > 1)
    {
      SD_print (simulator->simulationLog, "Simulation time (DASSL):");
      SD_print (simulator->simulationLog, "----------------");
      SD_print (simulator->simulationLog, "Miliseconds: %g",
		getTimeValue (simulator->sTime));
      SD_print (simulator->simulationLog, "Function evaluations: %llu",
		clcData->funEvaluations);
      //SD_print (simulator->simulationLog, "Scalar function evaluations: %d", clcData->scalarEvaluations);
      //SD_print (simulator->simulationLog, "Zero Crossings : %d", clcData->zeroCrossings);
      SD_print (simulator->simulationLog,
		"Function evaluations (reported by DASSL): %d",
		clcData->totalStepsDASSL);
      SD_print (simulator->simulationLog, "Jacobian evaluations : %d",
		clcData->totalJacobians);
      SD_print (simulator->simulationLog, "Zero crossing evaluations : %d",
		clcData->totalCrossingEvaluations);
      SD_print (simulator->simulationLog, "Output steps: %d",
		clcData->totalOutputSteps);
      SD_print (simulator->simulationLog, "Simulation steps: %d",
		clcData->totalSteps);
      SD_print (simulator->simulationLog, "Events detected : %d",
		clcData->totalEvents);
    }
  CLC_write_output (simOutput, solution, solution_time,
		    clcData->totalOutputSteps);
  // To avoid QSS output
  free (x);
  free (dx);
  free (outvar);
  free (root_output);
  free (solution_time);
  free (rwork);
  free (iwork);
  for (i = 0; i < simOutput->outputs; i++)
    {
      free (solution[i]);
    }
  free (solution);
}
Beispiel #27
0
void
QSS_SEQ_printSimulationLog (QSS_simulator simulator)
{
  SD_print (simulator->simulationLog, "Simulation time: %g ms",
	    simulator->simulationTime);
  SD_print (simulator->simulationLog, "CPU time per transition: %g",
	    simulator->simulationTime / simulator->totalSteps);
  int nOutputs = simulator->output->outputs;
  if (nOutputs > 0)
    {
      SD_print (simulator->simulationLog, "Simulation output:");
      int j;
      for (j = 0; j < nOutputs; j++)
	{
	  SD_print (simulator->simulationLog, "Variable %s changes: %d",
		    simulator->output->variable[j].name,
		    OUT_getSteps (simulator->log, j));
	}
    }
  SD_print (simulator->simulationLog, "Simulation transitions: %lu",
	    simulator->totalSteps);
  if (simulator->reinits > 0)
    {
      SD_print (simulator->simulationLog, "State variable reinits: %lu",
		simulator->reinits);
    }
  SD_print (simulator->simulationLog, "Initialization time: %g ms",
	    simulator->initTime);
  SD_print (simulator->simulationLog, "Save data time: %g ms",
	    simulator->saveTime);
  SD_print (
      simulator->simulationLog, "Total time: %g ms",
      simulator->initTime + simulator->simulationTime + simulator->saveTime);
#ifdef DEBUG
  if (simulator->settings->debug & SD_DBG_VarChanges)
    {
      FILE *vweights;
      FILE *eweights;
      FILE *heweights;
      int *vwgts = NULL, max, N;
      double norm;
      if (simulator->settings->debug & SD_DBG_Weights)
	{
	  int *xadj = NULL, *adjncy = NULL, *hevars = NULL, edges = 0;
	  char fileName[256];
	  strcpy (fileName, simulator->output->name);
	  strcat (fileName, ".vweights");
	  vweights = fopen (fileName, "wb");
	  strcpy (fileName, simulator->output->name);
	  strcat (fileName, ".ewgts");
	  eweights = fopen (fileName, "wb");
	  strcpy (fileName, simulator->output->name);
	  strcat (fileName, ".hewgts");
	  heweights = fopen (fileName, "wb");
	  int states = simulator->data->states;
	  int events = simulator->data->events;
	  int vsize = states + events, eiter;
	  vwgts = (int *) checkedMalloc (vsize * sizeof (int));
	  cleanVector(vwgts,0,vsize);
	  simulator->data->params->pm = SD_MetisCut;
	  if (GRP_readGraph (simulator->output->name, simulator->data, &xadj, &adjncy, &edges, 0, NULL, NULL, 0, NULL) == GRP_ReadError)
	    {
	      fprintf (stderr, "Could not read generated graph files.\n");
	      abort();
	    }
	  N = edges;
	  max = (2 * 1e9) / N;
	  norm = 0;
	  for (eiter = 0; eiter < states; eiter++)
	    {
	      if (simulator->simulationLog->states[eiter] > norm)
		{
		  norm = simulator->simulationLog->states[eiter];
		}
	    }
	  for (eiter = states; eiter < events; eiter++)
	    {
	      if (simulator->simulationLog->handlers[eiter] > norm)
		{
		  norm = simulator->simulationLog->handlers[eiter];
		}
	    }
	  for (eiter = 0; eiter < states; eiter++)
	    {
	      int init = xadj[eiter], end = xadj[eiter+1], iter;
	      for (iter = init; iter < end; iter++)
		{
		  int val = simulator->simulationLog->states[eiter] + 1;
		  int inf = adjncy[iter];
		  if (inf < states)
		    {
		      val += simulator->simulationLog->states[inf] + 1;
		    }
		  else
		    {
		      val += (simulator->simulationLog->handlers[inf - states] + 1) * 10 * (simulator->data->event[inf - states].nLHSSt + 1);
		    }
		  val = ((double)val / norm) * max;
		  fwrite (&val, sizeof(int), 1, eweights);
		}
	    }
	  for (eiter = states; eiter < vsize; eiter++)
	    {
	      int init = xadj[eiter], end = xadj[eiter+1], iter;
	      for (iter = init; iter < end; iter++)
		{
		  int val = (simulator->simulationLog->handlers[eiter - states] + 1) * 10 * (simulator->data->event[eiter - states].nLHSSt + 1);
		  int inf = adjncy[iter];
		  if (inf < states)
		    {
		      val += simulator->simulationLog->states[inf] + 1;
		    }
		  else
		    {
		      val += (simulator->simulationLog->handlers[inf - states] + 1) * 10 * (simulator->data->event[inf - states].nLHSSt + 1);
		    }
		  val = (val / norm) * max;
		  fwrite (&val, sizeof(int), 1, eweights);
		}
	    }
	  free (xadj);
	  free (adjncy);
	  xadj = NULL;
	  adjncy = NULL;
	  simulator->data->params->pm = SD_Patoh;
	  if (GRP_readGraph (simulator->output->name, simulator->data, &xadj, &adjncy, &edges, 0, NULL, NULL, 1, &hevars) == GRP_ReadError)
	    {
	      fprintf (stderr, "Could not read generated graph files.\n");
	      abort();
	    }
	  for (eiter = 0; eiter < edges; eiter++)
	    {
	      int var = hevars[eiter];
	      if (var < states)
		{
		  int val = simulator->simulationLog->states[var] + 1;
		  val = ((double)val / norm) * max;
		  fwrite (&val, sizeof(int), 1, heweights);
		}
	      else
		{
		  int val = (simulator->simulationLog->handlers[var-states] + 1) * 10 * (simulator->data->event[var - states].nLHSSt + 1);
		  val = ((double)val / norm) * max;
		  fwrite (&val, sizeof(int), 1, heweights);
		}
	    }
	  free (xadj);
	  free (adjncy);
	  free (hevars);
	}
      SD_print (simulator->simulationLog, "State Variables:");
      int forUL = simulator->data->states, j;
      for (j = 0; j < forUL; j++)
	{
	  if (simulator->settings->debug & SD_DBG_Weights)
	    {
	      vwgts[j] += simulator->simulationLog->states[j] + 1;
	      int nDS = simulator->data->nDS[j], iter;
	      for (iter = 0; iter < nDS; iter++)
		{
		  int vwgt = simulator->data->DS[j][iter];
		  vwgts[j] += simulator->simulationLog->states[vwgt];
		}
	    }
	  SD_print (simulator->simulationLog, "Variable %d changes: %d", j, simulator->simulationLog->states[j]);
	}
      if (simulator->data->events > 0)
	{
	  int states = simulator->data->states;
	  SD_print (simulator->simulationLog, "Handler execution:");
	  forUL = simulator->data->events;
	  for (j = 0; j < forUL; j++)
	    {
	      if (simulator->settings->debug & SD_DBG_Weights)
		{
		  vwgts[states + j] += (simulator->simulationLog->handlers[j] + 1) * (simulator->data->event[j].nLHSSt + 1);
		  int nZS = simulator->data->nZS[j], iter;
		  for (iter = 0; iter < nZS; iter++)
		    {
		      int vwgt = simulator->data->ZS[j][iter];
		      vwgts[states + j] += simulator->simulationLog->states[vwgt];
		    }
		  int nHD = simulator->data->nHD[j];
		  for (iter = 0; iter < nHD; iter++)
		    {
		      int vwgt = simulator->data->HD[j][iter];
		      vwgts[vwgt] += simulator->simulationLog->handlers[j];
		    }
		  int nHZ = simulator->data->nHZ[j];
		  for (iter = 0; iter < nHZ; iter++)
		    {
		      int vwgt = simulator->data->HZ[j][iter];
		      vwgts[states + vwgt] += simulator->simulationLog->handlers[j];
		    }
		  int nLHSSt = simulator->data->event[j].nLHSSt;
		  for (iter = 0; iter < nLHSSt; iter++)
		    {
		      int vwgt = simulator->data->event[j].LHSSt[iter];
		      vwgts[vwgt] += simulator->simulationLog->handlers[j];
		    }
		}
	      SD_print (simulator->simulationLog, "Handler %d:  %d", j, simulator->simulationLog->handlers[j]);
	    }
	}
      if (simulator->settings->debug & SD_DBG_Weights)
	{
	  int forUL = simulator->data->states + simulator->data->events;
	  N = forUL;
	  max = (2 * 1e9) / N;
	  norm = 0;
	  for (j = 0; j < forUL; j++)
	    {
	      if (vwgts[j] > norm)
		{
		  norm =vwgts[j];
		}
	    }
	  for (j = 0; j < forUL; j++)
	    {
	      vwgts[j] = ((double)vwgts[j] / norm) * max;
	      fwrite (&(vwgts[j]), sizeof(int), 1, vweights);
	    }
	  free (vwgts);
	  fclose (vweights);
	  fclose (eweights);
	  fclose (heweights);
	}
    }
#endif
  SD_print (simulator->simulationLog, "");
}
Beispiel #28
0
/**
 * Default policy has one scheduler and a configurable
 * number of workers, comp-targets and workpiles
 */
static ocr_model_policy_t * defaultOcrModelPolicy(u64 nb_policy_domains, u64 schedulerCount,
                                           u64 workerCount, u64 computeCount, u64 workpileCount) {

    // Default policy
    ocr_model_policy_t * defaultPolicy =
        (ocr_model_policy_t *) checkedMalloc(defaultPolicy, sizeof(ocr_model_policy_t));
    defaultPolicy->model.kind = ocr_policy_default_kind;
    defaultPolicy->model.nb_instances = nb_policy_domains;
    defaultPolicy->model.perTypeConfig = NULL;
    defaultPolicy->model.perInstanceConfig = NULL;

    defaultPolicy->nb_scheduler_types = 1;
    defaultPolicy->nb_worker_types = 1;
    defaultPolicy->nb_comp_target_types = 1;
    defaultPolicy->nb_workpile_types = 1;
    defaultPolicy->numMemTypes = 1;
    defaultPolicy->numAllocTypes = 1;

    // Default allocator
    ocrAllocatorModel_t *defaultAllocator =
        (ocrAllocatorModel_t*)malloc(sizeof(ocrAllocatorModel_t));
    defaultAllocator->model.perTypeConfig = NULL;
    defaultAllocator->model.perInstanceConfig = NULL;
    defaultAllocator->model.kind = OCR_ALLOCATOR_DEFAULT;
    defaultAllocator->model.nb_instances = 1;
    defaultAllocator->sizeManaged = gHackTotalMemSize;

    defaultPolicy->allocators = defaultAllocator;

    u64 index_config = 0, n_all_schedulers = schedulerCount*nb_policy_domains;

    void** scheduler_configurations = malloc(sizeof(scheduler_configuration*)*n_all_schedulers);
    for ( index_config = 0; index_config < n_all_schedulers; ++index_config ) {
        scheduler_configurations[index_config] = (scheduler_configuration*) malloc(sizeof(scheduler_configuration));
        scheduler_configuration* curr_config = (scheduler_configuration*)scheduler_configurations[index_config];
        curr_config->worker_id_begin = ( index_config / schedulerCount ) * workerCount;
        curr_config->worker_id_end = ( index_config / schedulerCount ) * workerCount + workerCount - 1;
    }

    u64 n_all_workers = workerCount*nb_policy_domains;

    index_config = 0;
    void** worker_configurations = malloc(sizeof(worker_configuration*)*n_all_workers );
    for ( index_config = 0; index_config < n_all_workers; ++index_config ) {
        worker_configurations[index_config] = (worker_configuration*) malloc(sizeof(worker_configuration));
        worker_configuration* curr_config = (worker_configuration*)worker_configurations[index_config];
        curr_config->worker_id = index_config;
    }

    defaultPolicy->schedulers = newModel( ocr_scheduler_default_kind, schedulerCount, NULL, scheduler_configurations );
    defaultPolicy->computes  = newModel( ocr_comp_target_default_kind, computeCount, NULL, NULL );
    defaultPolicy->workpiles  = newModel( ocr_workpile_default_kind, workpileCount, NULL, NULL );
    defaultPolicy->memories   = newModel( OCR_MEMPLATFORM_DEFAULT, 1, NULL, NULL );
    defaultPolicy->workers    = newModel( ocr_worker_default_kind, workerCount, NULL, worker_configurations);


    // Defines how ocr modules are bound together
    u64 nb_module_mappings = 5;
    ocr_module_mapping_t * defaultMapping =
        (ocr_module_mapping_t *) checkedMalloc(defaultMapping, sizeof(ocr_module_mapping_t) * nb_module_mappings);
    // Note: this doesn't bind modules magically. You need to have a mapping function defined
    //       and set in the targeted implementation (see ocr_scheduler_hc implementation for reference).
    //       These just make sure the mapping functions you have defined are called
    defaultMapping[0] = build_ocr_module_mapping(MANY_TO_ONE_MAPPING, OCR_WORKPILE, OCR_SCHEDULER);
    defaultMapping[1] = build_ocr_module_mapping(ONE_TO_ONE_MAPPING, OCR_WORKER, OCR_COMP_TARGET);
    defaultMapping[2] = build_ocr_module_mapping(ONE_TO_MANY_MAPPING, OCR_SCHEDULER, OCR_WORKER);
    defaultMapping[3] = build_ocr_module_mapping(MANY_TO_ONE_MAPPING, OCR_MEMORY, OCR_ALLOCATOR);
    defaultMapping[4] = build_ocr_module_mapping(MANY_TO_ONE_MAPPING, OCR_SCHEDULER, OCR_POLICY);
    defaultPolicy->nb_mappings = nb_module_mappings;
    defaultPolicy->mappings = defaultMapping;

    return defaultPolicy;
}
Beispiel #29
0
FRW_framework
FRW_Framework (QSS_data simData)
{
  FRW_framework p = checkedMalloc (sizeof(*p));
  p->state = FRW_FrameworkState ();
  p->ops = FRW_FrameworkOps ();
  if (simData->params->symDiff)
    {
      if (simData->params->lps > 0)
	{
	  p->ops->recomputeDerivatives = SYM_PAR_recomputeDerivatives;
	  p->ops->recomputeDerivative = SYM_PAR_recomputeDerivative;
	  p->ops->nextEventTime = SYM_PAR_nextEventTime;
	}
      else
	{
	  p->ops->recomputeDerivatives = SYM_recomputeDerivatives;
	  p->ops->recomputeDerivative = SYM_recomputeDerivative;
	  p->ops->nextEventTime = SYM_nextEventTime;
	}
      switch (simData->order)
	{
	case 1:
	  if (simData->params->lps > 0)
	    {
	      p->ops->recomputeDerivatives = FO_PAR_recomputeDerivatives;
	      p->ops->recomputeDerivative = FO_PAR_recomputeDerivative;
	      p->ops->nextEventTime = FO_PAR_nextEventTime;
	      p->ops->nextInputTime = FO_PAR_nextInputTime;
	    }
	  else
	    {
	      p->ops->recomputeDerivatives = FO_recomputeDerivatives;
	      p->ops->recomputeDerivative = FO_recomputeDerivative;
	      p->ops->nextEventTime = FO_nextEventTime;
	      p->ops->nextInputTime = FO_nextInputTime;
	    }
	  break;
	case 2:
	  if (simData->params->lps > 0)
	    {
	      p->ops->nextInputTime = SO_PAR_nextInputTime;
	    }
	  else
	    {
	      p->ops->nextInputTime = SO_nextInputTime;
	    }
	  break;
	case 3:
	  if (simData->params->lps > 0)
	    {
	      p->ops->nextInputTime = TO_PAR_nextInputTime;
	    }
	  else
	    {
	      p->ops->nextInputTime = TO_nextInputTime;
	    }
	  break;
	case 4:
	  if (simData->params->lps > 0)
	    {
	      p->ops->nextInputTime = TO_PAR_nextInputTime;
	    }
	  else
	    {
	      p->ops->nextInputTime = TO_nextInputTime;
	    }
	  break;
	}
    }
  else
    {
      switch (simData->order)
	{
	case 1:
	  if (simData->params->lps > 0)
	    {
	      p->ops->recomputeDerivatives = FO_PAR_recomputeDerivatives;
	      p->ops->recomputeDerivative = FO_PAR_recomputeDerivative;
	      p->ops->nextEventTime = FO_PAR_nextEventTime;
	      p->ops->nextInputTime = FO_PAR_nextInputTime;
	    }
	  else
	    {
	      p->ops->recomputeDerivatives = FO_recomputeDerivatives;
	      p->ops->recomputeDerivative = FO_recomputeDerivative;
	      p->ops->nextEventTime = FO_nextEventTime;
	      p->ops->nextInputTime = FO_nextInputTime;
	    }

	  break;
	case 2:
	  if (simData->params->lps > 0)
	    {
	      p->ops->recomputeDerivatives = SO_PAR_recomputeDerivatives;
	      p->ops->recomputeDerivative = SO_PAR_recomputeDerivative;
	      p->ops->nextEventTime = SO_PAR_nextEventTime;
	      p->ops->nextInputTime = SO_PAR_nextInputTime;
	    }
	  else
	    {
	      p->ops->recomputeDerivatives = SO_recomputeDerivatives;
	      p->ops->recomputeDerivative = SO_recomputeDerivative;
	      p->ops->nextEventTime = SO_nextEventTime;
	      p->ops->nextInputTime = SO_nextInputTime;
	    }
	  break;
	case 3:
	  if (simData->params->lps > 0)
	    {
	      p->ops->recomputeDerivatives = TO_PAR_recomputeDerivatives;
	      p->ops->recomputeDerivative = TO_PAR_recomputeDerivative;
	      p->ops->nextEventTime = TO_PAR_nextEventTime;
	      p->ops->nextInputTime = TO_PAR_nextInputTime;
	    }
	  else
	    {
	      p->ops->recomputeDerivatives = TO_recomputeDerivatives;
	      p->ops->recomputeDerivative = TO_recomputeDerivative;
	      p->ops->nextEventTime = TO_nextEventTime;
	      p->ops->nextInputTime = TO_nextInputTime;
	    }
	  break;
	case 4:
	  printf ("TODO!!\n");
	  break;
	default:
	  return (NULL);
	}
    }
  FRW_initDelta (p, simData->ft, simData->params->derDelta);
  return (p);
}
char* StandardNewArrayAllocator::alloc_memory(size_t size, const char*, int)
{
	return checkedMalloc(size);
}