Beispiel #1
0
int main(void)
{
	open_files();
	init_buffer();

#ifdef USE_EVENTFD
	/* TODO 2 - init eventfd */
	efd = eventfd(0, 0);
	DIE(efd < 0, "eventfd");
#endif

	do_io_async();

#ifdef USE_EVENTFD
	close(efd);
#endif
	close_files();

	return 0;
}
Beispiel #2
0
/**
 * lib_memset() - unit test for memset()
 *
 * Test memset() with varied alignment and length of the changed buffer.
 *
 * @uts:	unit test state
 * Return:	0 = success, 1 = failure
 */
static int lib_memset(struct unit_test_state *uts)
{
	u8 buf[BUFLEN];
	int offset, len;
	void *ptr;

	for (offset = 0; offset <= SWEEP; ++offset) {
		for (len = 1; len < BUFLEN - SWEEP; ++len) {
			init_buffer(buf, 0);
			ptr = memset(buf + offset, MASK, len);
			ut_asserteq_ptr(buf + offset, (u8 *)ptr);
			if (test_memset(uts, buf, MASK, offset, len)) {
				debug("%s: failure %d, %d\n",
				      __func__, offset, len);
				return CMD_RET_FAILURE;
			}
		}
	}
	return 0;
}
Beispiel #3
0
/* Prime, estimate, and time the collective called by the specified function
   for the given message size, iteration count, and time limit.  Then, print
   out the results.
*/
double get_time(double (*fn)(struct collParams* p), char* title, struct collParams* p, int iter, int time_limit)
{
    double time;
    double time_avg;
    int iter_limit;

    /* initialize buffers with known value */
    if (check_buffers) {
        init_buffer(sbuffer, p->myrank);
        memset(rbuffer, 0, buffer_size);
        check_sbuffer(p->myrank);
    }

    /* prime the collective with an intial call */
    p->iter = 1;
    time = fn(p);

    /* run through a small number of iterations to get a rough estimate of time */
    p->iter = ITRS_EST;
    time = fn(p);

    /* if a time limit has been specified, use the esitmate to limit the maximum number of iterations */
    iter_limit = (time_limit > 0   ) ? (int) (time_limit / time) : iter;
    iter_limit = (iter_limit < iter) ? iter_limit : iter;

    /* use the number calculated by the root (rank 0) which should be the slowest */
    MPI_Bcast(&iter_limit, 1, MPI_INT, 0, MPI_COMM_WORLD);

    /* run the tests (unless the limited iteration count is smaller than that used in the estimate) */
    if(iter_limit > ITRS_EST) {
        p->iter = iter_limit;
        time = fn(p);
    } else {
        iter_limit = ITRS_EST;
    }

    /* Collect and print the timing results recorded by each process */
    Print_Timings(time, title, p->size, iter_limit, p->comm);

    return time;
}
Beispiel #4
0
char *
macro_expand_next (char **lexptr,
                   macro_lookup_ftype *lookup_func,
                   void *lookup_baton)
{
  struct macro_buffer src, dest, tok;
  struct cleanup *back_to;

  /* Set up SRC to refer to the input text, pointed to by *lexptr.  */
  init_shared_buffer (&src, *lexptr, strlen (*lexptr));

  /* Set up DEST to receive the expansion, if there is one.  */
  init_buffer (&dest, 0);
  dest.last_token = 0;
  back_to = make_cleanup (cleanup_macro_buffer, &dest);

  /* Get the text's first preprocessing token.  */
  if (! get_token (&tok, &src))
    {
      do_cleanups (back_to);
      return 0;
    }

  /* If it's a macro invocation, expand it.  */
  if (maybe_expand (&dest, &tok, &src, 0, lookup_func, lookup_baton))
    {
      /* It was a macro invocation!  Package up the expansion as a
         null-terminated string and return it.  Set *lexptr to the
         start of the next token in the input.  */
      appendc (&dest, '\0');
      discard_cleanups (back_to);
      *lexptr = src.text;
      return dest.text;
    }
  else
    {
      /* It wasn't a macro invocation.  */
      do_cleanups (back_to);
      return 0;
    }
}
Beispiel #5
0
char *
macro_expand (const char *source,
              macro_lookup_ftype *lookup_func,
              void *lookup_func_baton)
{
  struct macro_buffer src, dest;
  struct cleanup *back_to;

  init_shared_buffer (&src, (char *) source, strlen (source));

  init_buffer (&dest, 0);
  dest.last_token = 0;
  back_to = make_cleanup (cleanup_macro_buffer, &dest);

  scan (&dest, &src, 0, lookup_func, lookup_func_baton);

  appendc (&dest, '\0');

  discard_cleanups (back_to);
  return dest.text;
}
Beispiel #6
0
int glkunix_startup_code(glkunix_startup_t *data)
{
    myargc = data->argc;
    myargv = data->argv;

    os_init_setup ();
    os_process_arguments (myargc, myargv);

    init_buffer ();
    init_err ();
    init_memory ();
    init_proc ();
    init_sound ();
    init_text ();

    os_init_screen ();

    init_undo ();
    z_restart ();
    return TRUE;
}
Beispiel #7
0
int	get_weather(char *code)
{
  char	*url;
  int	fd;
  int	result;

  result = 4242;
  dl_file(code);
  fd = open("/tmp/mein_weather.txt", O_RDONLY);
  while ((url = mein_getnextline(fd)) != NULL &&
	 fd != -1 && result == 4242)
    {
      if (match("Temperature:*", url))
	result = extract_weather(url);
      xfree(url);
    }
  xfree (url);
  xclose(fd);
  init_buffer();
  return (result);
}
Beispiel #8
0
void dispose_session(struct session *ses)
{
	int index;

	push_call("dispose_session(%p)", ses);

	UNLINK(ses, gtd->dispose_next, gtd->dispose_prev);

	for (index = 0 ; index < LIST_MAX ; index++)
	{
		free_list(ses->list[index]);
	}

	if (ses->map)
	{
		delete_map(ses);
	}

	if (ses->mccp)
	{
		inflateEnd(ses->mccp);
		free(ses->mccp);
	}

	init_buffer(ses, 0);

	free(ses->name);
	free(ses->host);
	free(ses->ip);
	free(ses->port);
	free(ses->group);
	free(ses->read_buf);
	free(ses->cmd_color);

	free(ses);

	pop_call();
	return;
}
Beispiel #9
0
Datum  spherepoint_in(PG_FUNCTION_ARGS)
{
    SPoint  * sp  = ( SPoint * ) MALLOC ( sizeof ( SPoint ) ) ;
    char    *  c  = PG_GETARG_CSTRING(0);
    double lng, lat;

    void sphere_yyparse( void );
    init_buffer ( c );
    sphere_yyparse();
    if ( get_point( &lng, &lat ) ) {
        sp->lng       = lng;
        sp->lat       = lat;
        spoint_check ( sp );
    } else {
        reset_buffer();
        FREE( sp );
        sp = NULL;
        elog ( ERROR , "spherepoint_in: parse error" );
    }
    reset_buffer();
    PG_RETURN_POINTER( sp );
}
Beispiel #10
0
int main()
{
  /* Initialize buffer to store ints */
  buffer *buff = init_buffer();

  seed_random_number_generator();

  /* Create/start threads */
  pthread_t producer, consumer;

  pthread_create(&producer, NULL, producer_function, buff);
  pthread_create(&consumer, NULL, consumer_function, buff);

  /* Join threads */
  pthread_join(producer, NULL);
  pthread_join(consumer, NULL);

  /* Free buffer/memory */
  destroy_buffer(buff);

  return 0;
}
/* Creates a new bacteria and fills the aminoacids arrays */
Bacteria::Bacteria(char *filename) {
    FILE * bacteria_file = fopen(filename,"r");
    InitVectors();
    
    /* This part is the same */
    char ch;
    while ((ch = fgetc(bacteria_file)) != EOF)
    {
        if (ch == '>')
        {
            while (fgetc(bacteria_file) != '\n'); // skip rest of line
            
            char buffer[LEN-1];
            fread(buffer, sizeof(char), LEN-1, bacteria_file);
            init_buffer(buffer);
        }
        else if (ch != '\n' && ch != '\r')
            cont_buffer(ch);
    }
    
    fclose (bacteria_file);
}
Beispiel #12
0
/* Read in a filename for a `r', `w', or `s///w' command. */
static struct buffer *
read_filename(void)
{
  struct buffer *b;
  int ch;

  b = init_buffer();
  ch = in_nonblank();
  while (ch != EOF && ch != '\n')
    {
#if 0 /*XXX ZZZ 1998-09-12 kpp: added, then had second thoughts*/
      if (posixicity == POSIXLY_EXTENDED)
        if (ch == ';' || ch == '#')
          {
            savchar(ch);
            break;
          }
#endif
      ch = add_then_next(b, ch);
    }
  add1_buffer(b, '\0');
  return b;
}
Beispiel #13
0
void init(void){

	DIR_DATA = STD_DIR_DATA;
	DIR_REGA = STD_DIR_REGA;
	DIR_REGB = STD_DIR_REGB;
	DIR_MC2  = STD_DIR_MC2;
	
	PORT_DATA = STD_PORT_DATA;
	PORT_REGA = STD_PORT_REGA;
	PORT_REGB = STD_PORT_REGB;
	PORT_MC2  = STD_PORT_MC2;
	
	init_mux();
	init_switch();
	init_buffer();
	init_processing();
	
	for(char i = 0; i<10; i++){
		for(char j = 0; j<13; j++){
			CUBE[i][j]=0x01;
		}
	}
   
    //Timer A:
    TCCR1A = 0x00;
    TCCR1B = (1<<WGM12)|(1<CS12);
	
    OCR1AH = TM1ZAEHLER>>8;
    OCR1AL = TM1ZAEHLER & 0x00FF;
	
	TIMSK = (1<<OCIE1A);
   
    sei();

	PORT_REGB |= (1<<PIN_ENABLE_CUBE); // CUBE EINSCHALTEN
	
}
Beispiel #14
0
int main(int, char **)
{
    Halide::Buffer<uint8_t> bufA(NN, NN);
    Halide::Buffer<uint8_t> output_buf(NN, NN);
    Halide::Buffer<uint8_t> reference_buf(NN, NN);
    init_buffer(output_buf, (uint8_t) 177);
    // Dummy data
    for (int i = 0; i < NN; i++) {
        for (int j = 0; j < NN; j++) {
            bufA(j, i) = i * 10 + j;
        }
    }
    for (int i = 0; i < NN; i++) {
        for (int j = 0; j < NN; j++) {
            // Same access pattern as in generator
            reference_buf((i + j * (NN - 1)) % NN, (i + j * 2) % NN) = bufA((j + 3) % NN, i);
        }
    }

    func(bufA.raw_buffer(), output_buf.raw_buffer());
    compare_buffers("test", output_buf, reference_buf);

    return 0;
}
Beispiel #15
0
int cdecl frotz_main (void)
{

    os_init_setup ();

    init_buffer ();

    init_err ();

    init_memory ();

    init_process ();

    init_sound ();

    os_init_screen ();

    init_undo ();

    z_restart ();

    interpret ();

    script_close ();

    record_close ();

    replay_close ();

    reset_memory ();

    os_reset_screen ();

    return 0;

}/* main */
Beispiel #16
0
void Triangle::Init()
{
	init_buffer();
	init_vertexArray();
	init_shader();
}
Beispiel #17
0
void do_bench(int nthreads, int size, int elsize, int rshift, FILE * ofile) {
  void *src, *srccpy;
  void **dest[NCHUNKS], *dest2;
  int nbytes = 0, cbytes = 0;
  int i, j;
  struct timeval last, current;
  float tmemcpy, tshuf, tunshuf;
  int clevel, doshuffle=1;
  unsigned char *orig, *round;

  blosc_set_nthreads(nthreads);

  /* Initialize buffers */
  src = malloc(size);
  srccpy = malloc(size);
  dest2 = malloc(size);
  /* zero src to initialize byte on it, and not only multiples of 4 */
  memset(src, 0, size);
  init_buffer(src, size, rshift);
  memcpy(srccpy, src, size);
  for (j = 0; j < nchunks; j++) {
    dest[j] = malloc(size+BLOSC_MAX_OVERHEAD);
  }

  /* Warm destination memory (memcpy() will go a bit faster later on) */
  for (j = 0; j < nchunks; j++) {
    memcpy(dest[j], src, size);
  }

  fprintf(ofile, "--> %d, %d, %d, %d\n", nthreads, size, elsize, rshift);
  fprintf(ofile, "********************** Run info ******************************\n");
  fprintf(ofile, "Blosc version: %s (%s)\n", BLOSC_VERSION_STRING, BLOSC_VERSION_DATE);
  fprintf(ofile, "Using synthetic data with %d significant bits (out of 32)\n", rshift);
  fprintf(ofile, "Dataset size: %d bytes\tType size: %d bytes\n", size, elsize);
  fprintf(ofile, "Working set: %.1f MB\t\t", (size*nchunks) / (float)MB);
  fprintf(ofile, "Number of threads: %d\n", nthreads);
  fprintf(ofile, "********************** Running benchmarks *********************\n");

  gettimeofday(&last, NULL);
  for (i = 0; i < niter; i++) {
    for (j = 0; j < nchunks; j++) {
      memcpy(dest[j], src, size);
    }
  }
  gettimeofday(&current, NULL);
  tmemcpy = get_usec_chunk(last, current);
  fprintf(ofile, "memcpy(write):\t\t %6.1f us, %.1f MB/s\n",
         tmemcpy, size/(tmemcpy*MB/1e6));

  gettimeofday(&last, NULL);
  for (i = 0; i < niter; i++) {
    for (j = 0; j < nchunks; j++) {
      memcpy(dest2, dest[j], size);
    }
  }
  gettimeofday(&current, NULL);
  tmemcpy = get_usec_chunk(last, current);
  fprintf(ofile, "memcpy(read):\t\t %6.1f us, %.1f MB/s\n",
         tmemcpy, size/(tmemcpy*MB/1e6));

  for (clevel=0; clevel<10; clevel++) {

    fprintf(ofile, "Compression level: %d\n", clevel);

    gettimeofday(&last, NULL);
    for (i = 0; i < niter; i++) {
      for (j = 0; j < nchunks; j++) {
        cbytes = blosc_compress(clevel, doshuffle, elsize, size, src,
                                dest[j], size+BLOSC_MAX_OVERHEAD);
      }
    }
    gettimeofday(&current, NULL);
    tshuf = get_usec_chunk(last, current);
    fprintf(ofile, "comp(write):\t %6.1f us, %.1f MB/s\t  ",
           tshuf, size/(tshuf*MB/1e6));
    fprintf(ofile, "Final bytes: %d  ", cbytes);
    if (cbytes > 0) {
      fprintf(ofile, "Ratio: %3.2f", size/(float)cbytes);
    }
    fprintf(ofile, "\n");

    /* Compressor was unable to compress.  Copy the buffer manually. */
    if (cbytes == 0) {
      for (j = 0; j < nchunks; j++) {
        memcpy(dest[j], src, size);
      }
    }

    gettimeofday(&last, NULL);
    for (i = 0; i < niter; i++) {
      for (j = 0; j < nchunks; j++) {
        if (cbytes == 0) {
          memcpy(dest2, dest[j], size);
          nbytes = size;
        }
        else {
          nbytes = blosc_decompress(dest[j], dest2, size);
        }
      }
    }
    gettimeofday(&current, NULL);
    tunshuf = get_usec_chunk(last, current);
    fprintf(ofile, "decomp(read):\t %6.1f us, %.1f MB/s\t  ",
           tunshuf, nbytes/(tunshuf*MB/1e6));
    if (nbytes < 0) {
      fprintf(ofile, "FAILED.  Error code: %d\n", nbytes);
    }
    /* fprintf(ofile, "Orig bytes: %d\tFinal bytes: %d\n", cbytes, nbytes); */

    /* Check if data has had a good roundtrip */
    orig = (unsigned char *)srccpy;
    round = (unsigned char *)dest2;
    for(i = 0; i<size; ++i){
      if (orig[i] != round[i]) {
        fprintf(ofile, "\nError: Original data and round-trip do not match in pos %d\n",
               (int)i);
        fprintf(ofile, "Orig--> %x, round-trip--> %x\n", orig[i], round[i]);
        break;
      }
    }

    if (i == size) fprintf(ofile, "OK\n");

  } /* End clevel loop */


  /* To compute the totalsize, we should take into account the 10
     compression levels */
  totalsize += (size * nchunks * niter * 10.);

  free(src); free(srccpy); free(dest2);
  for (i = 0; i < nchunks; i++) {
    free(dest[i]);
  }

}
Beispiel #18
0
// -----------------------------------------------------------------------------
int QALSH::knn(						// k-nn search
	float* query,						// query point
	int top_k,							// top-k value
	ResultItem* rslt,					// k-nn results
	char* output_folder)				// output folder
{
	// -------------------------------------------------------------------------
	//  Space allocation and initialization
	// -------------------------------------------------------------------------
									// init k-nn results
	for (int i = 0; i < top_k; i++) {
		rslt[i].id_   = -1;
		rslt[i].dist_ = MAXREAL;
	}
									// objects frequency
	int* frequency  = new int[n_pts_];
	for (int i = 0; i < n_pts_; i++) {
		frequency[i]  = 0;
	}
									// whether an object is checked
	bool* is_checked = new bool[n_pts_];
	for (int i = 0; i < n_pts_; i++) {
		is_checked[i] = false;
	}

	float* data = new float[dim_];	// one object data
	for (int i = 0; i < dim_; i++) {
		data[i] = 0.0f;
	}
	g_memory += ((SIZEBOOL + SIZEINT) * n_pts_ + SIZEFLOAT * dim_);

	bool* flag = new bool[m_];		// whether a hash table is finished
	for (int i = 0; i < m_; i++) {
		flag[i] = true;
	}

	float* q_val = new float[m_];	// hash value of query
	for (int i = 0; i < m_; i++) {
		q_val[i] = -1.0f;
	}
	g_memory += (SIZEFLOAT + SIZEBOOL) * m_;
									// left and right page buffer
	PageBuffer* lptr = new PageBuffer[m_];
	PageBuffer* rptr = new PageBuffer[m_];
	g_memory += (SIZECHAR * B_ * m_ * 2 + SIZEINT * m_ * 6);

	for (int i = 0; i < m_; i++) {
		lptr[i].leaf_node_ = NULL;
		lptr[i].index_pos_ = -1;
		lptr[i].leaf_pos_  = -1;
		lptr[i].size_      = -1;

		rptr[i].leaf_node_ = NULL;
		rptr[i].index_pos_ = -1;
		rptr[i].leaf_pos_  = -1;
		rptr[i].size_      = -1;
	}

	// -------------------------------------------------------------------------
	//  Compute hash value <q_dist> of query and init the page buffers 
	//  <lptr> and <rptr>.
	// -------------------------------------------------------------------------
	page_io_ = 0;					// num of page i/os
	dist_io_ = 0;					// num of dist cmpt
	init_buffer(lptr, rptr, q_val, query);

	// -------------------------------------------------------------------------
	//  Determine the basic <radius> and <bucket_width> 
	// -------------------------------------------------------------------------
	float radius = find_radius(lptr, rptr, q_val);
	float bucket_width = (w_ * radius / 2.0f);

	// -------------------------------------------------------------------------
	//  K-nn search
	// -------------------------------------------------------------------------
	bool again      = true;			// stop flag
	int  candidates = 99 + top_k;	// threshold of candidates
	int  flag_num   = 0;			// used for bucket bound
	int  scanned_id = 0;			// num of scanned id
	int checked=0;

	int id    = -1;					// current object id
	int count = -1;					// count size in one page
	int start = -1;					// start position
	int end   = -1;					// end position

	float left_dist = -1.0f;		// left dist with query
	float right_dist = -1.0f;		// right dist with query
	float knn_dist = MAXREAL;		// kth nn dist
									// result entry for update
	ResultItem* item = new ResultItem();
	g_memory += (long) sizeof(ResultItem);

	while (again) {
		// ---------------------------------------------------------------------
		//  Step 1: initialize the stop condition for current round
		// ---------------------------------------------------------------------
		flag_num = 0;
		for (int i = 0; i < m_; i++) {
			flag[i] = true;
		}

		// ---------------------------------------------------------------------
		//  Step 2: find frequent objects
		// ---------------------------------------------------------------------
		while (true) {
			for (int i = 0; i < m_; i++) {
				if (!flag[i]) continue;

				// -------------------------------------------------------------
				//  Step 2.1: compute <left_dist> and <right_dist>
				// -------------------------------------------------------------
				left_dist = -1.0f;
				if (lptr[i].size_ != -1) {
					left_dist = calc_proj_dist(&lptr[i], q_val[i]);
				}

				right_dist = -1.0f;
				if (rptr[i].size_ != -1) {
					right_dist = calc_proj_dist(&rptr[i], q_val[i]);
				}

				// -------------------------------------------------------------
				//  Step 2.2: determine the closer direction (left or right)
				//  and do collision counting to find frequent objects.
				//
				//  For the frequent object, we calc the L2 distance with
				//  query, and update the k-nn result.
				// -------------------------------------------------------------
				if (left_dist >= 0 && left_dist < bucket_width && 
					((right_dist >= 0 && left_dist <= right_dist) ||
					right_dist < 0)) {

					count = lptr[i].size_;
					end = lptr[i].leaf_pos_;
					start = end - count;
					for (int j = end; j > start; j--) {
						id = lptr[i].leaf_node_->get_entry_id(j);
						frequency[id]++;
						scanned_id++;

						if (frequency[id] > l_ && !is_checked[id]) {
							is_checked[id] = true;
							read_data(id, dim_, B_, data, output_folder);

							item->dist_ = calc_l2_dist(data, query, dim_);
							item->id_ = id;
							knn_dist = update_result(rslt, item, top_k);
							checked++;
							// -------------------------------------------------
							//  Terminating condition 2
							// -------------------------------------------------
							dist_io_++;
							if (dist_io_ >= candidates) {
								again = false;
								flag_num += m_;
								break;
							}
						}
					}
					update_left_buffer(&lptr[i], &rptr[i]);
				}
				else if (right_dist >= 0 && right_dist < bucket_width && 
					((left_dist >= 0 && left_dist > right_dist) || 
					left_dist < 0)) {

					count = rptr[i].size_;
					start = rptr[i].leaf_pos_;
					end = start + count;
					for (int j = start; j < end; j++) {
						id = rptr[i].leaf_node_->get_entry_id(j);
						frequency[id]++;
						scanned_id++;
						if (frequency[id] > l_ && !is_checked[id]) {
							is_checked[id] = true;
							read_data(id, dim_, B_, data, output_folder);

							item->dist_ = calc_l2_dist(data, query, dim_);
							item->id_ = id;
							knn_dist = update_result(rslt, item, top_k);
   							checked++;
							// -------------------------------------------------
							//  Terminating condition 2
							// -------------------------------------------------
							dist_io_++;
							if (dist_io_ >= candidates) {
								again = false;
								flag_num += m_;
								break;
							}
						}
					}
					update_right_buffer(&lptr[i], &rptr[i]);
				}
				else {
					flag[i] = false;
					flag_num++;
				}
				if (flag_num >= m_) break;
			}
			if (flag_num >= m_) break;
		}
		// ---------------------------------------------------------------------
		//  Terminating condition 1
		// ---------------------------------------------------------------------
		if (knn_dist < appr_ratio_ * radius && dist_io_ >= top_k) {
			again = false;
			break;
		}

		// ---------------------------------------------------------------------
		//  Step 3: auto-update <radius>
		// ---------------------------------------------------------------------
		radius = update_radius(lptr, rptr, q_val, radius);
		bucket_width = radius * w_ / 2.0f;
	}

	// -------------------------------------------------------------------------
	//  Release space
	// -------------------------------------------------------------------------
	if (data != NULL || frequency != NULL || is_checked != NULL) {
		delete[] data; data = NULL;
		delete[] frequency;  frequency  = NULL;
		delete[] is_checked; is_checked = NULL;
		g_memory -= ((SIZEBOOL + SIZEINT) * n_pts_ + SIZEFLOAT * dim_);
	}
	if (q_val != NULL || flag != NULL || item != NULL) {
		delete[] q_val; q_val = NULL;
		delete[] flag; flag = NULL;
		delete   item; item = NULL;
		g_memory -= (SIZEFLOAT + SIZEBOOL) * m_;
		g_memory -= (long) sizeof(ResultItem);
	}

	for (int i = 0; i < m_; i++) {
		// ---------------------------------------------------------------------
		//  CANNOT remove the condition
		//              <lptrs[i].leaf_node != rptrs[i].leaf_node>
		//  Because <lptrs[i].leaf_node> and <rptrs[i].leaf_node> may point 
		//  to the same address, then we would delete it twice and receive 
		//  the runtime error or segmentation fault.
		// ---------------------------------------------------------------------
		if (lptr[i].leaf_node_ && lptr[i].leaf_node_ != rptr[i].leaf_node_) {
			delete lptr[i].leaf_node_; lptr[i].leaf_node_ = NULL;
		}
		if (rptr[i].leaf_node_) {
			delete rptr[i].leaf_node_; rptr[i].leaf_node_ = NULL;
		}
	}
	delete[] lptr; lptr = NULL;
	delete[] rptr; rptr = NULL;
	g_memory -= (SIZECHAR * B_ * m_ * 2 + SIZEINT * m_ * 6);
	return (page_io_ + dist_io_);
}
Beispiel #19
0
double small_random_allocs(ibp_capset_t *caps, int n, int asize, double readfrac, int small_count, int min_size, int max_size)
{
    int i, io_size, offset, slot, err;
    opque_t *q;
    op_generic_t *op;
    double rnd, lmin, lmax;
    double nbytes;
    tbuffer_t *buf;

    q = new_opque();

    lmin = log(min_size);
    lmax = log(max_size);

    if (asize < max_size) {
        max_size = asize;
        log_printf(0, "small_random_allocs:  Adjusting max_size=%d\n", max_size);
    }

    char *rbuffer = (char *)malloc(max_size);
    char *wbuffer = (char *)malloc(max_size);
    init_buffer(rbuffer, '1', max_size);
    init_buffer(wbuffer, '2', max_size);

    type_malloc_clear(buf, tbuffer_t, small_count);

    nbytes = 0;
    for (i=0; i<small_count; i++) {
        rnd = rand()/(RAND_MAX+1.0);
        slot = n * rnd;

        rnd = rand()/(RAND_MAX+1.0);
        rnd = lmin + (lmax - lmin) * rnd;
        io_size = exp(rnd);
        if (io_size == 0) io_size = 1;
        nbytes = nbytes + io_size;

        rnd = rand()/(RAND_MAX+1.0);
        offset = (asize - io_size) * rnd;

//     log_printf(15, "small_random_allocs: slot=%d offset=%d size=%d\n", slot, offset, io_size);

        rnd = rand()/(RAND_MAX+1.0);
        if (rnd < readfrac) {
            tbuffer_single(&(buf[i]), io_size, rbuffer);
            op = new_ibp_read_op(ic, get_ibp_cap(&(caps[slot]), IBP_READCAP), offset, &(buf[i]), 0, io_size, ibp_timeout);
        } else {
            tbuffer_single(&(buf[i]), io_size, wbuffer);
            op = new_ibp_write_op(ic, get_ibp_cap(&(caps[slot]), IBP_WRITECAP), offset, &(buf[i]), 0, io_size, ibp_timeout);
        }

        opque_add(q, op);
    }

    io_start(q);
    err = io_waitall(q);
    if (err != 0) {
        printf("small_random_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, opque_tasks_failed(q));
    }
    opque_free(q, OP_DESTROY);

    free(buf);
    free(rbuffer);
    free(wbuffer);

    return(nbytes);
}
Beispiel #20
0
int wave_close(void* theHandler)
{
  SHOW_TIME("wave_close > ENTER");

  static int aStopStreamCount = 0;

#if (USE_PORTAUDIO == 19)
  if( pa_stream == NULL )
    {
      SHOW_TIME("wave_close > LEAVE (NULL stream)");
      return 0;
    }
      
  if( Pa_IsStreamStopped( pa_stream ) )
    {
      SHOW_TIME("wave_close > LEAVE (stopped)");
      return 0;
    }
#else
  if( pa_stream == NULL )
    {
      SHOW_TIME("wave_close > LEAVE (NULL stream)");
      return 0;
    }
  
  if( Pa_StreamActive( pa_stream ) == false && mInCallbackFinishedState == false )
    {
      SHOW_TIME("wave_close > LEAVE (not active)");
      return 0;
    }
#endif

  // Avoid race condition by making sure this function only
  // gets called once at a time
  aStopStreamCount++;
  if (aStopStreamCount != 1)
    {
      SHOW_TIME("wave_close > LEAVE (stopStreamCount)");
      return 0;
    }
  
  // Comment from Audacity-1.2.4b adapted to the eSpeak context. 
  //
  // We got here in one of two ways:
  //
  // 1. The calling program calls the espeak_Cancel function and we 
  //    therefore want to stop as quickly as possible.  
  //    So we use AbortStream().  If this is
  //    the case the portaudio stream is still in the Running state
  //    (see PortAudio state machine docs).
  //
  // 2. The callback told PortAudio to stop the stream since it had
  //    reached the end of the selection.  
  //    The event polling thread discovered this by noticing that 
  //    wave_is_busy() returned false.
  //    wave_is_busy() (which calls Pa_GetStreamActive()) will not return
  //    false until all buffers have finished playing, so we can call
  //    AbortStream without losing any samples.  If this is the case
  //    we are in the "callback finished state" (see PortAudio state
  //    machine docs).
  //
  // The moral of the story: We can call AbortStream safely, without
  // losing samples.
  //
  // DMM: This doesn't seem to be true; it seems to be necessary to
  // call StopStream if the callback brought us here, and AbortStream
  // if the user brought us here.
  //
  
#if (USE_PORTAUDIO == 19)
  if (pa_stream)
    {
      Pa_AbortStream( pa_stream );
      SHOW_TIME("wave_close > Pa_AbortStream (end)");

      Pa_CloseStream( pa_stream );
      SHOW_TIME("wave_close > Pa_CloseStream (end)");
      pa_stream = NULL;
      mInCallbackFinishedState = false;
    }
#else
  if (pa_stream)
    {
      if (mInCallbackFinishedState)
	{
	  Pa_StopStream( pa_stream );
	  SHOW_TIME("wave_close > Pa_StopStream (end)");
	}
      else
	{
	  Pa_AbortStream( pa_stream );
	  SHOW_TIME("wave_close > Pa_AbortStream (end)");
	}
      Pa_CloseStream( pa_stream );
      SHOW_TIME("wave_close > Pa_CloseStream (end)");

      pa_stream = NULL;
      mInCallbackFinishedState = false;
    }
#endif
  init_buffer();

  aStopStreamCount = 0; // last action
  SHOW_TIME("wave_close > LEAVE");
  return 0;
}
void OutputSingleLayerOperation::initExecution()
{
	this->m_imageInput = getInputSocketReader(0);
	this->m_outputBuffer = init_buffer(this->getWidth(), this->getHeight(), this->m_datatype);
}
Beispiel #22
0
struct session *new_session(struct session *ses, char *name, char *arg, int desc)
{
	int cnt = 0;
	char host[BUFFER_SIZE], port[BUFFER_SIZE], file[BUFFER_SIZE];
	struct session *newsession;

	push_call("new_session(%p,%p,%p,%d)",ses,name,arg,desc);

	if (HAS_BIT(gtd->flags, TINTIN_FLAG_TERMINATE))
	{
		pop_call();
		return ses;
	}

	arg = sub_arg_in_braces(ses, arg, host, GET_ONE, SUB_VAR|SUB_FUN);
	arg = sub_arg_in_braces(ses, arg, port, GET_ONE, SUB_VAR|SUB_FUN);
	arg = sub_arg_in_braces(ses, arg, file, GET_ONE, SUB_VAR|SUB_FUN);

	if (desc == 0)
	{
		if (*host == 0)
		{
			tintin_puts(ses, "#HEY! SPECIFY AN ADDRESS WILL YOU?");

			pop_call();
			return ses;
		}

		if (*port == 0)
		{
			tintin_puts(ses, "#HEY! SPECIFY A PORT NUMBER WILL YOU?");

			pop_call();
			return ses;
		}
	}

	for (newsession = gts ; newsession ; newsession = newsession->next)
	{
		if (!strcmp(newsession->name, name))
		{
			tintin_puts(ses, "THERE'S A SESSION WITH THAT NAME ALREADY.");

			pop_call();
			return ses;
		}
	}

	newsession                = (struct session *) calloc(1, sizeof(struct session));

	newsession->name          = strdup(name);
	newsession->host          = strdup(host);
	newsession->ip            = strdup("");
	newsession->port          = strdup(port);

	newsession->group         = strdup(gts->group);
	newsession->flags         = gts->flags;
	newsession->telopts       = gts->telopts;
	newsession->auto_tab      = gts->auto_tab;

	newsession->cmd_color     = strdup(gts->cmd_color);

	newsession->read_max      = gts->read_max;
	newsession->read_buf      = (unsigned char *) calloc(1, gts->read_max);

	LINK(newsession, gts->next, gts->prev);

	for (cnt = 0 ; cnt < LIST_MAX ; cnt++)
	{
		newsession->list[cnt] = copy_list(newsession, gts->list[cnt], cnt);
	}

	newsession->rows          = gts->rows;
	newsession->cols          = gts->cols;
	newsession->top_row       = gts->top_row;
	newsession->bot_row       = gts->bot_row;

	init_buffer(newsession, gts->scroll_max);

	if (desc)
	{
		tintin_printf(ses, "#TRYING TO LAUNCH '%s' RUNNING '%s'.", newsession->name, newsession->host);
	}
	else
	{
		tintin_printf(ses, "#TRYING TO CONNECT '%s' TO '%s' PORT '%s'.", newsession->name, newsession->host, newsession->port);
	}

	gtd->ses = newsession;

	dirty_screen(newsession);

	if (desc == 0)
	{
		newsession = connect_session(newsession);
	}
	else
	{
		SET_BIT(newsession->flags, SES_FLAG_CONNECTED|SES_FLAG_RUN);

		SET_BIT(newsession->telopts, TELOPT_FLAG_SGA);
		DEL_BIT(newsession->telopts, TELOPT_FLAG_ECHO);

		gtd->ses = newsession;

		gtd->ses->socket = desc;
	}

	if (newsession)
	{
		if (*file)
		{
			do_read(newsession, file);
		}
	}

	pop_call();
	return gtd->ses;
}
        /* Changed A LOT */
        Bacteria(char* filename)
        {
            FILE * bacteria_file = fopen(filename,"r");
            InitVectors();

            /* This part is the same */
            char ch;
            while ((ch = fgetc(bacteria_file)) != EOF)
            {
                if (ch == '>')
                {
                    while (fgetc(bacteria_file) != '\n'); // skip rest of line

                    char buffer[LEN-1];
                    fread(buffer, sizeof(char), LEN-1, bacteria_file);
                    init_buffer(buffer);
                }
                else if (ch != '\n' && ch != '\r')
                    cont_buffer(ch);
            }

            // keeping some calculations stored
            long total_plus_complement = total + complement;
            double total_div_2 = total * 0.5;
            int i_mod_aa_number = 0;
            int i_div_aa_number = 0;
            long i_mod_M1 = 0;
            long i_div_M1 = 0;

            double one_l_div_total[AA_NUMBER];
            for (int i=0; i<AA_NUMBER; i++)
                one_l_div_total[i] = (double)one_l[i] / total_l;
            
            double* second_div_total = new double[M1];
            for (int i=0; i<M1; i++)
                second_div_total[i] = (double)second[i] / total_plus_complement;

            // this is the stochastic processing for comparison. Computes everything and
            // stores. Need to understand better.
            count = 0;
            double* t = new double[M];

            for(long i=0; i<M; i++)
            {
                double p1 = second_div_total[i_div_aa_number];
                double p2 = one_l_div_total[i_mod_aa_number];
                double p3 = second_div_total[i_mod_M1];
                double p4 = one_l_div_total[i_div_M1];
                double stochastic =  (p1 * p2 + p3 * p4) * total_div_2;

                if (i_mod_aa_number == AA_NUMBER-1)
                {
                    i_mod_aa_number = 0;
                    i_div_aa_number++;
                }
                else
                    i_mod_aa_number++;

                if (i_mod_M1 == M1-1)
                {
                    i_mod_M1 = 0;
                    i_div_M1++;
                }
                else
                    i_mod_M1++;

                if (stochastic > EPSILON) 
                {
                    t[i] = (vector[i] - stochastic) / stochastic;
                    count++;
                }
                else
                    t[i] = 0;
            }
            
            delete second_div_total;
            delete vector;
            delete second;

            tv = new double[count];
            ti = new long[count];

            int pos = 0;
            for (long i=0; i<M; i++)
            {
                if (t[i] != 0)
                {
                    tv[pos] = t[i];
                    ti[pos] = i;
                    pos++;
                }
            }
            delete t;

            fclose (bacteria_file);
        }
Beispiel #24
0
static void
init_str_stream(BaseStream base, Str s)
{
    init_buffer(base, s->ptr, s->length);
}
Beispiel #25
0
static void
init_base_stream(BaseStream base, int bufsize)
{
    init_buffer(base, NULL, bufsize);
}
Beispiel #26
0
	void Triangle::init(ComPtr<ID3D12Device> pD3D12Device)
	{
		init_buffer(pD3D12Device);
		init_shader(pD3D12Device);
	}
Beispiel #27
0
int main(int argc, char** argv)
{
    std::vector<std::chrono::duration<double, std::milli>> duration_vector_1, duration_vector_2;

    bool run_ref = false, run_tiramisu = false;

    const char* env_ref = std::getenv("RUN_REF");
    if (env_ref != NULL && env_ref[0] == '1')
        run_ref = true;

    const char* env_tiramisu = std::getenv("RUN_TIRAMISU");
    if (env_tiramisu != NULL && env_tiramisu[0] == '1')
        run_tiramisu = true;

    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------
  
    double alpha = 2.5;
  
    Halide::Buffer<int> SIZES(1);
    SIZES(0) = nrow;
  
    Halide::Buffer<double> b_alpha(1);
    b_alpha(0) = alpha;
  
    Halide::Buffer<double> b_X(nrow), b_X_ref(nrow);

    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------

    {
        for (int i = 0; i < NB_TESTS; ++i)
        {
            init_buffer(b_X_ref, (double)1);
            auto start = std::chrono::high_resolution_clock::now();
      
            if (run_ref)
	    	scal_ref(nrow, alpha, b_X_ref.data());
      
            auto end = std::chrono::high_resolution_clock::now();
            duration_vector_1.push_back(end - start);
        }
    }

    {
        for (int i = 0; i < NB_TESTS; ++i)
        {
            init_buffer(b_X, (double)1);
            auto start = std::chrono::high_resolution_clock::now();

            if (run_tiramisu)
	    	scal(SIZES.raw_buffer(), b_alpha.raw_buffer(), b_X.raw_buffer());

            auto end = std::chrono::high_resolution_clock::now();
            duration_vector_2.push_back(end - start);
        }
    }

    print_time("performance_cpu.csv", "scal",
	       {"Ref", "Tiramisu"},
	       {median(duration_vector_1), median(duration_vector_2)});

    if (CHECK_CORRECTNESS && run_ref && run_tiramisu)
        compare_buffers("scal", b_X_ref, b_X);

    if (PRINT_OUTPUT)
    {
        std::cout << "Tiramisu " << std::endl;
        print_buffer(b_X);

        std::cout << "Reference " << std::endl;
        print_buffer(b_X_ref);
    }
  
    return 0;
}
Beispiel #28
0
void do_bench(char *compressor, char *shuffle, int nthreads, int size, int elsize,
              int rshift, FILE * ofile) {
  void *src, *srccpy;
  void *dest[NCHUNKS], *dest2;
  int nbytes = 0, cbytes = 0;
  int i, j, retcode;
  unsigned char *orig, *round;
  blosc_timestamp_t last, current;
  double tmemcpy, tshuf, tunshuf;
  int clevel, doshuffle;

  if (strcmp(shuffle, "shuffle") == 0) {
      doshuffle = BLOSC_SHUFFLE;
    }
  else if (strcmp(shuffle, "bitshuffle") == 0) {
      doshuffle = BLOSC_BITSHUFFLE;
    }
  else if (strcmp(shuffle, "noshuffle") == 0) {
      doshuffle = BLOSC_NOSHUFFLE;
    }

  blosc_set_nthreads(nthreads);
  if(blosc_set_compressor(compressor) < 0){
    printf("Compiled w/o support for compressor: '%s', so sorry.\n",
           compressor);
    exit(1);
  }

  /* Initialize buffers */
  srccpy = malloc(size);
  retcode = posix_memalign( (void **)(&src), 32, size);
  retcode = posix_memalign( (void **)(&dest2), 32, size);

  /* zero src to initialize byte on it, and not only multiples of 4 */
  memset(src, 0, size);
  init_buffer(src, size, rshift);
  memcpy(srccpy, src, size);
  for (j = 0; j < nchunks; j++) {
     retcode = posix_memalign( (void **)(&dest[j]), 32, size+BLOSC_MAX_OVERHEAD);
  }

  fprintf(ofile, "--> %d, %d, %d, %d, %s, %s\n", nthreads, size, elsize, rshift, compressor, shuffle);
  fprintf(ofile, "********************** Run info ******************************\n");
  fprintf(ofile, "Blosc version: %s (%s)\n", BLOSC_VERSION_STRING, BLOSC_VERSION_DATE);
  fprintf(ofile, "Using synthetic data with %d significant bits (out of 32)\n", rshift);
  fprintf(ofile, "Dataset size: %d bytes\tType size: %d bytes\n", size, elsize);
  fprintf(ofile, "Working set: %.1f MB\t\t", (size*nchunks) / (float)MB);
  fprintf(ofile, "Number of threads: %d\n", nthreads);
  fprintf(ofile, "********************** Running benchmarks *********************\n");

  blosc_set_timestamp(&last);
  for (i = 0; i < niter; i++) {
    for (j = 0; j < nchunks; j++) {
      memcpy(dest[j], src, size);
    }
  }
  blosc_set_timestamp(&current);
  tmemcpy = get_usec_chunk(last, current, niter, nchunks);
  fprintf(ofile, "memcpy(write):\t\t %6.1f us, %.1f MB/s\n",
         tmemcpy, (size * 1e6) / (tmemcpy*MB));

  blosc_set_timestamp(&last);
  for (i = 0; i < niter; i++) {
    for (j = 0; j < nchunks; j++) {
      memcpy(dest2, dest[j], size);
    }
  }
  blosc_set_timestamp(&current);
  tmemcpy = get_usec_chunk(last, current, niter, nchunks);
  fprintf(ofile, "memcpy(read):\t\t %6.1f us, %.1f MB/s\n",
         tmemcpy, (size * 1e6) / (tmemcpy*MB));

  for (clevel=0; clevel<10; clevel++) {

    fprintf(ofile, "Compression level: %d\n", clevel);

    blosc_set_timestamp(&last);
    for (i = 0; i < niter; i++) {
      for (j = 0; j < nchunks; j++) {
        cbytes = blosc_compress(clevel, doshuffle, elsize, size, src,
                                dest[j], size+BLOSC_MAX_OVERHEAD);
      }
    }
    blosc_set_timestamp(&current);
    tshuf = get_usec_chunk(last, current, niter, nchunks);
    fprintf(ofile, "comp(write):\t %6.1f us, %.1f MB/s\t  ",
           tshuf, (size * 1e6) / (tshuf*MB));
    fprintf(ofile, "Final bytes: %d  ", cbytes);
    if (cbytes > 0) {
      fprintf(ofile, "Ratio: %3.2f", size/(float)cbytes);
    }
    fprintf(ofile, "\n");

    /* Compressor was unable to compress.  Copy the buffer manually. */
    if (cbytes == 0) {
      for (j = 0; j < nchunks; j++) {
        memcpy(dest[j], src, size);
      }
    }

    blosc_set_timestamp(&last);
    for (i = 0; i < niter; i++) {
      for (j = 0; j < nchunks; j++) {
        if (cbytes == 0) {
          memcpy(dest2, dest[j], size);
          nbytes = size;
        }
        else {
          nbytes = blosc_decompress(dest[j], dest2, size);
        }
      }
    }
    blosc_set_timestamp(&current);
    tunshuf = get_usec_chunk(last, current, niter, nchunks);
    fprintf(ofile, "decomp(read):\t %6.1f us, %.1f MB/s\t  ",
           tunshuf, (nbytes * 1e6) / (tunshuf*MB));
    if (nbytes < 0) {
      fprintf(ofile, "FAILED.  Error code: %d\n", nbytes);
    }
    /* fprintf(ofile, "Orig bytes: %d\tFinal bytes: %d\n", cbytes, nbytes); */

    /* Check if data has had a good roundtrip.
       Byte-by-byte comparison is slow, so use 'memcmp' to check whether the
       roundtripped data is correct. If not, fall back to the slow path to
       print diagnostic messages. */
    orig = (unsigned char *)srccpy;
    round = (unsigned char *)dest2;
    if (memcmp(orig, round, size) != 0)
    {
      for(i = 0; i<size; ++i){
        if (orig[i] != round[i]) {
          fprintf(ofile, "\nError: Original data and round-trip do not match in pos %d\n",
                 (int)i);
          fprintf(ofile, "Orig--> %x, round-trip--> %x\n", orig[i], round[i]);
          break;
        }
      }
    }
    else { i = size; }

    if (i == size) fprintf(ofile, "OK\n");

  } /* End clevel loop */


  /* To compute the totalsize, we should take into account the 10
     compression levels */
  totalsize += (size * nchunks * niter * 10.);

  aligned_free(src); free(srccpy); aligned_free(dest2);
  for (i = 0; i < nchunks; i++) {
    aligned_free(dest[i]);
  }

}
Beispiel #29
0
/* ARGSUSED */
int
main (int argc, char **argv, char **envp)
{
  int skip_args = 0;

#ifdef HAVE_PERSONALITY_LINUX32
  /* See if there is a gap between the end of BSS and the heap.
     In that case, set personality and exec ourself again.  */
  if (!initialized
      && strcmp (argv[argc-1], "dump") == 0
      && !getenv ("EMACS_HEAP_EXEC"))
    {
      /* Set this so we only do this once.  */
      putenv ("EMACS_HEAP_EXEC=true");

      /* A flag to turn off address randomization which is introduced
	 in linux kernel shipped with fedora core 4 */
      personality (PER_LINUX32 | ADDR_NO_RANDOMIZE);

      execvp (argv[0], argv);

      /* If the exec fails, try to dump anyway.  */
      perror ("execvp");
    }
#endif /* HAVE_PERSONALITY_LINUX32 */
 
/* Map in shared memory, if we are using that.  */
#ifdef HAVE_SHM
  if (argc > 1 && !strcmp (argv[1], "-nl"))
    {
      map_in_data (0);
      /* The shared memory was just restored, which clobbered this.  */
      skip_args = 1;
    }
  else
    {
      map_in_data (1);
      /* The shared memory was just restored, which clobbered this.  */
      skip_args = 0;
    }
#endif

#ifdef VMS
  /* If -map specified, map the data file in */
  if (argc > 2 && ! strcmp (argv[1], "-map"))
    {
      skip_args = 2;
      mapin_data (argv[2]);
    }

#ifdef LINK_CRTL_SHARE
#ifdef SHAREABLE_LIB_BUG
  /* Bletcherous shared libraries! */
  if (!stdin)
    stdin = fdopen (0, "r");
  if (!stdout)
    stdout = fdopen (1, "w");
  if (!stderr)
    stderr = fdopen (2, "w");
  if (!environ)
    environ = envp;
#endif /* SHAREABLE_LIB_BUG */
#endif /* LINK_CRTL_SHARE */
#endif /* VMS */
/* 92.11.4, 93.2.17 by M.Higashida */
#if defined(MSDOS) && defined(EMX)
  environ = envp;
#endif
#ifdef WIN32
  environ = envp;
#endif
/* end of patch */

#ifdef USG_SHARED_LIBRARIES
  if (bss_end)
    brk (bss_end);
#endif

#ifdef NeXT
  extern int malloc_cookie;

  /* This helps out unexnext.c.  */
  if (initialized) {
    if (malloc_jumpstart (malloc_cookie) != 0)
      fatal("malloc jumpstart failed!\n");
  } else {
    emacszone = NXCreateZone(ZONESIZE*vm_page_size,vm_page_size,1);
    if(emacszone == NX_NOZONE)
      fatal("can't create emacs zone.\n");
  }
#endif /* NeXT */

  clearerr (stdin);

#ifdef APOLLO
#ifndef APOLLO_SR10
  /* If USE_DOMAIN_ACLS environment variable exists,
     use ACLs rather than UNIX modes. */
  if (egetenv ("USE_DOMAIN_ACLS"))
    default_acl (USE_DEFACL);
#endif
#endif /* APOLLO */

#ifndef SYSTEM_MALLOC
  /* Arrange for warnings when nearly out of space.  */
  malloc_init (0, malloc_warning);
#endif

/* 91.10.16 by S.Hirano */
#if defined(MSDOS) && defined(GO32)
  _fmode = O_BINARY;	/* all of files are treated as binary files */
  (stdin)->_flag &= ~_IOTEXT;   /* also binary for stdio */
  (stdout)->_flag &= ~_IOTEXT;
  (stderr)->_flag &= ~_IOTEXT;
#endif /* MSDOS */
/* end of patch */

#ifdef HIGHPRI
  setpriority (PRIO_PROCESS, getpid (), HIGHPRI);
  setuid (getuid ());
#endif

  inhibit_window_system = 0;

/* 92.3.31 by K.Handa, 92.10.21 by M.Higashida */
#if defined (HAVE_X_WINDOWS) || defined (HAVE_SUN_CONSOLE) || (defined(MSDOS) && defined(HAVE_VGA_ADAPTER)) || defined (WIN32)
  xargv = argv;
  xargc = argc;
#endif

/* Handle the -t switch, which specifies filename to use as terminal */
  if (skip_args + 2 < argc && !strcmp (argv[skip_args + 1], "-t"))
    {
      skip_args += 2;
      close (0);
      close (1);
      open (argv[skip_args], O_RDWR, 2 );
      dup (0);
      fprintf (stderr, "Using %s\n", argv[skip_args]);
/* 92.3.31 by K.Handa, 92.10.21 by M.Higashida */
#if defined (HAVE_X_WINDOWS) || defined (HAVE_SUN_CONSOLE) || (defined(MSDOS) && defined(HAVE_VGA_ADAPTER)) || defined (WIN32)
      inhibit_window_system = 1;	/* -t => -nw */
#endif
    }
#ifdef HAVE_X_WINDOWS
/* Handle the -d switch, which means use a different display for X */
  if (skip_args + 2 < argc && (!strcmp (argv[skip_args + 1], "-d") ||
			       !strcmp (argv[skip_args + 1], "-display")))
    {
      skip_args += 2;
      alternate_display = argv[skip_args];
    } 
  else
    alternate_display = 0;
#endif	/* HAVE_X_WINDOWS */
/* 92.3.31 by K.Handa */
#ifdef HAVE_SUN_CONSOLE
  if (skip_args + 1 < argc && (!strcmp (argv[skip_args + 1], "-sun"))) {
    extern Pixrect *screen;

    inhibit_window_system = -1;
    skip_args++;
    alternate_display = "/dev/fb";
    if (skip_args + 2 < argc && (!strcmp (argv[skip_args + 1], "-fb"))) {
      skip_args += 2;
      alternate_display = argv[skip_args];
    }
    if (screen = pr_open(alternate_display)) /* Just a test. */
      pr_close(screen);
    else
      alternate_display = 0;
  }
#endif /* HAVE_SUN_CONSOLE */
/* end of patch */
/* 92.10.17, 93.2.17 by M.Higashida */
#if defined(MSDOS) && defined(HAVE_VGA_ADAPTER)
  if (skip_args + 1 < argc && (!strcmp (argv[skip_args + 1], "-vga"))) {
    inhibit_window_system = -1;
    skip_args++;
  }
#endif /* MSDOS and HAVE_VGA_ADAPTER */
#ifdef WIN32
  inhibit_window_system = -1;
#endif
/* end of patch */
  if (skip_args + 1 < argc
      && (!strcmp (argv[skip_args + 1], "-nw")))
    {
      skip_args += 1;
      inhibit_window_system = 1;
    }

/* Handle the -batch switch, which means don't do interactive display.  */
  noninteractive = 0;
  if (skip_args + 1 < argc && !strcmp (argv[skip_args + 1], "-batch"))
    {
      skip_args += 1;
      noninteractive = 1;
    }

#ifdef POSIX_SIGNALS
  init_signals ();
#endif

#ifdef HAVE_TZSET
  /* Reinitialize the time zone if it was initialized before dumping Emacs.  */
  if (initialized)
    tzset ();
#endif
#ifdef WIN32 /* 93.2.25 by M.Higashida */
  _tzset ();
#endif

  if (
#ifndef CANNOT_DUMP
      ! noninteractive || initialized
#else
      1
#endif
      )
    {
      /* Don't catch these signals in batch mode if not initialized.
	 On some machines, this sets static data that would make
	 signal fail to work right when the dumped Emacs is run.  */
/* 91.10.16 by S.Hirano, 92.11.4 by M.Higashida */
#ifdef MSDOS
#ifdef GO32
      /* Nothing */
#else
#ifdef EMX
      signal (SIGBREAK, fatal_error_signal);
      signal (SIGQUIT, fatal_error_signal);
#endif
#endif
#else /* not MSDOS */
      signal (SIGHUP, fatal_error_signal);
      signal (SIGQUIT, fatal_error_signal);
      signal (SIGILL, fatal_error_signal);
      signal (SIGTRAP, fatal_error_signal);
      signal (SIGIOT, fatal_error_signal);
#ifdef SIGEMT
      signal (SIGEMT, fatal_error_signal);
#endif
      signal (SIGFPE, fatal_error_signal);
      signal (SIGBUS, fatal_error_signal);
      signal (SIGSEGV, fatal_error_signal);
      signal (SIGSYS, fatal_error_signal);
      signal (SIGTERM, fatal_error_signal);
#ifdef SIGXCPU
      signal (SIGXCPU, fatal_error_signal);
#endif
#ifdef SIGXFSZ
      signal (SIGXFSZ, fatal_error_signal);
#endif
#endif /* not MSDOS and GO32 */
/* end of patch */

#ifdef AIX
      /* This used to run fatal_error_signal,
	 but it isn't fatal.  There's nothing Emacs can usefully do.
	 Might as well let the system kill us if it insists.  */
      signal (SIGDANGER, SIG_IGN);
      signal (20, fatal_error_signal);
      signal (21, fatal_error_signal);
      signal (22, fatal_error_signal);
      signal (23, fatal_error_signal);
      signal (24, fatal_error_signal);
#ifdef SIGIO
      signal (SIGAIO, fatal_error_signal);
      signal (SIGPTY, fatal_error_signal);
#endif
#ifdef SIGURG
      /* Note that SIGIOINT is the same as SIGIO on some machines,
	 and the same as SIGURG on others.  It seems ore reliable to use the
	 name with a uniform meaning.  */
      signal (SIGURG, fatal_error_signal);
#endif
      signal (SIGGRANT, fatal_error_signal);
      signal (SIGRETRACT, fatal_error_signal);
      signal (SIGSOUND, fatal_error_signal);
      signal (SIGMSG, fatal_error_signal);
#endif /* AIX */
    }

  noninteractive1 = noninteractive;

/* Perform basic initializations (not merely interning symbols) */

  if (!initialized)
    {
      init_alloc_once ();
      init_obarray ();
      init_eval_once ();
      init_mc_once ();		/* 89.7.26, 91.10.19 by K.Handa */
      init_syntax_once ();	/* Create standard syntax table.  */
      init_category_once ();	/* 91.12.7 by K.Handa */
		      /* Must be done before init_buffer */
      init_buffer_once ();	/* Create buffer table and some buffers */
      init_minibuf_once ();	/* Create list of minibuffers */
			      /* Must precede init_window_once */
      init_window_once ();	/* Init the window system */
      /* 92.10.28 by M.Higashida */
#if defined (MSDOS) && defined (HAVE_VGA_ADAPTER)
      init_bdf_once ();		/* Init the BDF font structure. */
#endif
      /* end of patch */
    }

  init_alloc ();
#ifdef MAINTAIN_ENVIRONMENT
  init_environ ();
/* 92.3.25 by N.Hikichi */
#ifdef HAVE_X_WINDOWS
  if (alternate_display)
    set_environment_alist (build_string ("DISPLAY"),
			   build_string (alternate_display));
#endif /* HAVE_X_WINDOWS */
/* end of patch */
#endif
  init_codeconv ();		/* 92.1.7 by K.Handa */
  init_eval ();
  init_data ();
  init_read ();

  init_cmdargs (argc, argv, skip_args);	/* Create list Vcommand_line_args */
  init_buffer ();	/* Init default directory of main buffer */
  if (!noninteractive)
    {
#ifdef VMS
      init_vms_input ();/* init_display calls get_screen_size, that needs this */
#endif /* VMS */
      init_display ();	/* Determine terminal type.  init_sys_modes uses results */
    }
  init_keyboard ();	/* This too must precede init_sys_modes */
  init_callproc ();	/* And this too. */
  init_sys_modes ();	/* Init system terminal modes (RAW or CBREAK, etc.) */
  init_xdisp ();
  init_macros ();
  init_editfns ();
#ifdef VMS
  init_vmsfns ();
#endif /* VMS */
#ifdef subprocesses
  init_process ();
#endif /* subprocesses */

/* Intern the names of all standard functions and variables; define standard keys */

  if (!initialized)
    {
      /* The basic levels of Lisp must come first */
      /* And data must come first of all
	 for the sake of symbols like error-message */
      syms_of_data ();
      syms_of_alloc ();
#ifdef MAINTAIN_ENVIRONMENT
      syms_of_environ ();
#endif /* MAINTAIN_ENVIRONMENT */
      syms_of_read ();
      syms_of_print ();
      syms_of_eval ();
      syms_of_fns ();

      syms_of_abbrev ();
      syms_of_buffer ();
      syms_of_bytecode ();
      syms_of_callint ();
      syms_of_casefiddle ();
      syms_of_callproc ();
      syms_of_category ();	/* 91.11.11 by K.Handa */
      syms_of_codeconv ();	/* 92.1.7 by K.Handa */
      syms_of_cmds ();
#ifndef NO_DIR_LIBRARY
      syms_of_dired ();
#endif /* not NO_DIR_LIBRARY */
      syms_of_display ();
      syms_of_doc ();
      syms_of_editfns ();
      syms_of_emacs ();
      syms_of_fileio ();
#ifdef CLASH_DETECTION
      syms_of_filelock ();
#endif /* CLASH_DETECTION */
/* 92.11.1 by M.Higashida */
#ifdef FILE_TRANSLATION_MODE
      syms_of_transmode ();
#endif /* FILE_TRANSLATION_MODE */
/* end of patch */
      syms_of_indent ();
      syms_of_keyboard ();
      syms_of_keymap ();
      syms_of_macros ();
      syms_of_marker ();
      syms_of_minibuf ();
      syms_of_mocklisp ();
#ifdef subprocesses
      syms_of_process ();
#endif /* subprocesses */
      syms_of_search ();
      syms_of_syntax ();
      syms_of_undo ();
      syms_of_window ();
      syms_of_xdisp ();
#ifdef HAVE_X_WINDOWS
      syms_of_xfns ();
#ifdef HAVE_X_MENU
      syms_of_xmenu ();
#endif /* HAVE_X_MENU */
#endif /* HAVE_X_WINDOWS */
/* 87.6.8, 91.11.2, 92.3.31, 92.7.31  by K.Handa, 92.10.17, 93.2.17 by M.Higashida */
#ifdef HAVE_SUN_CONSOLE
      syms_of_sunterm ();
#endif
#if defined(MSDOS) && defined(HAVE_VGA_ADAPTER)
      syms_of_vgaterm ();
#endif
#ifdef WIN32
      syms_of_win32term ();
#endif
      syms_of_mc ();
      syms_of_ccl ();		/* 93.5.14 by K.Handa */
#ifdef WNN4
      syms_of_wnn ();
#endif
#ifdef CANNA
      syms_of_canna ();
#endif /* CANNA */
/* end of patch */

#ifdef MCPATH
      syms_of_mcpath ();
#endif /* MCPATH */

#ifdef SYMS_SYSTEM
      SYMS_SYSTEM;
#endif

#ifdef SYMS_MACHINE
      SYMS_MACHINE;
#endif

      keys_of_casefiddle ();
      keys_of_cmds ();
      keys_of_buffer ();
      keys_of_keyboard ();
      keys_of_keymap ();
      keys_of_macros ();
      keys_of_minibuf ();
      keys_of_window ();
    }

  if (!initialized)
    {
      /* Handle -l loadup-and-dump, args passed by Makefile. */
      if (argc > 2 + skip_args && !strcmp (argv[1 + skip_args], "-l"))
	Vtop_level = Fcons (intern ("load"),
			    Fcons (build_string (argv[2 + skip_args]), Qnil));
#ifdef CANNOT_DUMP
      /* Unless next switch is -nl, load "loadup.el" first thing.  */
      if (!(argc > 1 + skip_args && !strcmp (argv[1 + skip_args], "-nl")))
	Vtop_level = Fcons (intern ("load"),
			    Fcons (build_string ("loadup.el"), Qnil));
#endif /* CANNOT_DUMP */
    }

  initialized = 1;

  /* Enter editor command loop.  This never returns.  */
  Frecursive_edit ();
  /* NOTREACHED */
}
Beispiel #30
0
int main(int, char**)
{
    std::vector<std::chrono::duration<double,std::milli>> duration_vector_1;
    std::vector<std::chrono::duration<double,std::milli>> duration_vector_2;

#if SYNTHETIC_INPUT
    Halide::Buffer<uint8_t> im1(10, 10);
    Halide::Buffer<uint8_t> im2(10, 10);

    for (int i = 0; i < 10; i++)
	    for (int j = 0; j < 10; j++)
	    {
		    im1(i, j) = (uint8_t) i*i+j*j;
		    im2(i, j) = (uint8_t) i*i+j*j;
	    }
#else
    Halide::Buffer<uint8_t> im1 = Halide::Tools::load_image("./utils/images/rgb.png");
    Halide::Buffer<uint8_t> im2 = Halide::Tools::load_image("./utils/images/rgb.png");
#endif

    Halide::Buffer<float> Ix_m(im1.width(), im1.height());
    Halide::Buffer<float> Iy_m(im1.width(), im1.height());
    Halide::Buffer<float> It_m(im1.width(), im1.height());
    Halide::Buffer<int> C1(_NC);
    Halide::Buffer<int> C2(_NC);
    Halide::Buffer<int> SIZES(2);
    Halide::Buffer<int> u(_NC);
    Halide::Buffer<int> v(_NC);
    Halide::Buffer<float> A(2, 4*w*w);
    Halide::Buffer<float> tA(4*w*w, 2);
    Halide::Buffer<double> pinvA(4*w*w, 2);
    Halide::Buffer<double> det(1);
    Halide::Buffer<float> tAA(2, 2);
    Halide::Buffer<double> X(2, 2);

    SIZES(0) = im1.height();
    SIZES(1) = im1.width();
    C1(0) = 500; C2(0) = 400;
    C1(1) = 800; C2(1) = 900;
    C1(2) = 200; C2(2) = 400;
    C1(3) = 400; C2(3) = 200;
    C1(4) = 400; C2(4) = 500;
    C1(5) = 800; C2(5) = 200;
    C1(6) = 200; C2(6) = 900;
    C1(7) = 900; C2(7) = 200;

    det(0) = 0;
    init_buffer(Ix_m, (float) 0);
    init_buffer(Iy_m, (float) 0);
    init_buffer(It_m, (float) 0);
    init_buffer(A, (float) 0);
    init_buffer(tA, (float) 0);
    init_buffer(pinvA, (double) 0);
    init_buffer(tAA, (float) 0);
    init_buffer(X, (double) 0);

    // Warm up
    optical_flow_tiramisu(SIZES.raw_buffer(), im1.raw_buffer(), im2.raw_buffer(),
			  Ix_m.raw_buffer(), Iy_m.raw_buffer(), It_m.raw_buffer(),
			  C1.raw_buffer(), C2.raw_buffer(), u.raw_buffer(), v.raw_buffer(), A.raw_buffer(), pinvA.raw_buffer(), det.raw_buffer(), tAA.raw_buffer(), tA.raw_buffer(), X.raw_buffer());

    // Tiramisu
    for (int i=0; i<NB_TESTS; i++)
    {
        auto start1 = std::chrono::high_resolution_clock::now();
        optical_flow_tiramisu(SIZES.raw_buffer(), im1.raw_buffer(), im2.raw_buffer(),
			  Ix_m.raw_buffer(), Iy_m.raw_buffer(), It_m.raw_buffer(),
			  C1.raw_buffer(), C2.raw_buffer(), u.raw_buffer(), v.raw_buffer(), A.raw_buffer(), pinvA.raw_buffer(), det.raw_buffer(), tAA.raw_buffer(), tA.raw_buffer(), X.raw_buffer());
        auto end1 = std::chrono::high_resolution_clock::now();
        std::chrono::duration<double,std::milli> duration1 = end1 - start1;
        duration_vector_1.push_back(duration1);
    }

    std::cout << "Time: " << median(duration_vector_1) << std::endl;

#if SYNTHETIC_INPUT
    print_buffer(im1);
    print_buffer(im2);

    print_buffer(Ix_m);
    print_buffer(Iy_m);
    print_buffer(It_m);

    print_buffer(A);
    print_buffer(tA);
    print_buffer(tAA);
    print_buffer(det);
    print_buffer(X);
    print_buffer(pinvA);
#endif

    std::cout << "Output" << std::endl;

    print_buffer(u);
    print_buffer(v);

    return 0;
}