Пример #1
0
static inline list forward1(list t, int n)
{
   static bucket b[CHARS];   /* buckets */
   group g, g2;              /* groups */
   int pos = 0;              /* pos in string */

   if (n<2) return t;

   initmem(groupmem, sizeof(struct grouprec), n/15);
   initmem(bucketmem, sizeof(struct bucketrec), n/5);

   /* We use a dummy group g as the header of the group data
      structure. It does not contain any elements, but only a
      pointer to the first unfinished group. */
   g = (group) allocmem(groupmem, sizeof(struct grouprec));
   g2 = (group) allocmem(groupmem, sizeof(struct grouprec));
   g->next = g->nextunf = g2;
   g2->head = t;
   g2->next = g2->nextunf = NULL; 
   g2->finis = FALSE;

   intobuckets(g, b, pos);
   while (g->nextunf) {
      pos++;
      intogroups(b, pos);
      intobuckets(g, b, pos);
   }
   t = collect(g);

   freemem(bucketmem);
   freemem(groupmem);

   return t;
}
Пример #2
0
 /* attention: should have some upper/lower bound for memory allocation 
 * TODO: slice memory allocation, each slice takes up some amount of 
 * memory, which should be allocated accordingly.
 */
void schedmem(struct vm_info *vinfo, double capmem, double *tcmem, double *wr,
        double *mem_est, int n)
{
    int i, ret = 0;
    double availmem = 0.0, ttaken = 0.0,sum_mem_est = 0.0;
    
    for (i = 0; i < n; i++) {
        ttaken += min(mem_est[i], tcmem[i]);
        sum_mem_est += mem_est[i];
    }
    availmem = capmem - ttaken;

    for (i = 0; i < n; i++){
        if (mem_est[i] > tcmem[i])
        ret = -1;
        break;
    }

    if ((sum_mem_est <= capmem) && (ret == 0)) {
       for (i = 0; i < n; i++)
           allocmem(vinfo[i].dp, mem_est[i]);
    } else if (availmem >= 0.0) {
       for (i=0; i<n; i++)
           allocmem(vinfo[i].dp, min(mem_est[i], tcmem[i]) + wr[i] * availmem); 
    } else 
               availmem = 0.0;
} 
Пример #3
0
pcluster
new_cluster(uint size, uint * idx, uint sons, uint dim)
{
  pcluster  t;

  uint      i;

  t = (pcluster) allocmem((size_t) sizeof(cluster));
  t->type = 0;
  t->size = size;
  t->dim = dim;
  t->idx = idx;
  t->bmin = allocreal(dim);
  t->bmax = allocreal(dim);
  t->sons = sons;
  if (sons > 0) {
    t->son = (pcluster *) allocmem((size_t) sons * sizeof(pcluster));
    for (i = 0; i < sons; i++)
      t->son[i] = 0;
  }
  else
    t->son = 0;

  return t;
}
Пример #4
0
pdblock
new_dblock(pdcluster rc, pdcluster cc, uint rd, uint cd,
	   uint rsons, uint csons)
{
  pdblock   b;
  uint      i, j;

  b = (pdblock) allocmem(sizeof(dblock));
  b->rc = rc;
  b->cc = cc;
  b->rd = rd;
  b->cd = cd;
  b->adm = false;
  b->rsons = rsons;
  b->csons = csons;
  b->desc = 0;

  b->son = NULL;
  if (rsons > 0 && csons > 0) {
    b->son = (pdblock *) allocmem((size_t) sizeof(dblock) * rsons * csons);
    for (j = 0; j < csons; j++)
      for (i = 0; i < rsons; i++)
	b->son[i + j * rsons] = NULL;
  }

#ifdef USE_OPENMP
#pragma omp atomic
#endif
  active_dblock++;

  return b;
}
Пример #5
0
void *reallocmem(void *pOldAlloc, size_t bytes)
	{
	if (0 == pOldAlloc)
		return allocmem(bytes);
	size_t *pOldAllocSize = (size_t *) pOldAlloc - 1;
	void *pNewAlloc = allocmem(bytes);
	memcpy(pNewAlloc, pOldAlloc, *pOldAllocSize);
	return pNewAlloc;
	}
Пример #6
0
void
fill_dlp_cc_far_task_helmholtzbem3d(const uint * ridx, const uint * cidx,
				    pcbem3d bem, bool ntrans, pamatrix N)
{
  nearfield_args *nf_args;

  nf_args = (nearfield_args *) allocmem(sizeof(nearfield_args));
  nf_args->ridx = ridx;
  nf_args->cidx = cidx;
  nf_args->dist = true;
  nf_args->bem = bem;
  nf_args->ntrans = ntrans;
  nf_args->N = N;

  if (nf == NULL) {
    op_cb.dist = fill_dlp_cc_dist_gpu_wrapper_helmholtzbem3d;
    op_cb.vert = fill_dlp_cc_vert_gpu_wrapper_helmholtzbem3d;
    op_cb.edge = fill_dlp_cc_edge_gpu_wrapper_helmholtzbem3d;
    op_cb.iden = fill_dlp_cc_iden_gpu_wrapper_helmholtzbem3d;
    op_cb.sing_cpu = fill_dlp_cc_sing_cpu_wrapper_helmholtzbem3d;

    nf = new_ocltaskgroup(GPU_FIRST, NULL, merge_nf, cleanup_nf_merge,
			  distribute_nf, close_nf,
			  fill_cpu_wrapper_helmholtzbem3d,
			  fill_dlp_cc_dist_gpu_wrapper_helmholtzbem3d,
			  getsize_nf, split_nf_task, cleanup_nf_task,
			  (void *) &op_cb);
  }

  add_task_taskgroup(&nf, (void *) nf_args);

}
Пример #7
0
pcurve2d
new_curve2d(uint vertices, uint edges)
{
  pcurve2d  gr;

  gr = (pcurve2d) allocmem(sizeof(curve2d));
  gr->x = (real(*)[2]) allocmem((size_t) sizeof(real[2]) * vertices);
  gr->e = (uint(*)[2]) allocmem((size_t) sizeof(uint[2]) * edges);
  gr->n = (real(*)[2]) allocmem((size_t) sizeof(real[2]) * edges);
  gr->g = (real *) allocmem((size_t) sizeof(real) * edges);

  gr->vertices = vertices;
  gr->edges = edges;

  return gr;
}
Пример #8
0
bool
isclosed_surface3d(pcsurface3d gr)
{
  uint      edges = gr->edges;
  uint      triangles = gr->triangles;
  const     uint(*s)[3] = (const uint(*)[3]) gr->s;
  int      *visits;
  uint      i, j, problems;

  visits = (int *) allocmem((size_t) sizeof(int) * edges);

  for (i = 0; i < edges; i++)
    visits[i] = 0;

  for (i = 0; i < triangles; i++)
    for (j = 0; j < 3; j++)
      visits[s[i][j]]++;

  problems = 0;
  for (i = 0; i < edges; i++)
    if (visits[i] != 2)
      problems++;

  freemem(visits);

  return (problems == 0);
}
Пример #9
0
char *Kos_FileRead(kosFileInfo &fileInfo, int &code)
{
    char buffer[512], *p, *r;
    fileInfo.dataCount = 512;
    fileInfo.rwMode = 0;
    fileInfo.bufferPtr = (Byte *)buffer;
    memset((Byte*)buffer, 0, 512);
    int z = kos_FileSystemAccess(&fileInfo);
    code = z;

    //sprintf(debuf, "kos file read %U", code);
    //rtlDebugOutString(debuf);

    if (z != 0 && z != 6)
        return NULL;

    p = buffer;
    while (*p && *p++ != '\n');

    if (p == buffer)
        return NULL;

    r = (char*)allocmem(p - buffer);
    memset((Byte*)r, 0, p - buffer);
    //strncpy(r, buffer, p - buffer);
    for (int l = 0; l < p - buffer - 1; l++)
        r[l] = buffer[l];
    fileInfo.OffsetLow += p - buffer;
    return r;
}
Пример #10
0
char *make_cell_name(int x, int y, int xd, int yd)
{
    char *col_cap = make_col_cap(x);
    char *row_cap = make_row_cap(y);

    if (x <= 0 || x > col_count || y <= 0 || y > row_count)
        return NULL;

    char *res = (char*)allocmem(strlen(col_cap) + strlen(row_cap) + xd ? 1 : 0 + yd ? 1 : 0 + 1);
    int i = 0;
    if (xd)
    {
        res[i] = '$';
        i++;
    }
    strcpy(res + i, col_cap);
    i += strlen(col_cap);
    if (yd)
    {
        res[i] = '$';
        i++;
    }
    strcpy(res + i, row_cap);
    i += strlen(row_cap);
    res[i] = '\0';
    freemem(col_cap);
    freemem(row_cap);
    return res;
}
Пример #11
0
bool VDDisableCPUTracking() {
	HKEY hOpen;
	DWORD cbData;
	DWORD dwType;
	LPBYTE pByte;
	DWORD rc;

	bool fSuccess = true;

    if ( (rc = RegOpenKeyEx(HKEY_DYN_DATA,"PerfStats\\StopStat", 0,
					KEY_READ, &hOpen)) == ERROR_SUCCESS) {

		// query to get data size
		if ( (rc = RegQueryValueEx(hOpen,"KERNEL\\CPUUsage",NULL,&dwType,
				NULL, &cbData )) == ERROR_SUCCESS) {

			pByte = (LPBYTE)allocmem(cbData);

			rc = RegQueryValueEx(hOpen,"KERNEL\\CPUUsage",NULL,&dwType, pByte,
                              &cbData );

			freemem(pByte);
		} else
			fSuccess = false;

		RegCloseKey(hOpen);
	} else
		fSuccess = false;

	return fSuccess;
}
Пример #12
0
PRIVATE void run_finalize_queue(void) {
  OBJ *x;

  x = allocmem(sizeof(OBJ));
  *x = NULL;

  protect(x);

  wait_for_finalize();

  *x = next_to_finalize();

  while (*x != NULL) {
    if (OVECTORP(*x)) {
      finalize_ovector((OVECTOR) (*x));
    } else {
      /* %%% NOTE here's where objects should be handed to user level
	 to finalize. %%% */
      *x = NULL;	/* GC's the object */
    }

    *x = next_to_finalize();
  }

  unprotect(x);
  freemem(x);
}
Пример #13
0
static void push(list head, list tail, int size, int pos)
{   
   stackp = (stack *) allocmem(stackmem, sizeof(struct stackrec));
   stackp->head = head;
   stackp->tail = tail;
   stackp->size = size;
   stackp->pos = pos;
}
Пример #14
0
intcel* (mkintcel)(entry n  with_line_and_file)
{
    intcel *i;
    i = (intcel*) allocmem(sizeof(intcel));
    set_common_fields(i,INTEGER);
    i->intval = n;
    return i;
}
Пример #15
0
bigint* (mkbigint)(long size  with_line_and_file)
{
  bigint *result;
  if (size>SHRT_MAX) error("Big integer too big\n");
  result = (bigint*)allocmem(sizeof(bigint)+size*sizeof(digit));
  set_common_fields(result,BIGINT);
  result->allocsize = result->size = size;
  result->data = (digit *)&result[1];
  return result;
}
Пример #16
0
bool
isoriented_surface3d(pcsurface3d gr)
{
  uint      edges = gr->edges;
  uint      triangles = gr->triangles;
  const     uint(*e)[2] = (const uint(*)[2]) gr->e;
  const     uint(*t)[3] = (const uint(*)[3]) gr->t;
  const     uint(*s)[3] = (const uint(*)[3]) gr->s;
  int      *visits, *svisits;
  uint      i, j, k, problems;

  visits = (int *) allocmem((size_t) sizeof(int) * edges);
  svisits = (int *) allocmem((size_t) sizeof(int) * edges);

  for (i = 0; i < edges; i++)
    visits[i] = svisits[i] = 0;

  for (i = 0; i < triangles; i++)
    for (j = 0; j < 3; j++) {
      k = s[i][j];
      visits[k]++;
      if (e[k][0] == t[i][(j + 1) % 3]) {
	assert(e[k][1] == t[i][(j + 2) % 3]);
	svisits[k]++;
      }
      else {
	assert(e[k][0] == t[i][(j + 2) % 3]);
	assert(e[k][1] == t[i][(j + 1) % 3]);
	svisits[k]--;
      }
    }

  problems = 0;
  for (i = 0; i < edges; i++)
    if (visits[i] > 1 && (svisits[i] < -1 || svisits[i] > 1))
      problems++;

  freemem(svisits);
  freemem(visits);

  return (problems == 0);
}
Пример #17
0
pclusteroperator
new_leaf_clusteroperator(pccluster t)
{
  pclusteroperator co;

  co = (pclusteroperator) allocmem(sizeof(clusteroperator));

  init_leaf_clusteroperator(co, t);

  return co;
}
Пример #18
0
pclusteroperator *
enumerate_clusteroperator(pccluster t, pclusteroperator co)
{
  pclusteroperator *con;

  con = allocmem((size_t) sizeof(pclusteroperator) * co->t->desc);

  enumerate(t, 0, co, con);

  return con;
}
Пример #19
0
pcluster *
enumerate_cluster(pcluster t)
{
  pcluster *tn;

  tn = (pcluster *) allocmem((size_t) sizeof(pcluster) * t->desc);

  enumerate(t, 0, tn);

  return tn;
}
Пример #20
0
ptri2dbuilder
new_tri2dbuilder(uint vertices)
{
  ptri2dbuilder tb;
  uint      i;

  tb = (ptri2dbuilder) allocmem(sizeof(tri2dbuilder));
  tb->x = (real(*)[2]) allocmem(sizeof(real[2]) * vertices);
  tb->elist = (pedgeentry *) allocmem(sizeof(pedgeentry) * vertices);
  tb->tlist = 0;

  tb->vertices = vertices;
  tb->edges = 0;
  tb->triangles = 0;

  for (i = 0; i < vertices; i++)
    tb->elist[i] = 0;

  return tb;
}
Пример #21
0
pdblock  *
enumerate_dblock(pdblock b)
{

  pdblock  *bn;

  bn = (pdblock *) allocmem((size_t) sizeof(pdblock) * b->desc);

  enumerate(b, 0, bn);

  return bn;
}
Пример #22
0
ptet3dbuilder
new_tet3dbuilder(uint vertices)
{
  ptet3dbuilder tb;
  uint      i;

  tb = (ptet3dbuilder) allocmem(sizeof(tet3dbuilder));
  tb->x = (real(*)[3]) allocmem(sizeof(real[3]) * vertices);
  tb->elist = (pedgeentry *) allocmem(sizeof(pedgeentry) * vertices);
  tb->tlist = 0;

  tb->vertices = vertices;
  tb->edges = 0;
  tb->faces = 0;
  tb->tetrahedra = 0;

  for (i = 0; i < vertices; i++)
    tb->elist[i] = 0;

  return tb;
}
Пример #23
0
double depend_callback(char *str)
{
    cell_list *cur;
    // надо выдрать из АВ47 значения х и у.
    int i,j,x,y;

    if (abort_calc == 1)
        return 0.0;

    if (*str == '$') str++;
    for (i = 0; i < strlen(str); i++)
        if (str[i] >= '0' && str[i] <= '9')
            break;
    if (str[i-1] == '$')
        i--;
    if (i == strlen(str))
    {
        abort_calc = 1;
        serror(ERR_BADVARIABLE);
        return 0.0;
    }
    x = -1;
    for (j = 1; j < col_count; j++)
        //if (strncmp(str,cells[j][0],i)==0)
        if (str[0] == cells[j][0][0] && ((i == 1) || (str[1] == cells[j][0][1])))
        {
            x = j;
            break;
        }
    if (str[i] == '$')
        i++;

    y = -1;
    for (j = 1; j < row_count; j++)
        if (strcmp(str+i,cells[0][j])==0)
        {
            y = j;
            break;
        }
    if (x == -1 || y == -1)
    {
        abort_calc = 1;
        serror(ERR_BADVARIABLE);
        return 0.0;
    }
    cur = (cell_list*)allocmem(sizeof(cell_list));
    cur->x = x;
    cur->y = y;
    cur->next = last_dep;
    last_dep = cur;

    return 0.0;
}
Пример #24
0
/*
** 'link_library' is called to add a library to the relevant library list
*/
static void link_library(char *name, byte *base, int32 size, boolean onheap) {
  library *lp;
  int n;
  if (onheap) {		/* Library is held on Basic heap */
    lp = allocmem(sizeof(library));	/* Add library to list */
    lp->libname = allocmem(strlen(name)+1);	/* +1 for NULL at end */
    lp->libflink = basicvars.liblist;
    basicvars.liblist = lp;
  }
  else {	/* Library is held in permanent memory */
    lp = malloc(sizeof(library));
    if (lp==NIL) error(ERR_LIBSIZE, name);	/* Run out of memory */
    lp->libname = malloc(strlen(name)+1);
    lp->libflink = basicvars.installist;
    basicvars.installist = lp;
  }
  strcpy(lp->libname, name);
  lp->libstart = base;
  lp->libsize = size;
  lp->libfplist = NIL;
  for (n=0; n<VARLISTS; n++) lp->varlists[n] = NIL;
}
Пример #25
0
void
setsons_cluster(pcluster t, uint sons)
{
  uint      i;

  assert(t->sons == 0);

  t->sons = sons;
  t->son = (pcluster *) allocmem(sizeof(pcluster) * sons);

  for (i = 0; i < sons; i++)
    t->son[i] = 0;
}
Пример #26
0
static    pedgeentry
new_edgeentry(uint name, uint v0, uint v1, pedgeentry next)
{
  pedgeentry e;

  e = (pedgeentry) allocmem(sizeof(edgeentry));
  e->name = name;
  e->v[0] = v0;
  e->v[1] = v1;
  e->neighbours = 0;
  e->next = next;

  return e;
}
Пример #27
0
// -"- строки
char *make_row_cap(int i)
{
    char *r = (char*)allocmem(3);
    if (i <= 9)
    {
        r[0] = '0' + i;
        r[1] = '\0';
        return r;
    }
    r[0] = (i / 10) + '0';
    r[1] = (i % 10) + '0';
    r[2] = '\0';
    return r;
}
Пример #28
0
static    pedgeentry
new_edgeentry(uint name, uint v0, uint v1, pedgeentry next)
{
  pedgeentry e;

  e = (pedgeentry) allocmem(sizeof(edgeentry));
  e->name = name;
  e->v[0] = v0;
  e->v[1] = v1;
  e->flist = 0;
  e->boundary = false;
  e->next = next;

  return e;
}
Пример #29
0
static    pfaceentry
new_faceentry(uint name, pedgeentry e0, pedgeentry e1,
	      pedgeentry e2, pfaceentry next)
{
  pfaceentry f;

  f = (pfaceentry) allocmem(sizeof(faceentry));
  f->name = name;
  f->e[0] = e0;
  f->e[1] = e1;
  f->e[2] = e2;
  f->neighbours = 0;
  f->next = next;

  return f;
}
Пример #30
0
puniform
new_uniform(pclusterbasis rb, pclusterbasis cb)
{
  puniform  u;

  u = allocmem(sizeof(uniform));

  u->rb = u->cb = 0;
  u->rnext = u->rprev = u->cnext = u->cprev = 0;

  ref_row_uniform(u, rb);
  ref_col_uniform(u, cb);

  init_amatrix(&u->S, rb->k, cb->k);

  return u;
}