Esempio n. 1
0
/* Insert uop into corresponding load/store queue */
void X86ThreadInsertInLSQ(X86Thread *self, struct x86_uop_t *uop) {
  X86Core *core = self->core;

  struct linked_list_t *lq = self->lq;
  struct linked_list_t *sq = self->sq;
  struct linked_list_t *preq = self->preq;

  assert(!uop->in_lq && !uop->in_sq);
  assert(uop->uinst->opcode == x86_uinst_load ||
         uop->uinst->opcode == x86_uinst_store ||
         uop->uinst->opcode == x86_uinst_prefetch);

  if (uop->uinst->opcode == x86_uinst_load) {
    linked_list_out(lq);
    linked_list_insert(lq, uop);
    uop->in_lq = 1;
  } else if (uop->uinst->opcode == x86_uinst_store) {
    linked_list_out(sq);
    linked_list_insert(sq, uop);
    uop->in_sq = 1;
  } else {
    linked_list_out(preq);
    linked_list_insert(preq, uop);
    uop->in_preq = 1;
  }
  core->lsq_count++;
  self->lsq_count++;
}
Esempio n. 2
0
void oct_move( int oct_old, int oct_new ) {
	int i;

	cart_assert( oct_level[oct_old] != FREE_OCT_LEVEL );
	cart_assert( oct_level[oct_new] == FREE_OCT_LEVEL );
	cart_assert( oct_parent_cell[oct_old] >= 0 && oct_parent_cell[oct_old] < num_cells );
	cart_assert( cell_child_oct[ oct_parent_cell[oct_old] ] == oct_old );

	cell_child_oct[ oct_parent_cell[oct_old] ] = oct_new;
	oct_parent_cell[oct_new] = oct_parent_cell[oct_old];
	oct_level[oct_new] = oct_level[oct_old];
	oct_parent_root_sfc[oct_new] = oct_parent_root_sfc[oct_old];

	for ( i = 0; i < num_children; i++ ) {
		cell_move( oct_child( oct_old, i ), oct_child( oct_new, i ) );
	}

	for ( i = 0; i < num_neighbors; i++ ) {
		oct_neighbors[oct_new][i] = oct_neighbors[oct_old][i];
	}

	for ( i = 0; i < nDim; i++ ) {
		oct_pos[oct_new][i] = oct_pos[oct_old][i];
	}

	if ( root_cell_type(oct_parent_root_sfc[oct_new]) == CELL_TYPE_LOCAL ) {
		linked_list_insert( &local_oct_list[oct_level[oct_new]], oct_new );
	} else {
		linked_list_insert( &buffer_oct_list[oct_level[oct_new]], oct_new );
	}
}
Esempio n. 3
0
int event_analise(event_t * event, char * buf)
{
	struct event_em_t * em;
	const char * ps = strskpst(buf, "\t \r\n");
	if(strlen(ps) == 0 || ps[0] == '#')
		return 0;

	em = (struct event_em_t *)malloc(sizeof(struct event_em_t));
	ps = event_em_analise(em, ps);
	
	if(ps != 0)
	{
		linked_list_insert(event->all_event, 0, em);
		
		if(strlen(buf) >= 1024) //  命令长度太长 
			return -1;
		else
			strcpy(em->cmd, ps);
	}
	else
	{
		free(em);
		return -1;
	}

	return 0;
}
Esempio n. 4
0
//========= MY CODE =========//
void linked_list_add_new(struct linked_list_t *list, void *data, long long cycle)
{
	linked_list_out(list);
	linked_list_insert(list, data);
	list->current->cycle = cycle;
	linked_list_out(list);
}
Esempio n. 5
0
static char* insert_invalid_index(void) {
  linked_list_append(root, create_object(1));
  linked_list_append(root, create_object(2));
  linked_list_insert(root, create_object(3), 4);
  Object* object = (Object*)linked_list_get(root, 2);
  mu_assert(NULL != object && 3 == object->id, "Cannot insert item at an invalid index.");
  return 0;
}
Esempio n. 6
0
int add_bed_header_entry(bed_header_entry_t *header_entry, bed_file_t *bed_file) {
    if (linked_list_insert(header_entry, bed_file->header_entries)) {
        LOG_DEBUG_F("header entry %zu\n", bed_file->header_entries->size);
        return 1;
    } else {
        LOG_WARN_F("header entry %zu not inserted\n", bed_file->header_entries->size);
        return 0;
    }
}
Esempio n. 7
0
int add_bed_record(bed_record_t* record, bed_file_t *bed_file) {
    if (linked_list_insert(record, bed_file->records)) {
        LOG_DEBUG_F("record %zu\n", bed_file->records->size);
        return 1;
    } else {
        LOG_DEBUG_F("record %zu not inserted\n", bed_file->records->size);
        return 0;
    }
}
void test_insert()
{
	// regular insert
	linked_list* ll = linked_list_new();
	linked_list_insert(ll, 2);
	linked_list_insert(ll, 4);
	linked_list_insert(ll, 6);
	assert_equals(linked_list_size(ll), 3);
	assert_true(linked_list_contains(ll, 2));
	assert_true(linked_list_contains(ll, 4));
	assert_true(linked_list_contains(ll, 6));
	assert_false(linked_list_contains(ll, -1));
	assert_false(linked_list_contains(ll, 0));
	linked_list_clear(ll);
	linked_list* ll = linked_list_new();
	assert_equals(linked_list_size(ll), 0);
	assert_false(linked_list_contains(ll, 1));
	linked_list_insert(ll, 1);
	assert_equals(linked_list_size(ll), 1);
	assert_true(linked_list_contains(ll, 1));
	linked_list_clear(ll);
	// insert by index 
	// set by index 
}
Esempio n. 9
0
void X86CoreInsertInEventQueue(X86Core *self, struct x86_uop_t *uop)
{
	struct linked_list_t *event_queue = self->event_queue;
	struct x86_uop_t *item;

	assert(!uop->in_event_queue);
	linked_list_head(event_queue);
	for (;;)
	{
		item = linked_list_get(event_queue);
		if (!item || eventq_compare(uop, item) < 0)
			break;
		linked_list_next(event_queue);
	}
	linked_list_insert(event_queue, uop);
	uop->in_event_queue = 1;
}
Esempio n. 10
0
event_list_t * event_check(event_t * event, SYSTEMTIME * ntime, SYSTEMTIME * otime)
{
	linked_list_node_t * node = linked_list_first(event->all_event);

	linked_list_free(event->el.list);
	linked_list_create(&event->el.list);

	for(node; node; node = linked_list_next(node))
	{
		struct event_em_t * em = (struct event_em_t *)linked_list_data(node);
		
		if(event_em_compare(em, ntime, otime))
			linked_list_insert(event->el.list, 0, em);
	}

	return &event->el;
}
void test_lookup()
{
	// get 
	linked_list* ll = linked_list_new();
	int i;
	for (i = 0; i < 100; i++)
	{
		linked_list_insert(ll, i * 2);
	}
	assert_equals(linked_list_get(ll, 0), 0);
	assert_equals(linked_list_get(ll, 99), 99 * 2);
	assert_equals(linked_list_get(ll, 50), 50 * 2);
	// contains 
	assert_true(linked_list_contains(ll, 10));
	assert_false(linked_list_contains(ll, 1));
	// peek 
	//assert_equals(linked_list_first(ll), 0);
	// last 
	//assert_equals(linked_list_last(ll), 99 * 2);
	// index of 
}
Esempio n. 12
0
void evg_faults_init(void)
{
	FILE *f;
	char line[MAX_STRING_SIZE];
	char *line_ptr;
	struct evg_fault_t *fault;
	int line_num;
	long long last_cycle;

	evg_fault_list = linked_list_create();
	if (!*evg_faults_file_name)
		return;

	f = fopen(evg_faults_file_name, "rt");
	if (!f)
		fatal("%s: cannot open file", evg_faults_file_name);
	
	line_num = 0;
	last_cycle = 0;
	while (!feof(f))
	{
		const char *delim = " ";
	
		/* Read a line */
		line_num++;
		line_ptr = fgets(line, MAX_STRING_SIZE, f);
		if (!line_ptr)
			break;

		/* Allocate new fault */
		fault = calloc(1, sizeof(struct evg_fault_t));
		if (!fault)
			fatal("%s: out of memory", __FUNCTION__);

		/* Read <cycle> field */
		line_ptr = strtok(line_ptr, delim);
		if (!line_ptr)
			goto wrong_format;
		fault->cycle = atoll(line_ptr);
		if (fault->cycle < 1)
			fatal("%s: line %d: lowest possible cycle is 1",
				evg_faults_file_name, line_num);
		if (fault->cycle < last_cycle)
			fatal("%s: line %d: cycles must be ordered",
				evg_faults_file_name, line_num);

		/* <fault> - Type of fault */
		line_ptr = strtok(NULL, delim);
		if (!line_ptr)
			goto wrong_format;
		if (!strcmp(line_ptr, "ams"))
			fault->type = evg_fault_ams;
		else if (!strcmp(line_ptr, "reg"))
			fault->type = evg_fault_reg;
		else if (!strcmp(line_ptr, "mem"))
			fault->type = evg_fault_mem;
		else
			fatal("%s: line %d: invalid value for <fault> ('%s')",
				evg_faults_file_name, line_num, line_ptr);

		/* <cu_id> - Compute unit */
		line_ptr = strtok(NULL, delim);
		if (!line_ptr)
			goto wrong_format;
		fault->compute_unit_id = atoi(line_ptr);
		if (fault->compute_unit_id >= evg_gpu_num_compute_units || fault->compute_unit_id < 0)
			fatal("%s: line %d: invalid compute unit ID",
				evg_faults_file_name, line_num);

		/* Analyze rest of the line depending on fault type */
		switch (fault->type)
		{

		case evg_fault_ams:

			/* <stack_id> - Stack ID */
			line_ptr = strtok(NULL, delim);
			if (!line_ptr)
				goto wrong_format;
			fault->stack_id = atoi(line_ptr);
			if (fault->stack_id >= evg_gpu_max_wavefronts_per_compute_unit)
				fatal("%s: line %d: invalid stack ID",
					evg_faults_file_name, line_num);

			/* <am_id> - Active mask ID */
			line_ptr = strtok(NULL, delim);
			if (!line_ptr)
				goto wrong_format;
			fault->active_mask_id = atoi(line_ptr);
			if (fault->active_mask_id >= EVG_MAX_STACK_SIZE)
				fatal("%s: line %d: invalid active mask ID",
					evg_faults_file_name, line_num);

			/* <bit> */
			line_ptr = strtok(NULL, delim);
			if (!line_ptr)
				goto wrong_format;
			fault->bit = atoi(line_ptr);
			if (fault->bit >= evg_emu_wavefront_size)
				fatal("%s: line %d: invalid bit index",
					evg_faults_file_name, line_num);

			/* No more tokens */
			if (strtok(NULL, delim))
				fatal("%s: line %d: too many arguments",
					evg_faults_file_name, line_num);

			break;

		case evg_fault_reg:

			/* <reg_id> - Register ID */
			line_ptr = strtok(NULL, delim);
			if (!line_ptr)
				goto wrong_format;
			fault->reg_id = atoi(line_ptr);
			if (fault->reg_id >= evg_gpu_num_registers || fault->reg_id < 0)
				fatal("%s: line %d: invalid compute unit ID",
					evg_faults_file_name, line_num);

			/* <bit> */
			line_ptr = strtok(NULL, delim);
			if (!line_ptr)
				goto wrong_format;
			fault->bit = atoi(line_ptr);
			if (fault->bit < 0 || fault->bit >= 128)
				fatal("%s: line %d: invalid bit index",
					evg_faults_file_name, line_num);

			break;

		case evg_fault_mem:

			/* <byte> - Byte position in local memory */
			line_ptr = strtok(NULL, delim);
			if (!line_ptr)
				goto wrong_format;
			fault->byte = atoi(line_ptr);
			if (fault->byte >= evg_gpu_local_mem_size || fault->byte < 0)
				fatal("%s: line %d: invalid byte position",
					evg_faults_file_name, line_num);

			/* <bit> - Bit position */
			line_ptr = strtok(NULL, delim);
			if (!line_ptr)
				goto wrong_format;
			fault->bit = atoi(line_ptr);
			if (fault->bit > 7 || fault->bit < 0)
				fatal("%s: line %d: invalid bit position",
					evg_faults_file_name, line_num);

			break;
		}

		/* Insert fault in fault list */
		linked_list_out(evg_fault_list);
		linked_list_insert(evg_fault_list, fault);
		last_cycle = fault->cycle;
		continue;

wrong_format:
		fatal("%s: line %d: not enough arguments",
			evg_faults_file_name, line_num);
	}
	linked_list_head(evg_fault_list);
}
Esempio n. 13
0
void linked_list_add(struct linked_list_t *list, void *data)
{
	linked_list_out(list);
	linked_list_insert(list, data);
	linked_list_out(list);
}
Esempio n. 14
0
void suffix_mng_update(int chrom, size_t read_start, size_t read_end, 
		       size_t genome_start, size_t genome_end, 
		       suffix_mng_t *p) {

  if (!p) return;
  if (!p->suffix_lists) return;


  linked_list_t *suffix_list = p->suffix_lists[chrom];
  if (!suffix_list) return;

  seed_t *seed;

  if (linked_list_size(suffix_list) <= 0) {
    // list is empty, insert and return
    seed = seed_new(read_start, read_end, genome_start, genome_end);
    seed->chromosome_id = chrom;
    linked_list_insert(seed, suffix_list);
    p->num_seeds++;
    return;
  }
  
  linked_list_iterator_t* itr = linked_list_iterator_new(suffix_list);
  seed = (seed_t *) linked_list_iterator_curr(itr);
  while (seed != NULL) {
    // if it's included then return
    if (seed->chromosome_id == chrom && 
	seed->read_start <= read_start && seed->read_end >= read_end &&
	seed->genome_start <= genome_start && seed->genome_end >= genome_end) {
      
      // free memory
      linked_list_iterator_free(itr);
      return;
    } 
    
    // if it's previous then insert and return
    if (genome_start < seed->genome_start) {
      seed = seed_new(read_start, read_end, genome_start, genome_end);
      seed->chromosome_id = chrom;
      linked_list_iterator_insert(seed, itr);
      linked_list_iterator_prev(itr);
      p->num_seeds++;

      // free memory
      linked_list_iterator_free(itr);
      return;
    }
    
    //continue loop...
    linked_list_iterator_next(itr);
    seed = linked_list_iterator_curr(itr);
  }
  // insert at the last position
  seed = seed_new(read_start, read_end, genome_start, genome_end);
  seed->chromosome_id = chrom;
  linked_list_insert_last(seed, suffix_list);
  p->num_seeds++;

  // free memory
  linked_list_iterator_free(itr);
}
Esempio n. 15
0
static char* insert_empty(void) {
  linked_list_insert(root, create_object(1), 1);
  Object* object = (Object*)linked_list_get(root, 0);
  mu_assert(NULL != object && 1 == object->id, "Cannot insert item on empty list.");
  return 0;
}
Esempio n. 16
0
//====================================================================================
// apply_caling
//====================================================================================
int apply_caling(cal_seeker_input_t* input, batch_t *batch) {
  mapping_batch_t *mapping_batch = batch->mapping_batch;
  array_list_t *list = NULL;
  size_t read_index, num_cals;
  int min_seeds, max_seeds;


  cal_t *cal;
  array_list_t *cal_list;

  fastq_read_t *read;



  size_t num_chromosomes = input->genome->num_chromosomes + 1;
  size_t num_targets = mapping_batch->num_targets;
  size_t *targets = mapping_batch->targets;
  size_t new_num_targets = 0;
  array_list_t *region_list;
  bwt_anchor_t *bwt_anchor_back, *bwt_anchor_forw;
  linked_list_t *linked_list;
  int anchor_nt, gap_nt;
  seed_region_t *seed_region_start, *seed_region_end;
  //max_seeds = input->cal_optarg->num_seeds;
  
  //  size_t *new_targets = (size_t *) calloc(num_targets, sizeof(size_t));
  
  // set to zero
  mapping_batch->num_to_do = 0;

  for (size_t i = 0; i < num_targets; i++) {

    read_index = targets[i];
    read = array_list_get(read_index, mapping_batch->fq_batch); 
    region_list = mapping_batch->mapping_lists[read_index];
    // for debugging
    //    LOG_DEBUG_F("%s\n", ((fastq_read_t *) array_list_get(read_index, mapping_batch->fq_batch))->id);
    
    if (!list) {
      list = array_list_new(1000, 
			    1.25f, 
			    COLLECTION_MODE_ASYNCHRONIZED);
    }


    if (array_list_get_flag(region_list) == 0 || 
	array_list_get_flag(region_list) == 2) {
      //We have normal and extend seeds (anchors)
      max_seeds = (read->length / 15)*2 + 10;
      num_cals = bwt_generate_cal_list_linked_list(region_list,
						   input->cal_optarg,
						   &min_seeds, &max_seeds,
						   num_chromosomes,
						   list, read->length,
						   input->cal_optarg->min_cal_size, 0);
    } else {
      //We have double anchors with smaller distance between they
      //printf("Easy case... Two anchors and same distance between read gap and genome distance\n");
      num_cals = 0;
      for (int a = array_list_size(region_list) - 1; a >= 0; a -= 2) {
	max_seeds = 2;
	min_seeds = 2;
	bwt_anchor_back = array_list_remove_at(a, region_list);
	bwt_anchor_forw = array_list_remove_at(a - 1, region_list);

	linked_list = linked_list_new(COLLECTION_MODE_ASYNCHRONIZED);

	
	//Seed for the first anchor
	anchor_nt = bwt_anchor_forw->end - bwt_anchor_forw->start;
	//printf("\t seed0[%i-%i][%lu-%lu]\n", 0, anchor_nt - 1,
	//     bwt_anchor_forw->start, bwt_anchor_forw->end);
	seed_region_start = seed_region_new(0, anchor_nt - 1,
					    bwt_anchor_forw->start, bwt_anchor_forw->end, 0, 0, 0);

	//Seed for the first anchor
	gap_nt = read->length - (anchor_nt + (bwt_anchor_back->end - bwt_anchor_back->start));
	//printf("\t gap_nt = %i, anchor_nt = %i\n", gap_nt, anchor_nt);
	//printf("\t seed1[%i-%i][%lu-%lu]\n", anchor_nt + gap_nt, read->length - 1, 
	//     bwt_anchor_back->start + 1, bwt_anchor_back->end);
	seed_region_end = seed_region_new(anchor_nt + gap_nt, read->length - 1,
					  bwt_anchor_back->start + 1, bwt_anchor_back->end, 1, 0, 0);

	//The reference distance is 0 and the read distance not
	//The read distance is 0 and the reference distance not
	//if (seed_region_start->genome_end > seed_region_end->genome_start || 
	//  seed_region_start->read_end > seed_region_end->read_start) { 
	//array_list_clear(region_list, NULL);
	//continue;
	if (seed_region_end->genome_start - seed_region_start->genome_end < 5 || 
	    seed_region_end->read_start - seed_region_start->read_end < 5) {
	  seed_region_start->genome_end -= 5;
	  seed_region_start->read_end -= 5;
	  seed_region_end->genome_start += 5;
	  seed_region_end->read_start += 5;
	}

	linked_list_insert(seed_region_start, linked_list);
	linked_list_insert_last(seed_region_end, linked_list);

	cal = cal_new(bwt_anchor_forw->chromosome + 1,
		      bwt_anchor_forw->strand,
		      bwt_anchor_forw->start,
		      bwt_anchor_back->end + 1,
		      2,
		      linked_list,
		      linked_list_new(COLLECTION_MODE_ASYNCHRONIZED));
	array_list_insert(cal, list);
	num_cals++;
      }
    }

    // for debugging
    LOG_DEBUG_F("read %s : num. cals = %i, min. seeds = %i, max. seeds = %i\n", 
		read->id, num_cals, min_seeds, max_seeds);


    /*    if (num_cals == 0) {
      int seed_size = 24;
      //First, Delete old regions
      array_list_clear(mapping_batch->mapping_lists[read_index], region_bwt_free);
      //Second, Create new regions with seed_size 24 and 1 Mismatch
      bwt_map_inexact_seeds_seq(read->sequence, seed_size, seed_size/2,
				bwt_optarg, bwt_index, 
				mapping_batch->mapping_lists[read_index]);

      num_cals = bwt_generate_cal_list_linked_list(mapping_batch->mapping_lists[mapping_batch->targets[i]], 
						   input->cal_optarg,
						   &min_seeds, &max_seeds,
						   num_chromosomes,
						   list, read->length);
						   }*/

    /*
    for (size_t j = 0; j < num_cals; j++) {
      cal = array_list_get(j, list);
      LOG_DEBUG_F("\tchr: %i, strand: %i, start: %lu, end: %lu, num_seeds = %i, num. regions = %lu\n", 
		  cal->chromosome_id, cal->strand, cal->start, cal->end, cal->num_seeds, cal->sr_list->size);
    }
    */
    //    printf("min_seeds = %i, max_seeds = %i, min_limit = %i, num_cals = %i\n", 
    //	   min_seeds, max_seeds, min_limit, array_list_size(list));

    // filter incoherent CALs
    int founds[num_cals], found = 0;
    for (size_t j = 0; j < num_cals; j++) {
      founds[j] = 0;
      cal = array_list_get(j, list);
      LOG_DEBUG_F("\tcal %i of %i: sr_list size = %i (cal->num_seeds = %i) %i:%lu-%lu\n", 
		  j, num_cals, cal->sr_list->size, cal->num_seeds,
		  cal->chromosome_id, cal->start, cal->end);
      if (cal->sr_list->size > 0) {
	int start = 0;
	for (linked_list_item_t *list_item = cal->sr_list->first; list_item != NULL; list_item = list_item->next) {
	  seed_region_t *s = list_item->item;
	  
	  LOG_DEBUG_F("\t\t:: star %lu > %lu s->read_start\n", start, s->read_start);
	  if (start > s->read_start) {
	    LOG_DEBUG("\t\t\t:: remove\n");
	    found++;
	    founds[j] = 1;
	  }
	  start = s->read_end + 1;
	}
      } else {
	found++;
	founds[j] = 1;
      }
    }
    if (found) {
      min_seeds = 100000;
      max_seeds = 0;
      cal_list = array_list_new(MAX_CALS, 1.25f, COLLECTION_MODE_ASYNCHRONIZED);
      for (size_t j = 0; j < num_cals; j++) {
	if (!founds[j]) {
	  cal = array_list_get(j, list);
	  cal->num_seeds = cal->sr_list->size;
	  if (cal->num_seeds > max_seeds) max_seeds = cal->num_seeds;
	  if (cal->num_seeds < min_seeds) min_seeds = cal->num_seeds;
	  array_list_insert(cal, cal_list);
	  array_list_set(j, NULL, list);
	}
      }
      array_list_free(list, (void *) cal_free);
      num_cals = array_list_size(cal_list);
      list = cal_list;
    }
  
    //    LOG_FATAL_F("num. cals = %i, min. seeds = %i, max. seeds = %i\n", num_cals, min_seeds, max_seeds);
    // filter CALs by the number of seeds

    cal_list = list;
    list = NULL;
    /*
    int min_limit = input->cal_optarg->min_num_seeds_in_cal;

    if (min_limit < 0) min_limit = max_seeds;
    //    min_limit -= 3;
    
    if (min_seeds == max_seeds || min_limit <= min_seeds) {
      cal_list = list;
      list = NULL;
    } else {
      cal_list = array_list_new(MAX_CALS, 1.25f, COLLECTION_MODE_ASYNCHRONIZED);
      for (size_t j = 0; j < num_cals; j++) {
	cal = array_list_get(j, list);
	if (cal->num_seeds >= min_limit) {
	  array_list_insert(cal, cal_list);
	  array_list_set(j, NULL, list);
	}
      }
      array_list_clear(list, (void *) cal_free);
      num_cals = array_list_size(cal_list);
    }
    */
    if (num_cals > MAX_CALS) {
      for (size_t j = num_cals - 1; j >= MAX_CALS; j--) {
	cal = (cal_t *) array_list_remove_at(j, cal_list);
	cal_free(cal);
      }
      num_cals = array_list_size(cal_list);
    }
    
    //    LOG_DEBUG_F("num. cals = %i, MAX_CALS = %i\n", num_cals, MAX_CALS);

    if (num_cals > 0 && num_cals <= MAX_CALS) {
      array_list_set_flag(2, cal_list);
      targets[new_num_targets++] = read_index;

      /*
      int count1 = 0, count2 = 0;
      // count number of sw to do

      // method #1
      //      printf("method #1\n");
      seed_region_t *s, *prev_s;
      linked_list_iterator_t* itr;
      for (size_t j = 0; j < num_cals; j++) {
	prev_s = NULL;
	cal = array_list_get(j, cal_list);
	itr = linked_list_iterator_new(cal->sr_list);
	s = (seed_region_t *) linked_list_iterator_curr(itr);
	while (s != NULL) {
	  if ((prev_s == NULL && s->read_start != 0) || (prev_s != NULL)) {
	    //	    printf("\t\t\tcase 1\n");
	    count1++;
	  }
	  prev_s = s;
	  linked_list_iterator_next(itr);
	  s = linked_list_iterator_curr(itr);
	}
	if (prev_s != NULL && prev_s->read_end < read->length - 1) { 
	  count1++;
	  //	  printf("\t\t\tcase 2 (%i < %i)\n", prev_s->read_end, read->length - 1);
	}
	linked_list_iterator_free(itr);
      }

      // method #2
      printf("method #2\n");
      for (size_t j = 0; j < num_cals; j++) {
	cal = array_list_get(j, cal_list);
	printf("\t: %i\n", j);
	if (cal->sr_list->size > 0) {
	  int start = 0;
	  for (linked_list_item_t *list_item = cal->sr_list->first; list_item != NULL; list_item = list_item->next) {
	    seed_region_t *s = list_item->item;
	    printf("\t\t[%i|%i - %i|%i]\n", s->genome_start, s->read_start, s->read_end, s->genome_end);
	    if (s->read_start != start) {
	      count2++;
	    }
	    start = s->read_end + 1;
	  }
	  if (start < read->length) { 
	    count2++;
	  }
	}
      }
      printf("count #1 = %i, count #2 = %i\n", count1, count2);
      assert(count1 == count2);

      mapping_batch->num_to_do += count1;
*/

      // we have to free the region list
      array_list_free(mapping_batch->mapping_lists[read_index], (void *) region_bwt_free);
      mapping_batch->mapping_lists[read_index] = cal_list;
    } else {
      array_list_set_flag(0, mapping_batch->mapping_lists[read_index]);
      // we have to free the region list
      array_list_clear(mapping_batch->mapping_lists[read_index], (void *) region_bwt_free);
      if (cal_list) array_list_free(cal_list, (void *) cal_free);
      if (list) array_list_clear(list, (void *) cal_free);
    }

    /*    
    cal_list = list;
    list = NULL;
    array_list_set_flag(2, cal_list);
    //    mapping_batch->num_to_do += num_cals;
    targets[new_num_targets++] = read_index;
    
    // we have to free the region list
    array_list_free(mapping_batch->mapping_lists[read_index], (void *) region_bwt_free);
    mapping_batch->mapping_lists[read_index] = cal_list;
    */
    /*
    // filter CALs by the number of seeds
    int min_limit = input->cal_optarg->min_num_seeds_in_cal;
    if (min_limit < 0) min_limit = max_seeds;

    printf("min_seeds = %i, max_seeds = %i, min_limit = %i, num_cals = %i\n", 
	   min_seeds, max_seeds, min_limit, array_list_size(list));
    
    if (min_seeds == max_seeds || min_limit <= min_seeds) {
      cal_list = list;
      list = NULL;
    } else {
      cal_list = array_list_new(MAX_CALS, 1.25f, COLLECTION_MODE_ASYNCHRONIZED);
      for (size_t j = 0; j < num_cals; j++) {
	cal = array_list_get(j, list);
	if (cal->num_seeds >= min_limit) {
	  array_list_insert(cal, cal_list);
	  array_list_set(j, NULL, list);
	}
      }
      array_list_clear(list, (void *) cal_free);
      num_cals = array_list_size(cal_list);
      printf("************, num_cals = %i\n", num_cals);
    }

    if (num_cals > MAX_CALS) {
      for (size_t j = num_cals - 1; j >= MAX_CALS; j--) {
	cal = (cal_t *) array_list_remove_at(j, cal_list);
	cal_free(cal);
      }
      num_cals = array_list_size(cal_list);
    }

    if (num_cals > 0 && num_cals <= MAX_CALS) {
      array_list_set_flag(2, cal_list);
      mapping_batch->num_to_do += num_cals;
      targets[new_num_targets++] = read_index;
      
      // we have to free the region list
      array_list_free(mapping_batch->mapping_lists[read_index], (void *) region_bwt_free);
      mapping_batch->mapping_lists[read_index] = cal_list;
    } else {
      array_list_set_flag(0, mapping_batch->mapping_lists[read_index]);
      // we have to free the region list
      array_list_clear(mapping_batch->mapping_lists[read_index], (void *) region_bwt_free);
      if (cal_list) array_list_free(cal_list, (void *) cal_free);
      if (list) array_list_clear(list, (void *) cal_free);
    }
    */
  } // end for 0 ... num_targets

  // update batch
  mapping_batch->num_targets = new_num_targets;

  //  LOG_DEBUG_F("num. SW to do: %i\n", 	mapping_batch->num_to_do);

  //  exit(-1);

  // free memory
  if (list) array_list_free(list, NULL);

  if (batch->mapping_mode == RNA_MODE) {
    return RNA_STAGE;
  }

  if (batch->pair_input->pair_mng->pair_mode != SINGLE_END_MODE) {
    return PRE_PAIR_STAGE;
  } else if (batch->mapping_batch->num_targets > 0) {
    return SW_STAGE;
  }
  
  return DNA_POST_PAIR_STAGE;
}
Esempio n. 17
0
 /*******************************************************
 * split_cell
 *******************************************************/
int split_cell( int icell ) 
/* purpose: splits the given cell into num_children and
 * 	handles tree variables (does NOT handle interpolation
 * 	of actual cell variables.
 *
 * returns: 	 0	if operation is successful
 * 		-1	if cell is already split
 * 		-2	if there are no free octs remaining
 * NO LONGER USED: we need to use this function on buffer
 * 	cells which may violate +/- 1 refinement criteria
 * 	since they are pruned, so the refinement check
 * 	is moved to split
 *  		-4	if the split would violate the 
 * 				+/- 1 refinement criteria
 */
{
	int i;
	int oct_ptr;
	int type;

	cart_assert ( icell >= 0 && icell < num_cells );
	cart_assert ( cell_level( icell ) < max_level );

	/* make sure cell isn't already split */
	if ( cell_is_refined(icell) ) {
		cart_debug("split_cell(%u) error: cell already refined!", icell );
		return -1;
	}

	/* allocate a new oct */
	oct_ptr = oct_alloc();

	/* make sure we haven't run out of octs */
	if ( oct_ptr == NULL_OCT ) {
		return -2;
	}

	oct_level[oct_ptr] = cell_level(icell)+1;
	cart_assert( oct_level[oct_ptr] > min_level && oct_level[oct_ptr] <= max_level );

	/* add oct to appropriate linked list */
	type = root_cell_type( cell_parent_root_sfc(icell) );
	if ( type == CELL_TYPE_LOCAL ) {
		linked_list_insert( &local_oct_list[oct_level[oct_ptr]], oct_ptr );
		num_cells_per_level[oct_level[oct_ptr]] += num_children;
	} else if ( type == CELL_TYPE_BUFFER ) {
		linked_list_insert( &buffer_oct_list[oct_level[oct_ptr]], oct_ptr );
		num_buffer_cells[oct_level[oct_ptr]] += num_children;
	} else {
		cart_error("Bad cell type in split_cell!");
	}

	/* set up oct neighbors */
	cell_all_neighbors( icell, oct_neighbors[oct_ptr] );

	/* set up oct position */
	cell_center_position( icell, oct_pos[oct_ptr] );

	/* set up new oct */
	oct_parent_cell[oct_ptr] = icell;
	oct_parent_root_sfc[oct_ptr] = cell_parent_root_sfc(icell);

	/* set all newly allocated children to leaves */
	for ( i = 0; i < num_children; i++ ) {
		cell_child_oct[ oct_child( oct_ptr, i ) ] = UNREFINED_CELL;
	}

	/* set cell child pointer */
	cell_child_oct[icell] = oct_ptr;

#ifdef PARTICLES
	for ( i = 0; i < num_children; i++ ) {
		cell_particle_list[ oct_child( oct_ptr, i ) ] = NULL_PARTICLE;
	}

	split_particle_list( icell );
#endif /* PARTICLES */

#ifdef HYDRO_TRACERS
	for ( i = 0; i < num_children; i++ ) {
		cell_tracer_list[ oct_child( oct_ptr, i ) ] = NULL_TRACER;
	}

	split_tracer_list( icell );
#endif /* HYDRO_TRACERS */

	return 0;
}