wgt_t calc_max_domaincomvol(
    vtx_t const nvtxs, 
    adj_t const * const xadj, 
    vtx_t const * const adjncy, 
    wgt_t const * const vwgt, 
    vlbl_t const nparts,
    vlbl_t const * const where)
{
  wgt_t max;
  vlbl_t i;
  wgt_t * dcvi = NULL, * dcvo = NULL;

  dcvi = wgt_alloc(nparts);
  dcvo = wgt_alloc(nparts);

  calc_domaincomvol(nvtxs,xadj,adjncy,vwgt,nparts,where,dcvi,dcvo);

  max = 0;
  for (i=0;i<nparts;++i) {
    if (max < dcvi[i]) {
      max = dcvi[i];
    }
  }
  for (i=0;i<nparts;++i) {
    if (max < dcvo[i]) {
      max = dcvo[i];
    }
  }

  dl_free(dcvo);
  dl_free(dcvi);

  return max;
}
Example #2
0
void rpc_query_data_free (rpc_query_data *d) {
  if (d == NULL) {
    return;
  }

  dl_free (d->data, d->len * sizeof (int));
  dl_free (d, sizeof (rpc_query_data));
}
void nhop_degree_distribution(
    vtx_t const nvtxs, 
    adj_t const * xadj, 
    vtx_t const * const adjncy, 
    vtx_t const nhops, 
    vtx_t ** const r_degrees, 
    vtx_t * const r_maxdegree)
{
  vtx_t i, k, hop, maxdeg, ndeg;
  adj_t j;
  vtx_t * curdeg, * nextdeg, * degrees;

  if (nhops == 1) {
    /* maybe thi should be reverse */
    degree_distribution(nvtxs,xadj,r_degrees,r_maxdegree);
  } else {
    curdeg = vtx_alloc(nvtxs);
    nextdeg = vtx_alloc(nvtxs);

    /* set initial degrees */
    for (i=0;i<nvtxs;++i) {
      curdeg[i] = xadj[i+1] - xadj[i];
    }

    /* perform passes */
    maxdeg = 0;
    for (hop=1;hop<nhops;++hop) {
      for (i=0;i<nvtxs;++i) {
        ndeg = 0;
        for (j=xadj[i];j<xadj[i+1];++j) {
          k = adjncy[j];
          ndeg += curdeg[k]; 
        }
        nextdeg[i] = ndeg;
        if (ndeg > maxdeg) {
          maxdeg = ndeg;
        }
      }
      dl_swap(curdeg,nextdeg);
    }

    /* drop nextdeg */
    dl_free(nextdeg);

    /* allocate our histogram */
    degrees = vtx_calloc(maxdeg+1);

    /* histogram up our nhop degrees */
    for (i=0;i<nvtxs;++i) {
      ++degrees[curdeg[i]];
    }

    dl_free(curdeg);

    *r_degrees = degrees;
    *r_maxdegree = maxdeg;
  }
}
Example #4
0
void free_line(char *line)
{
	char *w;
	for (w=dl_next(line); w != line; w=dl_next(line)) {
		dl_del(w);
		dl_free(w);
	}
	dl_free(line);
}
Example #5
0
static void imlut_free(DL_STATE *page, imlut_t *imlut)
{
  if ( imlut->decode_array ) {
    dl_free(page->dlpools, imlut->decode_array, 2 * imlut->ncomps * sizeof(float),
            MM_ALLOC_CLASS_IMAGE_TABLES);
  }
  dl_free(page->dlpools, imlut, sizeof(imlut_t),
          MM_ALLOC_CLASS_IMAGE_TABLES);
}
Example #6
0
void http_query_data_free (http_query_data *d) {
  if (d == NULL) {
    return;
  }

  dl_free (d->uri, d->uri_len);
  dl_free (d->get, d->get_len);
  dl_free (d->headers, d->headers_len);
  dl_free (d->post, d->post_len);

  dl_free (d, sizeof (http_query_data));
}
Example #7
0
dl_error_t dl_context_destroy(dl_ctx_t dl_ctx)
{
	dl_free( &dl_ctx->alloc, dl_ctx->type_ids );
	dl_free( &dl_ctx->alloc, dl_ctx->type_descs );
	dl_free( &dl_ctx->alloc, dl_ctx->enum_ids );
	dl_free( &dl_ctx->alloc, dl_ctx->enum_descs );
	dl_free( &dl_ctx->alloc, dl_ctx->member_descs );
	dl_free( &dl_ctx->alloc, dl_ctx->enum_value_descs );
	dl_free( &dl_ctx->alloc, dl_ctx->enum_alias_descs );
	dl_free( &dl_ctx->alloc, dl_ctx->typedata_strings );
	dl_free( &dl_ctx->alloc, dl_ctx->default_data );
	dl_free( &dl_ctx->alloc, dl_ctx );
	return DL_ERROR_OK;
}
void dlthread_comm_finalize(
    dlthread_comm_t const comm_idx)
{
  size_t i, myid;
  comm_t * comm;

  if (comm_idx != DLTHREAD_COMM_SINGLE) {
    myid = dlthread_get_id(comm_idx);

    dlthread_barrier(comm_idx);

    comm = my_comms+comm_idx;

    if (comm->larray) {
      /* destroy locks if they exist */
      for (i=0;i<comm->nlarray;++i) {
        free_lock(comm->larray[myid]+i);
      }
      dl_free(comm->larray[myid]);

      dlthread_barrier(comm_idx);

      if (myid == 0) {
        dl_free(comm->larray);
      }
    }

    if (myid == 0) {
      dl_free(comm->buffer);
      free_barrier(&(comm->bar));
      free_lock(&(comm->loc));

      comm->in_use = 0;

      set_lock(ncomms_lock);
      if (comm_idx < last_free_comm) {
        last_free_comm = comm_idx;
      }
      unset_lock(ncomms_lock);
    }
  } else {
    /* clear this threads local buffer if it exists */
    if (__local_buffer) {
      dl_free(__local_buffer);
      __local_buffer = NULL;
      __local_buffer_size = 0;
    }
  }
}
Example #9
0
static void slv_done( slv_db_typ *pdb, dl_head_typ *pusr, 
		      comm_clt_typ *psvc_clt, int name_id, 
		      char *pservname, void *name_struct )
{
	int xport = psvc_clt->xport;

	if( pusr != NULL )
		dl_free( pusr );

	switch (xport)
	{
	case COMM_QNX6_XPORT:
		if ( NULL != name_struct ) {
		        name_detach( (name_attach_t *) name_struct, 0 );
		}
		break;
	case COMM_QNX_XPORT:
		if( name_id != ERROR )
			qnx_name_detach( 0, name_id );
		break;
	case COMM_PSX_XPORT:
		// terminate and clean-up after database queue
		comm_cleanup(psvc_clt, pservname, 0); 
		break;
	default:
		fprintf(stderr, " Transport %d not implemented\n", xport);
		break;	
	}
	if( psvc_clt != NULL )
		comm_done( psvc_clt );

	if( pdb != NULL )
		slv_db_destroy( pdb );

}
void * dlthread_get_buffer(
    size_t const n,
    dlthread_comm_t const comm_idx)
{
  void * buffer;
  comm_t * comm;

  size_t const myid = dlthread_get_id(comm_idx);

  if (comm_idx != DLTHREAD_COMM_SINGLE) {
    comm = my_comms+comm_idx;

    if (comm->bufsize < n) {
      dlthread_barrier(comm_idx);
      if (myid == 0) {
        dl_free(comm->buffer);
        comm->buffer = malloc(n);
        comm->bufsize = n;
      }
      dlthread_barrier(comm_idx);
    }
    buffer = comm->buffer;
  } else {
    if (__local_buffer_size < n) {
      __local_buffer = realloc(__local_buffer,n);
      __local_buffer_size = n;
    }
    buffer = __local_buffer; 
  }
  return buffer;
}
static void dl_load_txt_build_default_data( dl_ctx_t ctx, dl_txt_read_ctx* read_state, unsigned int member_index )
{
	if( ctx->member_descs[member_index].default_value_offset == 0xFFFFFFFF )
		return;

	// TODO: check that this is not outside the buffers
	dl_type_desc*   def_type   = dl_alloc_type( ctx, dl_internal_hash_string( "a_type_here" ) );
	dl_member_desc* def_member = dl_alloc_member( ctx );

	dl_member_desc* member = &ctx->member_descs[member_index];

	uint32_t def_start = member->default_value_offset;
	uint32_t def_len   = member->default_value_size;

	char def_buffer[2048]; // TODO: no hardcode =/

	// TODO: check that typename do not exist in the ctx!

	size_t name_start = ctx->typedata_strings_size;
	dl_txt_read_substr temp = { "a_type_here", 11 };
	def_type->name = dl_alloc_string( ctx, &temp );
	def_type->size[DL_PTR_SIZE_HOST]      = member->size[DL_PTR_SIZE_HOST];
	def_type->alignment[DL_PTR_SIZE_HOST] = member->alignment[DL_PTR_SIZE_HOST];
	def_type->member_count = 1;

	memcpy( def_member, member, sizeof( dl_member_desc ) );
	def_member->offset[0] = 0;
	def_member->offset[1] = 0;

	dl_internal_str_format( def_buffer, sizeof(def_buffer), "{\"a_type_here\":{\"%s\":%.*s}}", dl_internal_member_name( ctx, member ), (int)def_len, read_state->start + def_start );

	size_t prod_bytes;
	dl_error_t err;
	err = dl_txt_pack( ctx, def_buffer, 0x0, 0, &prod_bytes );
	if( err != DL_ERROR_OK )
		dl_txt_read_failed( ctx, read_state, DL_ERROR_INVALID_DEFAULT_VALUE, "failed to pack default-value for member \"%s\" with error \"%s\"",
															dl_internal_member_name( ctx, member ),
															dl_error_to_string( err ) );

	uint8_t* pack_buffer = (uint8_t*)dl_alloc( &ctx->alloc, prod_bytes );

	dl_txt_pack( ctx, def_buffer, pack_buffer, prod_bytes, 0x0 );

	// TODO: convert packed instance to typelib endian/ptrsize here!

	size_t inst_size = prod_bytes - sizeof( dl_data_header );

	ctx->default_data = (uint8_t*)dl_realloc( &ctx->alloc, ctx->default_data, ctx->default_data_size + inst_size, ctx->default_data_size );
	memcpy( ctx->default_data + ctx->default_data_size, pack_buffer + sizeof( dl_data_header ), inst_size );

	dl_free( &ctx->alloc, pack_buffer );

	member->default_value_offset = (uint32_t)ctx->default_data_size;
	member->default_value_size   = (uint32_t)inst_size;
	ctx->default_data_size += inst_size;

	--ctx->type_count;
	--ctx->member_count;
	ctx->typedata_strings_size = name_start;
}
void calc_domainconn(
    vtx_t const nvtxs, 
    adj_t const * const xadj, 
    vtx_t const * const adjncy, 
    vlbl_t const nparts, 
    vlbl_t const * const where, 
    int * const dc)
{
  vtx_t i, k;
  adj_t j;
  vlbl_t me;
  int * dd;

  dd = int_init_alloc(0,nparts*nparts);

  for (i=0;i<nvtxs;++i) {
    me = where[i];
    for (j=xadj[i];j<xadj[i+1];++j) {
      k = adjncy[j];
      if (me != where[k]) {
        dd[(me*nparts)+where[k]] = 1;
      }
    }
  }

  int_set(dc,0,nparts);

  for (me=0;me<nparts;++me) {
    dc[me] = int_sum(dd+(nparts*me),nparts);
  }

  dl_free(dd);
}
/**
 * @brief Move the current curser in the file to a specific section.
 *
 * @param file The file to move the cursor of.
 * @param section The name of the section to move to.
 * @param r_bufsize A reference to the current/resulting buffer size.
 *
 * @return 1 if the section is found.
 */
static int __find_section(
    file_t * file, 
    char const * const section, 
    size_t * const r_bufsize)
{
  int found = 0;
  ssize_t ll;
  char * line = NULL;
  size_t bufsize;
  char str[512];

  bufsize = *r_bufsize;

  while((ll = dl_get_next_line(file,&line,&bufsize)) >= 0) {
    dl_string_upperize(line);
    if (sscanf(line,__SECTION_STR"%*[ \t]%512s",str) != 1) {
      continue;
    } else {
      if (strcmp(section,str) == 0) {
        /* found the section */
        found = 1;
        break;
      } else {
        /* some other section */
      }
    }
  }
  dl_free(line);

  *r_bufsize = bufsize;

  return found;
}
Example #14
0
/**
 * Destroy the given blist. May also want to free the block data following it.
 * \param[in]     blist           The blist to be destroyed
 * \param[in]     followingBlock  Is there a block to be freed as well
 */
void blist_destroy(IM_SHARED *im_shared, IM_BLIST *blist, Bool followingBlock)
{
  if ( followingBlock )
    im_datafree(im_shared, blist, sizeof(IM_BLIST) + im_blocksizeof());
  else
    dl_free(im_shared->page->dlpools, (mm_addr_t)blist, sizeof(IM_BLIST),
            MM_ALLOC_CLASS_IMAGE_DATA);
}
Example #15
0
static void ctl_close(void)
{
    if(ctl_close_hook)
    {
	ctl_close_hook();
	dl_free(libhandle);
	ctl_close_hook = NULL;
    }
}
Example #16
0
static void cairocmd_clear(cairocmd_t* cmd) {
	if (!cmd)
		return;
	free(cmd->text);
	cmd->text = NULL;
	if (cmd->xy)
		dl_free(cmd->xy);
	cmd->xy = NULL;
}
Example #17
0
/**
 * _kh_sub_free:
 * @sub: a #kqueue_sub
 *
 * Frees a subscription object and all its associated memory.
 **/
void
_kh_sub_free (kqueue_sub *sub)
{
  if (sub->deps)
    {
      dl_free (sub->deps);
      sub->deps = NULL;
    }

  g_free (sub->filename);
  g_slice_free (kqueue_sub, sub);
}
void dlthread_free_shmem(
    void * ptr,
    dlthread_comm_t const comm_idx)
{
  size_t const myid = dlthread_get_id(comm_idx);

  dlthread_barrier(comm_idx);

  if (myid == 0) {
    dl_free(ptr);
  }
}
Example #19
0
/**
 * Purge the DL data for a single gouraud object.
 */
static size_t purge_gouraud(DL_STATE *page, LISTOBJECT *lobj)
{
  GOURAUDOBJECT *g = lobj->dldata.gouraud;
  size_t info[1];

  info[0] = g->gsize;
  if ( info[0] + sizeof(info) > dld.load_size )
    return 0;
  if ( !dl2disk((uint8 *)g, info, sizeof(info), lobj) )
    return 0;
  dl_free(page->dlpools, g->base, g->gsize, MM_ALLOC_CLASS_GOURAUD);
  return info[0] + sizeof(info);
}
Example #20
0
void plot_radec_reset(plotradec_t* args) {
	if (args->radecvals)
		dl_free(args->radecvals);
	if (args->racol)
		free(args->racol);
	if (args->deccol)
		free(args->deccol);
	if (args->fn)
		free(args->fn);
	memset(args, 0, sizeof(plotradec_t));
	args->ext = 1;
	args->radecvals = dl_new(32);
}
Example #21
0
static void 
_csngen_free_callbacks (CSNGen *gen)
{	
	PR_ASSERT (gen);

	if (gen->callbacks.list)
	{
		dl_cleanup (gen->callbacks.list, slapi_ch_free);
		dl_free (&(gen->callbacks.list));
	}

	if (gen->callbacks.lock)
		slapi_destroy_rwlock (gen->callbacks.lock);
}
double calc_partition_components(
    vtx_t const nvtxs,
    adj_t const * const xadj, 
    vtx_t const * const adjncy, 
    vlbl_t const nparts,
    vlbl_t const * const where)
{
  vlbl_t p, ncom;
  double avg;
  vtx_t * xnvtxs;
  adj_t ** xxadj;
  vtx_t ** xadjncy;

  xnvtxs = vtx_alloc(nparts);
  xxadj = r_adj_alloc(nparts);
  xadjncy = r_vtx_alloc(nparts);

  induce_subgraphs(nvtxs,xadj,adjncy,NULL,NULL,where,nparts,xnvtxs,xxadj, \
      xadjncy,NULL,NULL,NULL,NULL);

  avg = 0;
  for (p=0;p<nparts;++p) {
    label_components(xnvtxs[p],xxadj[p],xadjncy[p],NULL,&ncom);
    avg += ncom;
    dl_free(xxadj[p]);
    dl_free(xadjncy[p]);
  }

  dl_free(xnvtxs);
  dl_free(xxadj);
  dl_free(xadjncy);

  avg /= nparts;

  return avg;
}
double calc_edge_balance(
    vtx_t const nvtxs, 
    adj_t const * const xadj, 
    vtx_t const * const adjncy, 
    wgt_t const * const adjwgt, 
    vlbl_t const nparts,
    vlbl_t const * const where)
{
  vtx_t i;
  adj_t j;
  vlbl_t p;
  wgt_t max, total, w;
  wgt_t * pwgts;

  pwgts = wgt_calloc(nparts);

  if (adjwgt) {
    for (i=0;i<nvtxs;++i) {
      p = where[i];
      w = 0;
      for (j=xadj[i];j<xadj[i+1];++j) {
        w += adjwgt[j];
      }
      pwgts[p] += w;
    }
  } else {
    for (i=0;i<nvtxs;++i) {
      p = where[i];
      w = (wgt_t)(xadj[i+1]-xadj[i]);
      pwgts[p] += w;
    }
  }

  max = 0.0;
  total = 0.0;
  for (p=0;p<nparts;++p) {
    w = pwgts[p];
    total += w;
    if (max < w) {
      max = w;
    }
  }

  dl_free(pwgts);

  return (max*nparts)/(double)total;

}
Example #24
0
/**
 * _kh_start_watching:
 * @sub: a #kqueue_sub
 *
 * Starts watching on a subscription.
 *
 * Returns: %TRUE on success, %FALSE otherwise.
 **/
gboolean
_kh_start_watching (kqueue_sub *sub)
{
  g_assert (kqueue_socket_pair[0] != -1);
  g_assert (sub != NULL);
  g_assert (sub->filename != NULL);

  /* kqueue requires a file descriptor to monitor. Sad but true */
#if defined (O_EVTONLY)
  sub->fd = open (sub->filename, O_EVTONLY);
#else
  sub->fd = open (sub->filename, O_RDONLY);
#endif

  if (sub->fd == -1)
    {
      KH_W ("failed to open file %s (error %d)", sub->filename, errno);
      return FALSE;
    }

  _ku_file_information (sub->fd, &sub->is_dir, NULL);
  if (sub->is_dir)
    {
      /* I know, it is very bad to make such decisions in this way and here.
       * We already do have an user_data at the #kqueue_sub, and it may point to
       * GKqueueFileMonitor or GKqueueDirectoryMonitor. For a directory case,
       * we need to scan in contents for the further diffs. Ideally this process
       * should be delegated to the GKqueueDirectoryMonitor, but for now I will
       * do it in a dirty way right here. */
      if (sub->deps)
        dl_free (sub->deps);

      sub->deps = dl_listing (sub->filename);  
    }

  G_LOCK (hash_lock);
  g_hash_table_insert (subs_hash_table, GINT_TO_POINTER (sub->fd), sub);
  G_UNLOCK (hash_lock);

  _kqueue_thread_push_fd (sub->fd);
  
  /* Bump the kqueue thread. It will pick up a new sub entry to monitor */
  if (!_ku_write (kqueue_socket_pair[0], "A", 1))
    KH_W ("Failed to bump the kqueue thread (add fd, error %d)", errno);
  return TRUE;
}
int main(int argc, char *argv[]) {
	char* progname = argv[0];
    int argchar;
	char* infn;

    sl* methods = NULL;
    dl* scales = NULL;
    int i;
    int loglvl = LOG_MSG;

    while ((argchar = getopt (argc, argv, OPTIONS)) != -1)
        switch (argchar) {
        case '?':
        case 'h':
			printHelp(progname);
            return 0;
        case 'v':
            loglvl++;
            break;
        default:
            return -1;
        }

	if (optind != (argc - 1)) {
		printHelp(progname);
		exit(-1);
	}
	infn = argv[optind];

    log_init(loglvl);

    fits_use_error_system();

    if (fits_guess_scale(infn, &methods, &scales))
        exit(-1);

    for (i=0; i<sl_size(methods); i++) {
        printf("scale %s %g\n", sl_get(methods, i), dl_get(scales, i));
    }

    sl_free2(methods);
    dl_free(scales);

    return 0;
}
static inline void free_barrier(
    barrier_t * const bar)
{
  size_t i;
  int volatile * mybar;

  mybar = bar->vec;

  /* check to make sure bar is not in use */
  for (i=0;i<bar->nthreads;++i) {
    while (mybar[i*IDX_OFFSET] != 0) {
      _mm_pause();  
    }
  }

  /* keep the compiler from whining about freeing volatile memory */
  dl_free((void*)bar->vec);
}
Example #27
0
void glDeleteLists(GLuint list, GLsizei range) {
    FORWARD_IF_REMOTE(glDeleteLists);
    if (range < 0) {
        ERROR(GL_INVALID_VALUE);
    }
    ERROR_IN_BLOCK();
    for (int i = 0; i < range; i++) {
        displaylist_t *l = get_list(list);
        if (l) {
            if (state.list.active == l) {
                state.list.active = NULL;
            }
            dl_free(l);
            tack_set(&state.lists, list - 1, NULL);
        }
    }
    // lists just grow upwards, maybe use a better storage mechanism?
}
static void __vsep_func(
    void * const ptr)
{
  tid_t myid, nthreads;
  arg_t * arg;
  ctrl_t * ctrl;
  graph_t * graph;
  pid_t * where;
  pid_t ** dwhere;

  arg = ptr;

  ctrl = arg->ctrl;
  graph = arg->graph;
  where = arg->where;
  dwhere = arg->dwhere;

  myid = dlthread_get_id(ctrl->comm);
  nthreads = dlthread_get_nthreads(ctrl->comm);

  dlthread_barrier(ctrl->comm);

  if (nthreads > 1) {
    par_partition_pre(ctrl,graph);
  }

  dwhere[myid] = pid_alloc(graph->mynvtxs[myid]);

  par_partition_vertexseparator(ctrl,graph,dwhere);

  if (where) {
    __unify_where(dwhere,graph,where);
  }

  if (ctrl->verbosity >= MTMETIS_VERBOSITY_LOW) {
    dlthread_barrier(ctrl->comm);
    if (myid == 0) {
      partition_print_info(ctrl,graph,(pid_t const **)dwhere);
    }
    dlthread_barrier(ctrl->comm);
  }

  dl_free(dwhere[myid]);
}
/**
 * Detect and notify about the changes in the watched directory.
 *
 * This function is top-level and it operates with other specific routines
 * to notify about different sets of events in a different conditions.
 *
 * @param[in] wrk   A pointer to #worker.
 * @param[in] w     A pointer to #watch.
 * @param[in] event A pointer to the received kqueue event.
 **/
void
produce_directory_diff (worker *wrk, watch *w, struct kevent *event)
{
    assert (wrk != NULL);
    assert (w != NULL);
    assert (event != NULL);

    assert (w->type == WATCH_USER);
    assert (w->is_directory);

    dep_list *was = NULL, *now = NULL;
    was = dl_shallow_copy (w->deps);
    now = dl_listing (w->filename);
    if (now == NULL && errno != ENOENT) {
        /* Why do I skip ENOENT? Because the directory could be deleted at this
         * point */
        perror_msg ("Failed to create a listing for directory %s",
                    w->filename);
        dl_shallow_free (was);
        return;
    }

    dl_shallow_free (w->deps);
    w->deps = now;

    bulk_events be;
    memset (&be, 0, sizeof (be));

    handle_context ctx;
    memset (&ctx, 0, sizeof (ctx));
    ctx.wrk = wrk;
    ctx.w = w;
    ctx.be = &be;
    
    dl_calculate (was, now, &cbs, &ctx);
    
    if (be.memory) {
        safe_write (wrk->io[KQUEUE_FD], be.memory, be.size);
        free (be.memory);
    }

    dl_free (was);
}
Example #30
0
void glEndList() {
    FORWARD_IF_REMOTE(glEndList);
    GLuint list = state.list.name;
    displaylist_t *dl = state.list.active;
    if (!dl || state.block.active) {
        ERROR(GL_INVALID_OPERATION);
    }

    displaylist_t *old = get_list(list);
    if (old) {
        dl_free(old);
    }

    tack_set(&state.lists, list - 1, dl);
    state.list.active = NULL;
    if (state.list.mode == GL_COMPILE_AND_EXECUTE) {
        glCallList(list);
    }
}