示例#1
0
int
main(int argc, char *argv[])
{
    struct dict_radix *dict = new_dict_radix();

    allocate_nodes(dict, 200000, 100000, 10000);

    read_dict(dict, NULL);
    print_sizes(dict);
    print_stats(dict);
    return 0;
}
示例#2
0
/* ---------------------------------------------------------------------- */
static mxArray *
allocate_grid(struct processed_grid *grid, const char *func)
/* ---------------------------------------------------------------------- */
{
    size_t nflds, nhf;
    const char *fields[] = { "nodes", "faces", "cells",
                             "type", "cartDims", "griddim" };

    mxArray *G, *nodes, *faces, *cells;
    mxArray *type, *typestr, *cartDims, *griddim;

    nflds    = sizeof(fields) / sizeof(fields[0]);
    nhf      = count_halffaces(grid->number_of_faces, grid->face_neighbors);

    G        = mxCreateStructMatrix(1, 1, nflds, fields);

    nodes    = allocate_nodes(grid->number_of_nodes);
    faces    = allocate_faces(grid->number_of_faces,
                              grid->face_ptr[ grid->number_of_faces ]);
    cells    = allocate_cells(grid->number_of_cells, nhf);
    type     = mxCreateCellMatrix(1, 1);
    typestr  = mxCreateString(func);
    cartDims = mxCreateDoubleMatrix(1, 3, mxREAL);
    griddim  = mxCreateDoubleScalar(3);

    if ((G        != NULL) && (nodes   != NULL) && (faces   != NULL) &&
        (cells    != NULL) && (type    != NULL) && (typestr != NULL) &&
        (cartDims != NULL) && (griddim != NULL)) {
        mxSetCell(type, 0, typestr);

        mxSetField(G, 0, "nodes"   , nodes   );
        mxSetField(G, 0, "faces"   , faces   );
        mxSetField(G, 0, "cells"   , cells   );
        mxSetField(G, 0, "type"    , type    );
        mxSetField(G, 0, "cartDims", cartDims);
        mxSetField(G, 0, "griddim" , griddim );
    } else {
        if (griddim  != NULL) { mxDestroyArray(griddim);  }
        if (cartDims != NULL) { mxDestroyArray(cartDims); }
        if (typestr  != NULL) { mxDestroyArray(typestr);  }
        if (type     != NULL) { mxDestroyArray(type);     }
        if (cells    != NULL) { mxDestroyArray(cells);    }
        if (faces    != NULL) { mxDestroyArray(faces);    }
        if (nodes    != NULL) { mxDestroyArray(nodes);    }
        if (G        != NULL) { mxDestroyArray(G);        }

        G = NULL;
    }

    return G;
}
示例#3
0
文件: poly.c 项目: barnaba/jimp2
int read_poly_file(const char *filename, triangulateio * input)
{
  int error_value = 0;
  FILE *polyfile;
  int markers;
  int firstnode;

  polyfile = fopen(filename, "r");
  if (polyfile == (FILE *) NULL) {
    printf("  Error:  Cannot access file %s.\n", filename);
    return FILE_ERR;
  }

  error_value = read_nodes_header(polyfile, input, &markers);
  if (error_value != SUCCESS)
    return error_value;

  allocate_nodes(input);

  error_value = read_nodes(polyfile, input, &markers, &firstnode);
  if (error_value != SUCCESS)
    return error_value;


  error_value = read_segments_header(polyfile, input, &markers);
  if (error_value != SUCCESS)
    return error_value;

  allocate_segments(input);
  error_value = read_segments(polyfile, input, markers, firstnode);
  if (error_value != SUCCESS)
    return error_value;

  error_value = read_holes_header(polyfile, input);
  if (error_value != SUCCESS)
    return error_value;

  allocate_holes(input);
  error_value = read_holes(polyfile, input);
  if (error_value != SUCCESS)
    return error_value;


  report(input, 1, 0, 0, 1, 0, 0);
  return SUCCESS;
}
示例#4
0
void PDQ_Init(char *name)
{
	extern char             model[];
	extern char             s1[];
	extern char     		tUnit[];
	extern char     		wUnit[];
	extern int              demand_ext;
	extern int              method;
	extern double           tolerance;
	
	// These 3 globals are reset = 0 at the end of this proc
	extern int              nodes;
	extern int              streams;
	extern int              demands; // set = 1 by SetDemand()
	
	extern int              prev_init;
	extern NODE_TYPE        *node;
	extern JOB_TYPE         *job;
	extern TERMINAL_TYPE    *tm;
	extern BATCH_TYPE       *bt;
	extern TRANSACTION_TYPE *tx;
	extern SYSTAT_TYPE      *sys;
	extern int               PDQ_DEBUG;
	extern void              allocate_nodes();
	extern void              allocate_jobs();
	char                    *p = "PDQ_Init()";
	
	if (PDQ_DEBUG)
		debug(p, "Entering");

	if (strlen(name) > MAXCHARS) {
		resets(s1);
		sprintf(s1, "Model name > %d characters", MAXCHARS);
		errmsg(p, s1);
	}
    
    // There may be multiple Inits in the same model
	if (prev_init) {
		for (c = 0; c < MAXSTREAMS; c++) {
			if (job[c].term) {
				if (job[c].term->sys) {
					PDQ_FREE(job[c].term->sys);
					job[c].term->sys = NULL;
					job[c].batch->sys = NULL;
					job[c].trans->sys = NULL;
				}
				PDQ_FREE(job[c].term);
				job[c].term = NULL;
			}
			if (job[c].batch) {
				if (job[c].batch->sys) {
					PDQ_FREE(job[c].batch->sys);
					job[c].term->sys = NULL;
					job[c].batch->sys = NULL;
					job[c].trans->sys = NULL;
				}
				PDQ_FREE(job[c].batch);
				job[c].batch = NULL;
			}
			if (job[c].trans) {
				if (job[c].trans->sys) {
					PDQ_FREE(job[c].trans->sys);
					job[c].term->sys = NULL;
					job[c].batch->sys = NULL;
					job[c].trans->sys = NULL;
				}
				PDQ_FREE(job[c].trans);
				job[c].trans = NULL;
			}
		}   // over c loop

		if (job) {
			PDQ_FREE(job);
			job = NULL;
		}
		if (node) {
			PDQ_FREE(node);
			node = NULL;
		}

		resets(model);
		resets(wUnit);
		resets(tUnit);
	}

	// Copy user-supplied name string into PDQ global model[]
	strcpy(model, name);
    Comment[0] = '\0';  // NULL string

	demand_ext = VOID;
	method = VOID;
	tolerance = TOL;

	allocate_nodes(MAXNODES+1);
	allocate_jobs(MAXSTREAMS+1);

/********************************************************************************** 
	On 12/6/06 John Strunk (Carnegie Mellon Univ.) sent the following comment:
		"My code analyzes a large number of models within a single
		invocation, so I call PDQ::Init to re-init the state before each
		model is analyzed. Unfortunately, a large portion of execution time
		(of my whole program) is spent in PDQ_Init, and I've tracked it
		down to the nested loop at PDQ_Build.c:130.  Perhaps it would be
		possible to remove this set of loops entirely since calloc in
		allocate_*() right above that inits the memory to zero.  These
		changes can provide a 6x speedup in my application."

	for (cc = 0; cc < MAXSTREAMS; cc++) {
		for (kk = 0; kk < MAXNODES; kk++) {
			node[kk].devtype = VOID;
			node[kk].sched = VOID;
			node[kk].demand[cc] = 0.0;
			node[kk].resit[cc] = 0.0;
			node[kk].qsize[cc] = 0.0;
		}
		job[cc].should_be_class = VOID;
		job[cc].network = VOID;
	}

	NJG on Tue, Apr 3, 2007
	Since the speedup would be nearly an order of magnitude, it's worth a
	try. I was probably being overly defensive when I originally zeroed out
	every array element. After commenting out the above loops, a simple PDQ
	test (no re-Init calls), does not reveal any integrity problems.
	
	The VOID constant in PDQ_Lib.h also set to zero instead of -1.
**********************************************************************************/
	
	// reset circuit counters 
	nodes = streams = demands = 0; 

	c = k = 0;
	prev_init = TRUE;

	if (PDQ_DEBUG) {
		debug(p, "Exiting");
	}
	
}  /* PDQ_Init */
示例#5
0
/*this fucntion is already serialized in the function that calls this 
  so from here on out there is no worry about locking*/
gasnete_coll_local_tree_geom_t *gasnete_coll_tree_geom_create_local(gasnete_coll_tree_type_t in_type, int rootrank, gasnete_coll_team_t team, gasnete_coll_tree_geom_t *base_geom)  {
  gasnete_coll_local_tree_geom_t *geom;
  int i;
  gasnete_coll_tree_type_t intype_copy;
  tree_node_t *allnodes = (tree_node_t*) team->tree_construction_scratch;
  tree_node_t rootnode,mynode;
  gasneti_assert(rootrank<team->total_ranks && rootrank >=0);
  gasneti_assert_always(in_type);
  intype_copy = in_type;
  geom = (gasnete_coll_local_tree_geom_t*)gasneti_malloc(sizeof(gasnete_coll_local_tree_geom_t));
  gasneti_assert_always(in_type==intype_copy);
  
  switch (in_type->tree_class) {
#if 1
  case GASNETE_COLL_NARY_TREE:
      gasneti_assert(in_type->num_params ==1);
      allnodes =  allocate_nodes((tree_node_t**) &team->tree_construction_scratch, team, rootrank);
      rootnode = make_nary_tree(allnodes, team->total_ranks, in_type->params[0]);
       geom->rotation_points = (int*) gasneti_malloc(sizeof(int)*1);
       geom->num_rotations = 1;
       geom->rotation_points[0] = rootrank;
      break;
    case GASNETE_COLL_KNOMIAL_TREE:
      gasneti_assert(in_type->num_params ==1);
       allnodes = allocate_nodes((tree_node_t**) &team->tree_construction_scratch, team, rootrank);
      rootnode = make_knomial_tree(allnodes, team->total_ranks, in_type->params[0]);
       geom->rotation_points = (int*) gasneti_malloc(sizeof(int)*1);
       geom->num_rotations = 1;
       geom->rotation_points[0] = rootrank;
      break;
    case GASNETE_COLL_FLAT_TREE:
      allocate_nodes((tree_node_t**) &team->tree_construction_scratch , team, rootrank);
      rootnode = make_flat_tree(team->tree_construction_scratch, team->total_ranks);
      geom->rotation_points = (int*) gasneti_malloc(sizeof(int)*1);
      geom->num_rotations = 1;
      geom->rotation_points[0] = rootrank;
      break;
    case GASNETE_COLL_RECURSIVE_TREE:
      gasneti_assert(in_type->num_params ==1);
      allnodes = allocate_nodes((tree_node_t**) &team->tree_construction_scratch, team, rootrank);
      rootnode = make_recursive_tree(allnodes, team->total_ranks, in_type->params[0]);
      geom->rotation_points = (int*) gasneti_malloc(sizeof(int)*1);
      geom->num_rotations = 1;
      geom->rotation_points[0] = rootrank;
      break;
    case GASNETE_COLL_FORK_TREE:
      allnodes = allocate_nodes((tree_node_t**) &team->tree_construction_scratch, team, rootrank);
      rootnode = make_fork_tree(allnodes, team->total_ranks, in_type->params, in_type->num_params);
       geom->rotation_points = (int*) gasneti_malloc(sizeof(int)*1);
       geom->num_rotations = 1;
       geom->rotation_points[0] = rootrank;
      break;
    case GASNETE_COLL_HIERARCHICAL_TREE:
#if 0
      allnodes = team->tree_construction_scratch = allocate_nodes(allnodes, team, 0);
      rootnode = make_hiearchical_tree(in_type, allnodes, team->total_ranks);
       /* XXX ADD CODE TO GET ROTATION POINTS*/
      break;
#else
       gasneti_fatalerror("HIERARCHICAL_TREE not yet fully supported");
#endif
#endif
    default:
       gasneti_fatalerror("unknown tree type");
      break;
  }
  
  rootnode = setparents(rootnode);
  mynode = find_node(rootnode, team->myrank);

  geom->root = rootrank;
  geom->tree_type = in_type;
  geom->total_size = team->total_ranks;
  geom->parent = GET_PARENT_ID(mynode);
  geom->child_count = GET_NUM_CHILDREN(mynode);
  geom->mysubtree_size = treesize(mynode);
  geom->parent_subtree_size = treesize(mynode->parent);
  geom->children_reversed = mynode->children_reversed;
  if(rootrank != team->myrank) {
    geom->num_siblings = GET_NUM_CHILDREN(mynode->parent);
    geom->sibling_id = -1;
    geom->sibling_offset = 0;
    for(i=0; i<geom->num_siblings; i++) {
      int tmp_id;
      if(mynode->parent->children_reversed==1) {
        tmp_id = geom->num_siblings-1-i;
      } else {
        tmp_id =i;
      }
      if(GET_NODE_ID(GET_CHILD_IDX(mynode->parent, tmp_id))==team->myrank) {
        geom->sibling_id = tmp_id;
        break;
      } else {
        geom->sibling_offset += treesize(GET_CHILD_IDX(mynode->parent, tmp_id));
      }
    }
  } else {
    geom->num_siblings = 0;
    geom->sibling_id = 0;
    geom->sibling_offset = 0;
    /***** THIS NEEDS TO BE TAKEN OUT
      The DFS ordering that we impose on the trees will mean that this no longer needs to be kept around
      but it's in here for now for backward compatability sake until we make the neccessary changes to all the other collective algorithms
      ****/
    geom->dfs_order = (gasnet_node_t*) gasneti_malloc(sizeof(gasnet_node_t)*team->total_ranks);
    for(i=0; i<team->total_ranks; i++) {
      geom->dfs_order[i] = (i+rootrank)%team->total_ranks;
    }
  }
  geom->seq_dfs_order = 1;
  geom->child_list = (gasnet_node_t*) gasneti_malloc(sizeof(gasnet_node_t)*geom->child_count);
  geom->subtree_sizes = (gasnet_node_t*) gasneti_malloc(sizeof(gasnet_node_t)*geom->child_count);
  geom->child_offset = (gasnet_node_t*) gasneti_malloc(sizeof(gasnet_node_t)*geom->child_count);
  geom->grand_children = (gasnet_node_t*)gasneti_malloc(sizeof(gasnet_node_t)*geom->child_count); 
  geom->num_non_leaf_children=0;
  geom->num_leaf_children=0;
  geom->child_contains_wrap = 0;
  for(i=0; i<geom->child_count; i++) {
    geom->child_list[i] = GET_NODE_ID(GET_CHILD_IDX(mynode,i));
    geom->subtree_sizes[i] = treesize(GET_CHILD_IDX(mynode,i));
    geom->grand_children[i] = GET_NUM_CHILDREN(GET_CHILD_IDX(mynode, i));
    if(geom->subtree_sizes[i] > 1) {
      geom->num_non_leaf_children++;
    } else {
      geom->num_leaf_children++;
    }
    if(geom->child_list[i]+geom->subtree_sizes[i] > geom->total_size) {
      geom->child_contains_wrap = 1;
    }
    
  }
  gasneti_assert((geom->num_leaf_children+geom->num_non_leaf_children) == geom->child_count);
  
  if(mynode->children_reversed==1) {
    size_t temp_offset = 0;
    for(i=geom->child_count-1; i>=0; i--) {
      geom->child_offset[i] = temp_offset; 
      temp_offset+=geom->subtree_sizes[i];
    }
  } else {
    size_t temp_offset = 0;
    for(i=0; i<geom->child_count; i++) {
      geom->child_offset[i] = temp_offset; 
      temp_offset+=geom->subtree_sizes[i];
    }
  }

#if 0
  /* Not using the reference counts for now */
  gasneti_weakatomic_set(&(geom->ref_count), 0, 0);
  geom->base_geom = base_geom;
#endif

#if 0  
  gasnete_coll_print_tree(geom, gasneti_mynode);
#endif
  return geom;
}