Пример #1
0
static void sort(void *base, size_t nmemb) {
#ifdef  DEBUG
    void *init_base = base;
    size_t init_nmemb = nmemb;
    if (init_nmemb > 1) dump_array("sort() start in " __FILE__, init_base, init_nmemb, 0, 0, length);
#endif
    while (nmemb > 1) {
#ifdef DEBUG
        qsort_called++;
        dump_array("sort() partition start.", base, nmemb, 0, 0, length);
#endif
#define first (char *)base
        char *last = first + (nmemb - 1) * length;  // point the last element
#ifdef  DEBUG
        if (trace_level >= TRACE_DUMP) fprintf(OUT, "pivot <-- %s [last]\n", dump_data(last));
#endif
        char pivot[length], *hole; copy(pivot, hole = last);    // save the last element as a pivot
        char *lo = first, *hi = last - length;  // search pointers
        for (; lo < hole; lo += length) {       // outer loop
            if (comp(lo, pivot) > 0) {
#ifdef  DEBUG
                if (trace_level >= TRACE_DUMP) fprintf(OUT, "move %s --> %s\n", dump_data(lo), dump_data(hole));
#endif
                copy(hole, lo); hole = lo;  // move a hole to lo.
                for (; hi > hole; hi -= length) {   // inner loop, symmetric to the outer loop
                    if (comp(hi, pivot) < 0) {      // symmetric comparison
#ifdef  DEBUG
                        if (trace_level >= TRACE_DUMP) fprintf(OUT, "move %s <-- %s\n", dump_data(hole), dump_data(hi));
#endif
                        copy(hole, hi); hole = hi;  // move a hole to hi
                    }
                }
            }
        }
#ifdef  DEBUG
        if (trace_level >= TRACE_DUMP) fprintf(OUT, "restore pivot %s to %s [%s]\n",
                dump_data(pivot), dump_data(hole), dump_size_t(NULL, (hole - first) / length));
#endif
        copy(hole, pivot);  // restore
        size_t  n_lo = (hole - first) / length; // the number of elements in lower partition
        size_t  n_hi = (last - hole) / length;
#ifdef DEBUG
        dump_array("sort() partitioned.", base, n_lo, 1, n_hi, length);
        dump_rate(n_lo, n_hi);
#endif
        // recursion and iteration
        if (n_lo < n_hi) {
            sort(base, n_lo);   // shorter sub-array consists of lesser elements
            nmemb = n_hi; base = hole + length; // prepare to the next loop
        } else {    // n_lo >= n_hi
            sort(hole + length, n_hi);  // greater or equal elements
            nmemb = n_lo;
        }
    }
#ifdef DEBUG
    if (init_nmemb > 1) dump_array("sort() done.", init_base, init_nmemb, 0, 0, length);
#endif
}
Пример #2
0
int main(void)
{
    int array[] = { 38, 27, 43, 3, 9, 82, 10 };
    size_t arrlen = sizeof(array) / sizeof(array[0]);

    dump_array("Before:", array, arrlen);
    merge_sort(array, arrlen);
    dump_array("After:", array, arrlen);
    return 0;
}
Пример #3
0
int main(int argc, char** argv){
    printf("Before merge sort:\n");
    dump_array(A);
    
    merge_sort(A, 0, 8);
    
    printf("After merge sort:\n");
    dump_array(A);
    return 0;
    //return test_merge();
 }
Пример #4
0
void dump_value(pTHX_ SV* val, Buffer* buf)
{
    if (!val) {
      return;
    }

    if (SvIOK(val)) {
        char str[50];
        int len = sprintf(str, "%ld", (long) SvIV(val));
        buffer_append(buf, str, len);
    } else if (SvNOK(val)) {
        char str[50];
        int len = sprintf(str, "%lf", (double) SvNV(val));
        buffer_append(buf, str, len);
    } else if (SvPOK(val)) {
        STRLEN len;
        char* str = SvPV(val, len);
        buffer_append(buf, "\"", 1);
        buffer_append(buf, str, len);
        buffer_append(buf, "\"", 1);
    } else if (SvROK(val)) {
        SV* rv = SvRV(val);
        if (SvTYPE(rv) == SVt_PVAV) {
            dump_array(aTHX_ (AV*) rv, buf);
        } else if (SvTYPE(rv) == SVt_PVHV) {
            dump_hash(aTHX_ (HV*) rv, buf);
        }
    }
}
Пример #5
0
void ngx_array_t_test()
{
	ngx_pool_t* pool;
	int i = 0;

	printf("--------------------------------\n");
   	printf("the size of ngx_array_t: \n");
	printf("--------------------------------\n");
	printf("%lu\n\n", sizeof(ngx_array_t));

	printf("--------------------------------\n");
	printf("create a new pool: \n");
	printf("--------------------------------\n");
	pool = ngx_create_pool(1024, NULL);
	dump_pool(pool);

	printf("--------------------------------\n");
	printf("alloc an array from the pool: \n");
	printf("--------------------------------\n");
	ngx_array_t* array = ngx_array_create(pool, 10, sizeof(int));
	dump_pool(pool);

	for(i = 0; i < 100; ++i)
	{
		int* ptr = ngx_array_push(array);
		*ptr = i + 1;
	}

	dump_array(array);

	ngx_array_destroy(array);
	ngx_destroy_pool(pool);
}
Пример #6
0
/*
 * demonstrate the differences between pointer and array
 */
int main(void) {
    char str[] = {'h', 'e', 'l', 'l', 'o', '\0'};
    char *p = str;
    dump_array(&str);

    return 0;
}
Пример #7
0
static void sort(void *base, size_t nmemb) {
    if (nmemb <= 1) return; // 0 or 1
#ifdef DEBUG
    qsort_called++;
    dump_array("sort() start in " __FILE__, base, nmemb, 0, 0, length);
#endif
#define first   ((char *)base)
    char *last = first + (nmemb - 1) * length;
    char *middle = first + (nmemb >> 1) * length;
    char *pivot = nmemb <= small_boundary ? middle :
                 (comp(first, last) < 0 ?
                 (comp(middle, first) < 0 ? first: (comp(middle,  last) < 0 ? middle : last)) :
                 (comp(middle, last ) < 0 ? last : (comp(middle, first) < 0 ? middle : first)));
#ifdef DEBUG
    if (trace_level >= TRACE_DUMP) {
        if (nmemb <= small_boundary)
            fprintf(OUT, "pivot is the middle element %s\n", dump_data(middle));
        else fprintf(OUT, "pivot = %s\tfrom (%s, %s, %s)\n"
            , dump_data(pivot), dump_data(first), dump_data(middle), dump_data(last));
    }
#endif
    swap(first, pivot);
    char *lo = pivot = first;
    char *hi = last + length;
    while (TRUE) {
        while(comp(lo += length, pivot) < 0) if (lo >= last) break;
        while(comp(hi -= length, pivot) > 0) if (hi <= first) break;
#ifdef  DEBUG
        if (trace_level >= TRACE_DEBUG) fprintf(OUT, "lo = %s\thi = %s\n"
                , dump_data(lo), dump_data(hi));
#endif
        if (lo >= hi) break;
        swap(lo, hi);
    }
    swap(first, hi);
    size_t  n_lo = (hi - first) / length;   // number of elements in lower partition
    size_t  n_hi = (last - hi) / length;
#ifdef  DEBUG
    dump_array("sort() partitioned.", base, n_lo, 1, n_hi, length);
    dump_rate(n_lo, n_hi);
#endif
    sort(first, n_lo);
    sort(hi + length, n_hi);
#ifdef DEBUG
    dump_array("sort() done.", base, nmemb, 0, 0, length);
#endif
}
Пример #8
0
int write_C(char * file, char * argv[])
{
	FILE * o;
	char buf[SIZE];
	int l;

	sprintf(buf, "%s.x.c", file);
	o = fopen(buf, "w");
	if (!o)
		return -1;
	srand((unsigned)time(NULL));
	fprintf(o, "#if 0\n");
	fprintf(o, "\t%s %s, %s\n", my_name, version, subject);
	fprintf(o, "\t%s %s %s %s\n\n\t", cpright, author.f, author.s, author.e);
	for (l = 0; argv[l]; l++)
		fprintf(o, "%s ", argv[l]);
	fprintf(o, "\n#endif\n\n");
	fprintf(o, "static  long date = %ld;\n", date);
	fprintf(o, "static  char mail[] = \"%s\";\n", mail);
	fprintf(o, "static  int  relax = %d;\n", relax);
	l = noise(buf, 256, 256, 0);
	dump_array(o, buf, "pswd", l);
	state_0();
	key(buf, l);
	dump_array(o, strdup(shll), "shll", strlen(shll) + 1);
	dump_array(o, inlo, "inlo", strlen(inlo) + 1);
	dump_array(o, xecc, "xecc", strlen(xecc) + 1);
	dump_array(o, lsto, "lsto", strlen(lsto) + 1);
	l = noise(buf, 8, 8, 1);
	fprintf(o, "#define TEXT_%s	\"%s\"\n", "chk1", buf);
	dump_array(o, buf, "chk1", l + 1);
	if (!relax && key_with_file(shll)) {
		fprintf(stderr, "%s: invalid file name: %s", my_name, shll);
		perror("");
		exit(1);
	}
	dump_array(o, opts, "opts", strlen(opts) + 1);
	dump_array(o, text, "text", strlen(text) + 1);
	l = noise(buf, 8, 8, 1);
	fprintf(o, "#define TEXT_%s	\"%s\"\n", "chk2", buf);
	dump_array(o, buf, "chk2", l + 1);
	fprintf(o, "typedef char %s_t[%d];\n\n", "hide", 1<<12);
	fprintf(o, DEBUGEXEC_line, DEBUGEXEC_flag);
	fprintf(o, TRACEABLE_line, TRACEABLE_flag);
	for (l = 0; RTC[l]; l++)
		fprintf(o, "%s\n", RTC[l]);
	fflush(o);
	fclose(o);
	return 0;
}
Пример #9
0
int main() {
  /* Uncomment the next line if you'd prefer different output every time. */
  /* srand(time(0)); */


  /* What is sizeof(d3)?
     What is sizeof(d3[1])?
     What is sizeof(d3[1][0]?
     What is sizeof(d3[1][1][1]?
  */
  int d3[D1][D2][D3];

  /* 
     In words, what is the data type of d3?
     In words, what is the data type of *d3?
     In words, what is the data type of **d3?
     In words, what is the data type of ***d3?

     What is the data type of ptr?
  */
  int* ptr = (int*) d3;

  /* 
     Your compiler should not issue any warning/error on the line above.
     What not?

     What if the line changes to:

     int* ptr = d3;

     What happens then with the compiler and why?
  */

  
  int n =  D1 * D2 * D3 * sizeof(int) - sizeof(int);

  /* What does this next C statement do? In particular, why is d3 cast to an int? */
  /* Why, in the initialization of n above, do I subtract sizeof(int) at the end? */
  int* foo = (int*) ((int) d3 + n);


  /* Explain, in words and/or pictures, what this loop does. */
  while (foo >= ptr) {
    *foo = rand() % UB; /* generate and assign a 1-digit or 2-digit integer */
    foo--;              /* Explain in words or pictures what's going on here. */
    
  }
  /* What would happen if the while  test were changed to

         while (foo > ptr)
  */
  
  dump_array(d3); /* Could I call dump_array(ptr) here? Explain. */

  return 0;
}
Пример #10
0
int main(void)
{
	int a[] = {23, 58, 100, 500, 808, -58, -15, -10, -9, -2};
	int temp[size];
	int i, neg_pos;
	
	dump_array("original: ", size, a);

	for(i = 0; i < size; i++)
	{
		if(a[i] < 0)
		{
			neg_pos = i;
			break;
		}
	}
	int num_negs = (size - neg_pos);
	int num_pos = (size - num_negs);

	//shift negatives to beginning of buff
	for(i = 0; i < num_negs; i++)
	{
		temp[i] = a[neg_pos + i];
	}
	
	//shift positives to end of buffer
	for(i =0; i < num_pos; i++)
	{
		temp[neg_pos + i] = a[i];
	}
	
	//transfer buff contents to originl
	for(i = 0; i < size; i++)
	{
		a[i] = temp[i];
	}
	dump_array("final: ", size, a);

	return 0;
}
Пример #11
0
static void merge(int *left, size_t l_len, int *right, size_t r_len, int *output)
{
    size_t r_pos = 0;
    size_t l_pos = 0;
    size_t o_pos = 0;
    enter_func(__func__);
    dump_array("Left:", left, l_len);
    dump_array("Right:", right, r_len);
    while (r_pos < r_len && l_pos < l_len)
    {
        if (right[r_pos] < left[l_pos])
            output[o_pos++] = right[r_pos++];
        else
            output[o_pos++] = left[l_pos++];
    }
    while (r_pos < r_len)
        output[o_pos++] = right[r_pos++];
    while (l_pos < l_len)
        output[o_pos++] = left[l_pos++];
    dump_array("Output:", output, r_len + l_len);
    exit_func(__func__);
}
Пример #12
0
int main(int argc, char **argv)
{
	int i, group = 8, bin = 256;
	int buff[N];
	int lst[] = {0x7fda8d60, 0x7e03cffb, 0x7b65dedb, 0x7a395300};
	int sorted[] = {0x7e03cffb,0x7fda8d60,-0x7b65dedb,-0x7a395300};
	int ints[] = {1021542644 , 2044511900 , 1736498784 , 103143327};
	//int ints_copy[N], buff2[N]; 

	dump_array("original: ", N, ints);
	//radix_sort(0, lst, buff);

	//flag = LST;
	
	for(i =0; i < MAXBIT; i = i + group)
	{
		radix_sort(i, ints, buff);
	}
	
	//correct(sorted);
	dump_array("after sort iA: ", N, buff);
}
Пример #13
0
static void sort(void *base, size_t nmemb) {
    if (nmemb <= 1) return; // 0 or 1
#define first   ((char *)base)
#ifdef DEBUG
    qsort_called++;
    dump_array("sort() start in " __FILE__, base, nmemb, 0, 0, length);
#endif
    char *last = base + (nmemb - 1) * length;
    char *lt = first, *p = first + length, *gt = last;
    char pivot[length]; copy(pivot, first);
    while (p <= gt) {
#ifdef  DEBUG
        if (trace_level >= TRACE_DEBUG) fprintf(OUT, "*p = %s\n", dump_data(p));
#endif
        int chk = comp(p, pivot);
        if (chk < 0) {
            swap(p, lt);
            lt += length; p += length;
        }
        else if (chk > 0) {
            swap(p, gt);
            gt -= length;
        }
        else
            p += length;
    }
    size_t  n_lo = (lt - first) / length;   // number of elements in lower partition
    size_t  n_hi = (last - gt) / length;
#ifdef  DEBUG
    dump_array("sort() partitioned.", base, n_lo, 1, n_hi, length);
    dump_rate(n_lo, n_hi);
#endif
    sort(first, n_lo);
    sort(gt + length, n_hi);
#ifdef DEBUG
    dump_array("sort() done.", base, nmemb, 0, 0, length);
#endif
}
Пример #14
0
std::ostream& operator <<(std::ostream& os, const Event& event)
{
    os << "Event{ " << event.id << ", " <<
            event.model.getEventTrigger(event.id) << ", " <<
            event.isExpired() << ", " << event.isCurrent() << ", " <<
            event.getPriority() << ", " << event.delay << ", " <<
            event.assignTime << ", ";

    dump_array(os, event.dataSize, event.data);

    os << "}";

    return os;
}
void quick_sort_body(int left,int right,int data[]){
  printf("quick [%d to %d]\n",left,right);
  dump_array(data,10);
  int l,r,pivot,temp;
  
  if(left>=right-1) return;
  
  //(1)適当に1つ選ぶ(とりあえず、調査区間の真ん中のやつ)
  pivot=data[(left + right) / 2];
  
  //(2)調査区間(topからbottomまで)を調べる
  for(l=left, r=right; l<r;){
  //while(1){
    
    //(3)左側でしきい値より大きい物を探し、その位置を左indexとする
    //while(l<=r && data[l]<=pivot){
    while(l<=r && data[l]<pivot){
      printf("%d <= %d\n",data[l],pivot);
      l++;
    }
    
    //(4)右側でしきい値より小さい物を探し、その位置を右indexとする
    while(l<=r && pivot<data[r]){
      printf("%d > %d\n",data[r],pivot);
      r--;
    }
    
    if(l<r){//左indexが右indexより小さかったら値を入れ替え
      temp=data[l];
      data[l]=data[r];
      data[r]=temp;
    }//else if(l>=r) break;//左indexが右indexより大きくなってしまったら終了
    
    //l++;
    //r--;
  }
  
  //最初に選択した値を真ん中に持ってく
  
  temp=data[left];
  data[left]=data[r];
  data[r]=temp;
  
  if(left < l-1)//左側にまだ2つ以上残ってたら
    quick_sort_body(left,l-1,data);
  
  if(r+1 < right)//右側にまだ2つ以上残ってたら
    quick_sort_body(r+1,right,data);
  
}
Пример #16
0
void merge_sort(int *array, size_t len)
{
    if (len <= 1)
        return;
    int left[(len+1)/2];
    int l_pos = 0;
    int right[(len+1)/2];
    int r_pos = 0;
    size_t mid = len / 2;

    enter_func(__func__);
    dump_array("Input:", array, len);
    for (size_t i = 0; i < mid; i++)
        left[l_pos++] = array[i];
    for (size_t i = mid; i < len; i++)
        right[r_pos++] = array[i];
    dump_array("Left:", left, l_pos);
    dump_array("Right:", right, r_pos);
    merge_sort(left, l_pos);
    merge_sort(right, r_pos);
    merge(left, l_pos, right, r_pos, array);
    dump_array("Result:", array, len);
    exit_func(__func__);
}
void
dump_dest_ref (OilTest *test)
{
  int i;
  for(i=0;i<OIL_ARG_LAST;i++){
    OilParameter *p = &test->params[i];
    if (p->is_pointer) {
      if (p->direction == 'd') {
        printf ("  %s:\n", p->parameter_name);
        dump_array (p->ref_data + p->test_header,
            p->ref_data + p->test_header,
            p->type, p->pre_n, p->stride, p->post_n);
      }
    }
  }
}
	std::wostream& operator <<(std::wostream& os, out_mark<pp_as_t<pp::array_any, array_info_t<T,U> > > const & vv ){

		auto const unmarked_v = vv.m_v.m_val;
		auto const v = unmarked_v.m_value;

		size_t count = unmarked_v.m_in_count;

		if( unmarked_v.m_out_count && *unmarked_v.m_out_count<=unmarked_v.m_in_count ){
			count = *unmarked_v.m_out_count;
		}

		os << pp_as<pp::hex_auto>( static_cast<void const*>(v) ) <<L"=";
		if(v){
			dump_array(os, v, count);
		} else {
			os << STC_P_NULL_LIT;
		}
		return os;
	}
Пример #19
0
int
main(int argc, char * * argv)
{
  struct codebook * *	cb = malloc(argc * sizeof(struct codebook *));
  int			i;

  if ( argc < 2 ) {
    fprintf(stderr, usage, argv[0]);
    fprintf(stderr, format);
    exit(1);
  }

  for ( i = 0; i < argc - 2; i++ ) {
    FILE *	in = fopen(argv[i + 2], "r");

    if ( in == NULL ) {
      perror(argv[i + 2]);
      exit(1);
    }

    cb[i] = load(in, argv[i + 2]);

    fclose(in);
  }

  printf(header);
  for ( i = 0; i < argc - 2; i++ ) {
    printf("  /* %s */\n", argv[i + 2]);
    dump_array(cb[i], i);
  }
  printf("\nconst struct lsp_codebook %s[] = {\n", argv[1]);
  for ( i = 0; i < argc - 2; i++ ) {
    printf("  /* %s */\n", argv[i + 2]);
    dump_structure(cb[i], i);
    printf(",\n");
  }
  printf("  { 0, 0, 0, 0 }\n");
  printf("};\n");

  return 0;
}
int
check_test (OilTest *test)
{
  int i, failed = 0;
  for(i=0;i<OIL_ARG_LAST;i++){
    OilParameter *p = &test->params[i];
    if (p->is_pointer) {
      if (p->direction == 'i' || p->direction == 'd') {
	if (!test_difference(p->test_data + p->test_header,
            p->ref_data + p->test_header,
            p->type, p->pre_n, p->stride, p->post_n))
	  continue;
        printf (" Failure in %s (marked by *, ref in ()):\n",
	    p->parameter_name);
        dump_array (p->test_data + p->test_header,
            p->ref_data + p->test_header,
            p->type, p->pre_n, p->stride, p->post_n);
	failed = 1;
      }
    }
  }
  return failed;
}
Пример #21
0
static void verify_rebirth_round_robin(const servers_fixture *f,
                                       grpc_channel *client,
                                       const int *actual_connection_sequence,
                                       const size_t num_iters) {
  int *expected_connection_sequence;
  size_t i, j, unique_seq_last_idx, unique_seq_first_idx;
  const size_t expected_seq_length = f->num_servers;
  int *seen_elements;

  dump_array("actual_connection_sequence", actual_connection_sequence, num_iters);

  /* verify conn. seq. expectation */
  /* get the first unique run of length "num_servers". */
  expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length);
  seen_elements = gpr_malloc(sizeof(int) * expected_seq_length);

  unique_seq_last_idx = ~(size_t)0;

  memset(seen_elements, 0, sizeof(int) * expected_seq_length);
  for (i = 0; i < num_iters; i++) {
    if (actual_connection_sequence[i] < 0 ||
        seen_elements[actual_connection_sequence[i]] != 0) {
      /* if anything breaks the uniqueness of the run, back to square zero */
      memset(seen_elements, 0, sizeof(int) * expected_seq_length);
      continue;
    }
    seen_elements[actual_connection_sequence[i]] = 1;
    for (j = 0; j < expected_seq_length; j++) {
      if (seen_elements[j] == 0) break;
    }
    if (j == expected_seq_length) { /* seen all the elements */
      unique_seq_last_idx = i;
      break;
    }
  }
  /* make sure we found a valid run */
  dump_array("seen_elements", seen_elements, expected_seq_length);
  for (j = 0; j < expected_seq_length; j++) {
    GPR_ASSERT(seen_elements[j] != 0);
  }

  GPR_ASSERT(unique_seq_last_idx != ~(size_t)0);

  unique_seq_first_idx = (unique_seq_last_idx - expected_seq_length + 1);
  memcpy(expected_connection_sequence,
         actual_connection_sequence + unique_seq_first_idx,
         sizeof(int) * expected_seq_length);

  /* first iteration succeeds */
  GPR_ASSERT(actual_connection_sequence[0] != -1);
  /* then we fail for a while... */
  GPR_ASSERT(actual_connection_sequence[1] == -1);
  /* ... but should be up at "unique_seq_first_idx" */
  GPR_ASSERT(actual_connection_sequence[unique_seq_first_idx] != -1);

  for (j = 0, i = unique_seq_first_idx; i < num_iters; i++) {
    const int actual = actual_connection_sequence[i];
    const int expected =
        expected_connection_sequence[j++ % expected_seq_length];
    if (actual != expected) {
      gpr_log(GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected,
              actual, i);
      print_failed_expectations(expected_connection_sequence,
                                actual_connection_sequence, expected_seq_length,
                                num_iters);
      abort();
    }
  }

  /* things are fine once the servers are brought back up */
  assert_channel_connectivity(client, 1, GRPC_CHANNEL_READY);
  gpr_free(expected_connection_sequence);
  gpr_free(seen_elements);
}
Пример #22
0
int merge_compare(struct sorthash_t *obarray, int hashcount)
/* report our results (header portion) */
{
    struct match_t *match, *copy;
    int matchcount;

    hashcount = compact_matches(obarray, hashcount);
    obarray = (struct sorthash_t *)realloc(obarray, 
				   sizeof(struct sorthash_t)*hashcount);
    matchcount = hashcount;
    hitlist = reduce_matches(obarray, &matchcount);
    if (debug)
	dump_array("After removing uniques.\n", obarray, hashcount);
    report_time("%d range groups after removing unique hashes", matchcount);

    mergecount = collapse_ranges(hitlist, matchcount);
    /*
     * Here's where we do significance filtering.  As a side effect,
     * compact the match list in order to cut the n log n qsort time
     */
    for (copy = match = hitlist; match < hitlist + matchcount; match++)
	if (match->nmatches > 0 && copy < match)
	{
	    int	i, flags = 0, maxsize = 0;

	    for (i=0; i < match->nmatches; i++)
	    {
		struct sorthash_t	*rp = match->matches+i;
		int matchsize = rp->hash.end - rp->hash.start + 1;

		if (matchsize >= maxsize)
		    maxsize = matchsize;

		/*
		 * This odd-looking bit of logic, deals with an
		 * annoying edge case.  Sometimes we'll get boilerplate C
		 * stuff in both a C and a text file. To cope, propagate
		 * insignificance -- if we know from one context that a
		 * particular span of text is not interesting, declare it
		 * uninteresting everywhere.
		 */
		flags |= rp->hash.flags;
	    }

	    /*
	     * Filter for sigificance right at the last minute.  The
	     * point of doing it this way is to allow significance bits to 
	     * propagate through range merges.
	     */
	    if (maxsize >= minsize && (nofilter || !(flags & INSIGNIFICANT)))
		*copy++ = *match;
	}

    mergecount = (copy - hitlist);

    /* sort everything so the report looks neat */
    qsort(hitlist, mergecount, sizeof(struct match_t), sortmatch);

    if (debug)
	dump_array("After merging ranges.\n", obarray, hashcount);
    report_time("%d range groups after merging", mergecount);

    return(mergecount);
 }
Пример #23
0
struct match_t *reduce_matches(struct sorthash_t *obarray, int *hashcountp)
/* assemble list of duplicated hashes */
{
     unsigned int nonuniques, nreduced, progress, hashcount = *hashcountp;
     struct sorthash_t *mp, *np;
     struct match_t	*reduced;

     if (debug)
	 dump_array("Chunk list before reduction.\n",obarray, hashcount);

     if (debug)
	 dump_array("Chunk list after reduction.\n",obarray, hashcount);

     /* build list of hashes with more than one range associated */
     nonuniques = progress = 0;
     if (verbose)
	 fprintf(stderr, "%% Extracting duplicates...   ");
     nreduced = 10000;
     reduced = (struct match_t *)malloc(sizeof(struct match_t) * nreduced);
     for (np = obarray; np < obarray + hashcount; np = mp)
     {
	 int i, heterogenous, nmatches;

	 if (verbose && !debug && progress++ % 10000 == 0)
	     fprintf(stderr, "\b\b\b%02.0f%%", progress / (hashcount * 0.01));

	 /* count the number of hash matches */
	 nmatches = 1;
	 for (mp = np+1; mp < obarray + hashcount; mp++)
	     if (SORTHASHCMP(np, mp))
		 break;
	     else
		 nmatches++;

	 /* if all these matches are within the same tree, toss them */
	 heterogenous = 0;
	 for (i = 0; i < nmatches; i++)
	     if (!sametree(np[i].file->name, np[(i+1) % nmatches].file->name))
		 heterogenous++;
	 if (!heterogenous)
	 {
	     np[i].hash.flags = INTERNAL_FLAG;	/* used only in debug code */
	     continue;
	 }

	 if (debug)
	 {
	     printf("*** %ld has %d in its clique\n", np-obarray, nmatches);
	     for (i = 0; i < nmatches; i++)
		 printf("%ld: %s:%d:%d\n", 
			np-obarray+i, np[i].file->name, np[i].hash.start, np[i].hash.end);
	 }

	 /* passed all tests, keep this set of ranges */
	 if (nonuniques >= nreduced)
	 {
	     nreduced *= 2;
	     reduced = (struct match_t *)realloc(reduced,
						 sizeof(struct match_t)*nreduced);
	 }
	 /*
	  * Point into the existing hash array rather than allocating
	  * new storage.  This means our working set won't get any
	  * smaller, but it avoids the time overhead of doing a bunch
	  * of malloc and free calls.
	  */
	 reduced[nonuniques].matches = np;
	 reduced[nonuniques].nmatches = nmatches;
	 nonuniques++;
     }
     if (verbose)
	 fprintf(stderr, "\b\b\b100%% done.\n");

     *hashcountp = nonuniques;
     return reduced;
}
Пример #24
0
GLboolean r300_run_vb_render(GLcontext *ctx,
				 struct tnl_pipeline_stage *stage)
{
	r300ContextPtr rmesa = R300_CONTEXT(ctx);
	struct radeon_vertex_buffer *VB = &rmesa->state.VB;
	int i;
	LOCAL_VARS
   
	if (RADEON_DEBUG & DEBUG_PRIMS)
		fprintf(stderr, "%s\n", __FUNCTION__);

	if (stage) {
 		TNLcontext *tnl = TNL_CONTEXT(ctx);
		radeon_vb_to_rvb(rmesa, VB, &tnl->vb);
	}
	
	r300UpdateShaders(rmesa);
	if (rmesa->state.VB.LockCount == 0 || 1) {
 	  	r300ReleaseArrays(ctx);
		r300EmitArrays(ctx, GL_FALSE);

		r300UpdateShaderStates(rmesa);
	} else {
		/* TODO: Figure out why do we need these. */
		R300_STATECHANGE(rmesa, vir[0]);
		R300_STATECHANGE(rmesa, vir[1]);
		R300_STATECHANGE(rmesa, vic);
		R300_STATECHANGE(rmesa, vof);
		
#if 0		
		fprintf(stderr, "dt:\n");
		for(i=0; i < VERT_ATTRIB_MAX; i++){
			fprintf(stderr, "dt %d:", i);
			dump_dt(&rmesa->state.VB.AttribPtr[i], VB->Count);
		}
		
		fprintf(stderr, "before:\n");
		for(i=0; i < rmesa->state.aos_count; i++){
			fprintf(stderr, "aos %d:", i);
			dump_array(&rmesa->state.aos[i], VB->Count);
		}
#endif
#if 0
 	  	r300ReleaseArrays(ctx);
		r300EmitArrays(ctx, GL_FALSE);
			
		fprintf(stderr, "after:\n");
		for(i=0; i < rmesa->state.aos_count; i++){
			fprintf(stderr, "aos %d:", i);
			dump_array(&rmesa->state.aos[i], VB->Count);
		}
#endif
	}
	
	reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
	e32(0x0000000a);

	reg_start(0x4f18,0);
	e32(0x00000003);
#if 0
	reg_start(R300_VAP_PVS_WAITIDLE,0);
		e32(0x00000000);
#endif
	r300EmitState(rmesa);
	
	for(i=0; i < VB->PrimitiveCount; i++){
		GLuint prim = VB->Primitive[i].mode;
		GLuint start = VB->Primitive[i].start;
		GLuint length = VB->Primitive[i].count;
		
		r300_render_vb_primitive(rmesa, ctx, start, start + length, prim);
	}

	reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
	e32(0x0000000a/*0x2*/);

	reg_start(0x4f18,0);
	e32(0x00000003/*0x1*/);

#ifdef USER_BUFFERS
	r300UseArrays(ctx);
#endif
	return GL_FALSE;
}
Пример #25
0
int
main(int argc, char **argv)
{
	struct _vte_trie *trie;
	GValueArray *array = NULL;
	GQuark quark;
	gunichar buf[LINE_MAX];
	const gunichar *consumed;
	gsize buflen;

	_vte_debug_init();

	g_type_init();
	trie = _vte_trie_new();

	_vte_trie_add(trie, "abcdef", 6, "abcdef",
		      g_quark_from_static_string("abcdef"));
	_vte_trie_add(trie, "abcde", 5, "abcde",
		      g_quark_from_static_string("abcde"));
	_vte_trie_add(trie, "abcdeg", 6, "abcdeg",
		      g_quark_from_static_string("abcdeg"));
	_vte_trie_add(trie, "abc%+Aeg", 8, "abc%+Aeg",
		      g_quark_from_static_string("abc%+Aeg"));
	_vte_trie_add(trie, "abc%deg", 7, "abc%deg",
		      g_quark_from_static_string("abc%deg"));
	_vte_trie_add(trie, "abc%%eg", 7, "abc%%eg",
		      g_quark_from_static_string("abc%%eg"));
	_vte_trie_add(trie, "abc%%%i%deg", 11, "abc%%%i%deg",
		      g_quark_from_static_string("abc%%%i%deg"));
	_vte_trie_add(trie, "<esc>[%i%d;%dH", 14, "vtmatch",
		      g_quark_from_static_string("vtmatch"));
	_vte_trie_add(trie, "<esc>[%i%mL", 11, "multimatch",
		      g_quark_from_static_string("multimatch"));
	_vte_trie_add(trie, "<esc>[%mL<esc>[%mL", 18, "greedy",
		      g_quark_from_static_string("greedy"));
	_vte_trie_add(trie, "<esc>]2;%sh", 11, "decset-title",
		      g_quark_from_static_string("decset-title"));

	printf("Wide encoding is `%s'.\n", VTE_CONV_GUNICHAR_TYPE);

	_vte_trie_print(trie);
	printf("\n");

	quark = 0;
	convert_mbstowcs("abc", 3, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "abc",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("abcdef", 6, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "abcdef",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("abcde", 5, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "abcde",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("abcdeg", 6, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "abcdeg",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("abc%deg", 7, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "abc%deg",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("abc10eg", 7, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "abc10eg",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("abc%eg", 6, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "abc%eg",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("abc%10eg", 8, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "abc%10eg",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("abcBeg", 6, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "abcBeg",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("<esc>[25;26H", 12, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "<esc>[25;26H",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("<esc>[25;2", 10, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "<esc>[25;2",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
	}

	quark = 0;
	convert_mbstowcs("<esc>[25L", 9, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "<esc>[25L",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
	}

	quark = 0;
	convert_mbstowcs("<esc>[25L<esc>[24L", 18, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "<esc>[25L<esc>[24L",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
	}

	quark = 0;
	convert_mbstowcs("<esc>[25;26L", 12, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "<esc>[25;26L",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
	}

	quark = 0;
	convert_mbstowcs("<esc>]2;WoofWoofh", 17, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "<esc>]2;WoofWoofh",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("<esc>]2;WoofWoofh<esc>]2;WoofWoofh", 34,
			 buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "<esc>]2;WoofWoofh<esc>]2;WoofWoofh",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	quark = 0;
	convert_mbstowcs("<esc>]2;WoofWoofhfoo", 20, buf, &buflen, sizeof(buf));
	printf("`%s' = `%s'\n", "<esc>]2;WoofWoofhfoo",
	       _vte_trie_match(trie, buf, buflen,
			       NULL, &consumed, &quark, &array));
	printf("=> `%s' (%d)\n", g_quark_to_string(quark), (int)(consumed - buf));
	if (array != NULL) {
		dump_array(array);
		_vte_matcher_free_params_array(NULL, array);
		array = NULL;
	}

	_vte_trie_free(trie);

	return 0;
}
Пример #26
0
/* Check if the given pattern matches part of the given trie, returning an
 * empty string on a partial initial match, a %NULL if there's no match in the
 * works, and the result string if we have an exact match. */
static const char *
_vte_trie_matchx(struct _vte_trie *trie, const gunichar *pattern, gsize length,
		 gboolean greedy,
		 const char **res, const gunichar **consumed,
		 GQuark *quark, GValueArray *array)
{
	unsigned int i;
	const char *hres;
	enum cclass cc;
	const char *best = NULL;
	GValueArray *bestarray = NULL;
	GQuark bestquark = 0;
	const gunichar *bestconsumed = pattern;

	/* Make sure that attempting to save output values doesn't kill us. */
	if (res == NULL) {
		res = &hres;
	}

	/* Trivial cases.  We've matched an entire pattern, or we're out of
	 * pattern to match. */
	if (trie->result != NULL) {
		*res = trie->result;
		*quark = trie->quark;
		*consumed = pattern;
		return *res;
	}
	if (length <= 0) {
		if (trie->trie_path_count > 0) {
			*res = "";
			*quark = g_quark_from_static_string("");
			*consumed = pattern;
			return *res;
		} else {
			*res = NULL;
			*quark = 0;
			*consumed = pattern;
			return *res;
		}
	}

	/* Now figure out which (if any) subtrees to search.  First, see
	 * which character class this character matches. */
	for (cc = exact; cc < invalid; cc++)
	for (i = 0; i < trie->trie_path_count; i++) {
		struct _vte_trie *subtrie = trie->trie_paths[i].trie;
		struct char_class *cclass = trie->trie_paths[i].cclass;
		struct char_class_data *data = &trie->trie_paths[i].data;
		if (trie->trie_paths[i].cclass->type == cc) {
			/* If it matches this character class... */
			if (cclass->check(pattern[0], data)) {
				const gunichar *prospect = pattern + 1;
				const char *tmp;
				GQuark tmpquark = 0;
				GValueArray *tmparray;
				gboolean better = FALSE;
				/* Move past characters which might match this
				 * part of the string... */
				while (cclass->multiple &&
				       ((gsize)(prospect - pattern) < length) &&
				       cclass->check(prospect[0], data)) {
					prospect++;
				}
				/* ... see if there's a parameter here, ... */
				tmparray = g_value_array_new(0);
				cclass->extract(pattern,
						prospect - pattern,
						data,
						tmparray);
				/* ... and check if the subtree matches the
				 * rest of the input string.  Any parameters
				 * further on will be appended to the array. */
				_vte_trie_matchx(subtrie,
						 prospect,
						 length - (prospect - pattern),
						 greedy,
						 &tmp,
						 consumed,
						 &tmpquark,
						 tmparray);
				/* If we haven't seen any matches yet, go ahead
				 * and go by this result. */
				if (best == NULL) {
					better = TRUE;
				} else
				/* If we have a match, and we didn't have one
				 * already, go by this result. */
				if ((best != NULL) &&
				    (best[0] == '\0') &&
				    (tmp != NULL) &&
				    (tmp[0] != '\0')) {
					better = TRUE;
				} else
				/* If we already have a match, and this one's
				 * better (longer if we're greedy, shorter if
				 * we're not), then go by this result. */
				if ((tmp != NULL) &&
				    (tmp[0] != '\0') &&
				    (bestconsumed != NULL) &&
				    (consumed != NULL) &&
				    (*consumed != NULL)) {
					if (greedy &&
					    (bestconsumed < *consumed)) {
						better = TRUE;
					} else
					if (!greedy &&
					    (bestconsumed > *consumed)) {
						better = TRUE;
					}
				}
				if (better) {
					best = tmp;
					if (bestarray != NULL) {
						_vte_matcher_free_params_array(
								NULL, bestarray);
					}
					bestarray = tmparray;
					bestquark = tmpquark;
					bestconsumed = *consumed;
				} else {
					_vte_matcher_free_params_array(
							NULL, tmparray);
					tmparray = NULL;
				}
			}
		}
	}

	/* We're done searching.  Copy out any parameters we picked up. */
	if (bestarray != NULL) {
		for (i = 0; i < bestarray->n_values; i++) {
			GValue *value = g_value_array_get_nth(bestarray, i);
			g_value_array_append(array, value);

			if (G_VALUE_HOLDS_POINTER(value)) {
				g_value_set_pointer(value, NULL);
			}
		}
		_vte_matcher_free_params_array(NULL, bestarray);
	}
#if 0
	printf("`%s' ", best);
	dump_array(array);
#endif
	*quark = bestquark;
	*res = best;
	*consumed = bestconsumed;
	return *res;
}
	std::wostream& operator <<(std::wostream& os, in_mark<pp_as_t<pp::array_any, array_info_t<T,U> > > const & vv ){
		dump_array(os,  vv.m_v.m_val.m_value, vv.m_v.m_val.m_in_count);
		return os;
	}
Пример #28
0
std::ostream& operator <<(std::ostream& os, const ModelData& data)
{
    os << "ModelData:"                 << endl;
    os << "time: "                     << data.time << endl;                             // 2
    os << "numIndependentSpecies: "    << data.numIndependentSpecies << endl;            // 3
    os << "numDependentSpecies: "      << data.numDependentSpecies << endl;              // 4
    os << "dependentSpeciesConservedSums:" << endl;                                      // 5
    dump_array(os, data.numDependentSpecies, data.dependentSpeciesConservedSums);
    os << "numGlobalParameters: "      << data.numGlobalParameters << endl;              // 6
    os << "globalParameters: "         << endl;                                          // 7
    dump_array(os, data.numGlobalParameters, data.globalParameters);
    os << "numReactions: "             << data.numReactions << endl;                     // 8
    os << "reactionRates: "            << endl;                                          // 9
    dump_array(os, data.numReactions, data.reactionRates);
    os << "numRateRules: "             << data.numRateRules << endl;                     // 10
    os << "rateRuleValues: "           << endl;                                          // 11
    dump_array(os, data.numRateRules, data.rateRuleValues);
    os << "rateRuleRates: "            << endl;                                          // 11
    dump_array(os, data.numRateRules, data.rateRuleRates);

//    unsigned*                                localParametersOffsets;           // 12
//
//
//    unsigned*                                localParametersNum;               // 13
//
//
//    double*                             localParameters;                  // 14

    os << "numFloatingSpecies: "       << data.numFloatingSpecies << endl;       // 15

    os << "floatingSpeciesConcentrations: " << endl;                                     // 16
    dump_array(os, data.numFloatingSpecies, data.floatingSpeciesConcentrations);



    //double* floatingSpeciesInitConcentrations;    // 17


    os << "floatingSpeciesAmountRates: " << endl;       // 18
    dump_array(os, data.numFloatingSpecies, data.floatingSpeciesAmountRates);

    os << "floatingSpeciesAmounts: "    << endl;           // 19
    dump_array(os, data.numFloatingSpecies, data.floatingSpeciesAmounts);

//    unsigned*                                floatingSpeciesCompartments;      // 20
    os << "numBoundarySpecies: "       << data.numBoundarySpecies << endl;  // 21
    os << "boundarySpeciesConcentrations:" << endl;                         // 22
    dump_array(os, data.numBoundarySpecies, data.boundarySpeciesConcentrations);
    os << "boundarySpeciesAmounts:"    << endl;                             // 23
    dump_array(os, data.numBoundarySpecies, data.boundarySpeciesAmounts);
//    unsigned*                                boundarySpeciesCompartments;      // 24
    os << "numCompartments: "          << data.numCompartments << endl;     // 25
    os << "compartmentVolumes:"        << endl;                             // 26
    dump_array(os, data.numCompartments, data.compartmentVolumes);
    os << "stoichiometry:"             << endl;                             // 27
//    int                                 numEvents;                        // 28
//    int                                 eventTypeSize;                    // 29
//    bool*                               eventType;                        // 30
//    int                                 eventPersistentTypeSize;          // 31
//    bool*                               eventPersistentType;              // 32
//    int                                 eventTestsSize;                   // 33
//    double*                             eventTests;                       // 34
//    int                                 eventPrioritiesSize;              // 35
//    double*                             eventPriorities;                  // 36
//    int                                 eventStatusArraySize;             // 37
//    bool*                               eventStatusArray;                 // 38
//    int                                 previousEventStatusArraySize;     // 39
//    bool*                               previousEventStatusArray;         // 40
//    int                                 workSize;                         // 41
//    double*                             work;                             // 42
//    EventDelayHandler*                eventDelays;                      // 43
//    EventAssignmentHandler*           eventAssignments;                 // 44
//    ComputeEventAssignmentHandler*    computeEventAssignments;          // 45
//    PerformEventAssignmentHandler*    performEventAssignments;          // 46
//    char*                               modelName;                        // 47
//    char**                              variableTable;                    // 48
//    char**                              boundaryTable;                    // 49
//    char**                              globalParameterTable;             // 50
//    int                                 srSize;                           // 51
//    double*                             sr;                               // 52





    return os;
}
Пример #29
0
int
main (void)
{
  int i;
  int me, npes;
  long *pSync;
  double *A;

  /*
   * Kick the OpenSHMEM program off.  Discover program layout, and
   * prep. the sync work array for barrier
   */
  start_pes (0);
  me = shmem_my_pe ();
  npes = shmem_n_pes ();

  pSync = shmalloc (sizeof (*pSync) * _SHMEM_BARRIER_SYNC_SIZE);
  for (i = 0; i < _SHMEM_BARRIER_SYNC_SIZE; i += 1)
    {
      pSync[i] = _SHMEM_SYNC_VALUE;
    }
  shmem_barrier_all ();

  /*
   * Allocate array everywhere and initialize
   */
  A = shmalloc (sizeof (*A) * X * Y);
  init_array (A, X, Y, 0.0);

  /*
   * Use PEs 0 and 1 as sender and receiver
   */
  if (me == 0)
    {
      double *target = & A[OFFSET (0, 0, Y)];
      shmem_double_p (target, 3.142, 1);
    }

  /*
   * Pair-wise sync sender & receiver.  Other PEs do not enter
   * barrier
   */
  if ( (me == 0) || (me == 1) )
    {
      shmem_barrier (0, 0, 2, pSync);
    }
  else
    {
      printf ("PE %d / %d not in barrier\n", me, npes);
    }

  /*
   * Receiver shows us updated array
   */
  if (me == 1)
    {
      dump_array (stdout, A, X, Y);
    }

  return 0;
}
int main(int argc,char *argv[]){
  
	int i,result;
  clock_t time_start,time_end;
  srand((unsigned)time(NULL));
  
  int array_length=10;//!< 数列の長さ
  enum SORT_TYPE sort_type = BOUBLE;//!< ソートの種類
  enum INPUT_TYPE input_type = RAND;//!< 数列の入力方法
  
  /* ループしてgetoptを使用しオプションを一つずつ取得して行く
   (「:」がついてるのは引数あり)
   */
  while((result=getopt(argc,argv,"bqmchn:i"))!=-1){
    switch(result){//指定されたオプションで切り替え
        //ソート手法
      case 'b'://バブルソート
        sort_type=BOUBLE;
        printf("use Bouble sort\n");
        break;
      case 'q'://クイックソート
        sort_type=QUICK;
        printf("use Quick sort\n");
        break;
      case 'm'://マージソート
        sort_type=MARGE;
        printf("use Marge sort\n");
        break;
      case 'c'://コームソート
        sort_type=COMB;
        printf("use Comb sort\n");
        break;
        
        //その他のオプション
      case 'n'://数列の長さ(値を取る引数の場合は外部変数optargにその値を格納されてる。)
        array_length=atoi(optarg);
        printf("sorting %d numbers\n",array_length);
        break;
      case 'i'://数字を自分で指定する
        input_type=STDINPUT;
        printf("setting numbers by myself\n");
        break;
      case 'h'://ヘルプを表示
        help(argv[0]);
        exit(0);
        break;
    }
  }
  
  int numbers[array_length];
  
  if(input_type==STDINPUT){//自分で決めるとき
    for(i=0;i<array_length;i++){
      printf("numbers[%d]->",i);
      scanf("%d",&numbers[i]);
    }
  }else{//ランダムに決めるとき
    for(i=0;i<array_length;i++){
      numbers[i]=rand()%10;//乱数
    }
  }
  
  printf("first array (%d numbers) ======\n",array_length);
  dump_array(numbers,array_length);
  printf("======\n");
  time_start = clock();//実行時間測定開始
  
  switch(sort_type){
    case BOUBLE:
      bouble_sort(numbers,array_length);
      break;
    case QUICK:
      quick_sort(numbers,array_length);
      break;
  }
  
  time_end = clock();//実行時間測定終了
  printf("result ======\n");
  dump_array(numbers,array_length);
  
  printf("time = %lf[sec]\n", (double)(time_end-time_start)/CLOCKS_PER_SEC);
  printf("======\n");
  
  return 0;
}