Exemplo n.º 1
0
int rename_all_files_to_final(struct list *updates)
{
	int ret, update_errs = 0, update_good = 0, skip = 0;
	struct list *list;
	unsigned int complete = 0;
	unsigned int list_length = list_len(updates);

	list = list_head(updates);
	while (list) {
		struct file *file;
		file = list->data;
		list = list->next;
		complete++;
		if (file->do_not_update) {
			skip += 1;
			continue;
		}

		ret = rename_staged_file_to_final(file);
		if (ret != 0) {
			update_errs += 1;
		} else {
			update_good += 1;
		}

		print_progress(complete, list_length);
	}

	print_progress(list_length, list_length); /* Force out 100% */
	printf("\n");
	return update_count - update_good - update_errs - (update_skip - skip);
}
Exemplo n.º 2
0
/*********************** Add audio effect **********************/
static void add_effect(
    void (*effect_init)(void* obj, int td, int fs),
    void (*effect_run)(void* obj, sound_t *out, sound_t *in),
    void (*effect_end)(void* obj),
    char *effect_name
)
{
    void *			effect;
    snd_pcm_uframes_t	count;
    sound_t 		ModWave1;
    sound_t			ModWave2;

    // fs in Hz divided by 100 so that td=1 is set in 10ms intervals
    effect_init(&effect, 20, WaveRate/100);

    print_progress(effect_name, 0);
    // Apply effect
    for(count=0; count < (WaveSize * WaveBits / 8); count += WaveBits / 8)
    {
        print_progress(effect_name, (count*100) / WaveSize * 8 / WaveBits );

        ModWave1 = *(unsigned short*)(WavePtr + count) << 8;

        effect_run(effect, &ModWave2, &ModWave1);

        *(unsigned short*)(WavePtr + count) = ModWave2 >> 8;
    }
    print_progress(effect_name, 100);
    printf("\n");

    effect_end(effect);
}
Exemplo n.º 3
0
idxint ECOS_BB_solve(ecos_bb_pwork* prob) {
    idxint curr_node_idx = 0;

#if MI_PRINTLEVEL > 0
    if (prob->stgs->verbose){
        PRINTTEXT("Iter\tLower Bound\tUpper Bound\tGap\n");
        PRINTTEXT("================================================\n");
    }
#endif

    /* Initialize to root node and execute steps 1 on slide 6 */
    /* of http://stanford.edu/class/ee364b/lectures/bb_slides.pdf*/
    prob->iter = 0;
    initialize_root(prob);
    /*print_node(prob, curr_node_idx);*/
    get_bounds(curr_node_idx, prob);

    prob->global_L = prob->nodes[curr_node_idx].L;
    prob->global_U = prob->nodes[curr_node_idx].U;

    while ( should_continue(prob, curr_node_idx) ){

#if MI_PRINTLEVEL > 0
        if (prob->stgs->verbose){ print_progress(prob); }
#endif

        ++(prob->iter);

        /* Step 2*/
        /* Branch replaces nodes[curr_node_idx] with leftNode*/
        /* and nodes[prob->iter] with rightNode */
        branch(curr_node_idx, prob);

        /* Step 3*/
        get_bounds(curr_node_idx, prob);
        get_bounds(prob->iter, prob);

        /* Step 4*/
        prob->global_L = get_global_L(prob);

        curr_node_idx = get_next_node(prob);
    }
    load_solution(prob);

#if MI_PRINTLEVEL > 0
    if (prob->stgs->verbose){ print_progress(prob); }
#endif

    return get_ret_code(prob);
}
Exemplo n.º 4
0
int progress_callback(void *clientp,
                        double dltotal, double dlnow,
                        double ultotal, double ulnow)
{
    
    // determine wether we are uploading or downloading
    if(dltotal > 0 || dlnow > 0)
        print_progress(dltotal, dlnow);
    else if (ultotal > 0 || ulnow > 0)
        print_progress(ultotal, ulnow);
    else
        fprintf(stderr, "\rUnknown Progress...");
    
    return 0;
}
Exemplo n.º 5
0
void
OSMDocumentParserCallback::show_progress() {
    if ((++m_line % (m_rDocument.lines() / 100)) == 0) {
        print_progress(m_rDocument.lines(), m_line % m_rDocument.lines());
        std::cout << " Total osm elements parsed: " << m_line;
    }
}
Exemplo n.º 6
0
int fetch_progress(git_transfer_progress const *stats, void *payload)
  {
  struct progress_data *pd = (struct progress_data*) payload;
  pd->fetch_progress = *stats;
  print_progress(pd);
  return 0;
  }
Exemplo n.º 7
0
    void run_markov_chain(stan::mcmc::base_mcmc* sampler,
                          const int num_iterations,
                          const int start,
                          const int finish,
                          const int num_thin,
                          const int refresh,
                          const bool save,
                          const bool warmup,
                          stan::io::mcmc_writer <Model,
                          SampleRecorder, DiagnosticRecorder, MessageRecorder>& 
                          writer,
                          stan::mcmc::sample& init_s,
                          Model& model,
                          RNG& base_rng,
                          const std::string& prefix,
                          const std::string& suffix,
                          std::ostream& o,
                          StartTransitionCallback& callback) {
      for (int m = 0; m < num_iterations; ++m) {
        callback();
        
        print_progress(m, start, finish, refresh, warmup, prefix, suffix, o);
      
        init_s = sampler->transition(init_s);
          
        if ( save && ( (m % num_thin) == 0) ) {
          writer.write_sample_params(base_rng, init_s, *sampler, model);
          writer.write_diagnostic_params(init_s, sampler);
        }

      }
      
    }
Exemplo n.º 8
0
static void next_test_case(void)
{
	struct test_case *test;

	if (test_current)
		test_current = g_list_next(test_current);
	else
		test_current = test_list;

	if (!test_current) {
		g_timer_stop(test_timer);

		g_main_loop_quit(main_loop);
		return;
	}

	test = test_current->data;

	printf("\n");
	print_progress(test->name, COLOR_BLACK, "init");

	test->start_time = g_timer_elapsed(test_timer, NULL);

	if (test->timeout > 0)
		test->timeout_id = g_timeout_add_seconds(test->timeout,
							test_timeout, test);

	test->stage = TEST_STAGE_PRE_SETUP;

	test->pre_setup_func(test->test_data);
}
Exemplo n.º 9
0
static DPOINT *get_point_location(int random_path) {
	static int current = 0;
	int i = 0, ri = 0; /* ri: random index */
	DPOINT *pt = NULL;

	if (current == val_data->n_list) {
		current = 0; /* reset for next run */
		return NULL;
	}
	if (current == 0 && random_path) { /* first time: randomize list order */
		for (i = 0; i < val_data->n_list; i++) {
			ri = floor(r_uniform() * (val_data->n_list));
			if (ri >= val_data->n_list) /* obsolete, but anyway... */
				ri = val_data->n_list - 1;
			/* now swap list pointers i and ri: */
			pt = val_data->list[i];
			val_data->list[i] = val_data->list[ri];
			val_data->list[ri] = pt;
		}
	} 
	if (DEBUG_TRACE)
		printf("[cell %d]\n", current); 
	pt = val_data->list[current];
	print_progress(current, val_data->n_list);
	SET_INDEX(pt, current);
	current++;
	return pt;
}
Exemplo n.º 10
0
void tester_wait(unsigned int seconds, tester_wait_func_t func,
							void *user_data)
{
	struct test_case *test;
	struct wait_data *wait;

	if (!func || seconds < 1)
		return;

	if (!test_current)
		return;

	test = test_current->data;

	wait = new0(struct wait_data, 1);
	if (!wait)
		return;

	wait->seconds = seconds;
	wait->test = test;
	wait->func = func;
	wait->user_data = user_data;

	g_timeout_add(1000, wait_callback, wait);

	print_progress(test->name, COLOR_BLACK, "waiting %u seconds", seconds);
}
Exemplo n.º 11
0
double orth_err(matrix_t * matp)
{
  int i, j, k;
  double err, s;
  
  if (verbose >= 2)
    {
      printf("Computing orthogonality error...");
      fflush(stdout);
    }
  
  err = 0.0;
  
  for (j=0 ; j<numcols ; j++)
    {
      print_progress (0, numcols + j, 2*numcols);
      s = 0.0;
      for (k=0 ; k<numrows ; k++)
	s += (*matp)[j][k] * (*matp)[j][k];
      s -= 1;
      err = MAX(err, fabs(s));
      
      for (i=j+1 ; i<numcols ; i++) {
	s = 0.0;
	for (k=0 ; k<numrows ; k++)
	  s += (*matp)[i][k] * (*matp)[j][k];
	err = MAX(err, fabs(s));
      }
    }
  
  if (verbose >= 2)
    printf(" ok: %g, verbose = %d\n", err, verbose);
  
  return err;
}
Exemplo n.º 12
0
template <int dim, typename T> void update(grid<dim,T>& oldGrid, int steps)
{
	int rank=0;
    #ifdef MPI_VERSION
    rank = MPI::COMM_WORLD.Get_rank();
    #endif

	ghostswap(oldGrid);

	grid<dim,T> newGrid(oldGrid);

	T r = 1.0;
	T u = 1.0;
	T K = 1.0;
	T M = 1.0;
	T dt = 0.01;
	T kT = 0.01;
	T dV = 1.0;

	for (int step=0; step<steps; step++) {
		if (rank==0)
			print_progress(step, steps);

		for (int i=0; i<nodes(oldGrid); i++) {
			T phi = oldGrid(i);
			T noise = gaussian(0.0,sqrt(2.0*kT/(dt*dV)));
			newGrid(i) = phi-dt*M*(-r*phi+u*pow(phi,3)-K*laplacian(oldGrid,i)+noise);
		}
		swap(oldGrid,newGrid);
		ghostswap(oldGrid);
	}
}
Exemplo n.º 13
0
void convert_table(char *in,char *out)
{
  TABLE src,dst;
  int i;

  if (open_table(&src,in,"I")<0) {
    print_error("Cannot open input file %s",in);
    exit_session(ERR_OPEN);
  }
  else
    handle_select_flag(&src,'Q',NULL);

  if (create_table(&dst,out,src.row,src.col,'W',src.ident)<0) {
    close_table(&src);
    print_error("Cannot create output file %s",out);
    exit_session(ERR_CREAT);
  }
  else {
    reset_print_progress();
    for (i=1;i<=src.col;i++) {
      print_progress("Convert table: ", (int)((100*i)/src.col),1);
      copy_col(&src,&dst,i);
    }
	
    CP_non_std_desc(&src,&dst);
	
    close_table(&dst);
    close_table(&src);
  }
}
Exemplo n.º 14
0
static int fetch_progress(const git_transfer_progress *stats, void *payload)
{
	progress_data *pd = (progress_data*)payload;
	pd->fetch_progress = *stats;
	print_progress(pd);
	return 0;
}
Exemplo n.º 15
0
void checkout_progress(char const *path, size_t cur, size_t tot, void *payload)
  {
  struct progress_data *pd = (struct progress_data*) payload;
  pd->completed_steps = cur;
  pd->total_steps = tot;
  pd->path = path;
  print_progress(pd);
  }
Exemplo n.º 16
0
static gboolean teardown_callback(gpointer user_data)
{
	struct test_case *test = user_data;

	test->stage = TEST_STAGE_TEARDOWN;

	print_progress(test->name, COLOR_MAGENTA, "teardown");
	test->teardown_func(test->test_data);

	return FALSE;
}
Exemplo n.º 17
0
static void
handle_crash (CutRunContext  *run_context,
              CutTestResult  *result,
              CutConsoleUI   *console)
{
    if (console->verbose_level < CUT_VERBOSE_LEVEL_NORMAL)
        return;
    print_progress(console, CUT_TEST_RESULT_CRASH, "!");
    print_progress_in_detail(console, result);
    fflush(stdout);
}
Exemplo n.º 18
0
static gboolean done_callback(gpointer user_data)
{
	struct test_case *test = user_data;

	test->end_time = g_timer_elapsed(test_timer, NULL);

	print_progress(test->name, COLOR_BLACK, "done");
	next_test_case();

	return FALSE;
}
Exemplo n.º 19
0
static gboolean run_callback(gpointer user_data)
{
	struct test_case *test = user_data;

	test->stage = TEST_STAGE_RUN;

	print_progress(test->name, COLOR_BLACK, "run");
	test->test_func(test->test_data);

	return FALSE;
}
Exemplo n.º 20
0
static gboolean setup_callback(gpointer user_data)
{
	struct test_case *test = user_data;

	test->stage = TEST_STAGE_SETUP;

	print_progress(test->name, COLOR_BLUE, "setup");
	test->setup_func(test->test_data);

	return FALSE;
}
Exemplo n.º 21
0
bool Test::do_test(bool cond, const std::string& lbl,
                   const char* fname, long lineno)
{
    if (!cond) {
        return do_fail(lbl, fname, lineno);
    }
    else {
        _Succeed();
        print_progress();
        return true;
    }
}
Exemplo n.º 22
0
static gboolean wait_callback(gpointer user_data)
{
	struct wait_data *wait = user_data;
	struct test_case *test = wait->test;

	wait->seconds--;

	if (wait->seconds > 0) {
		print_progress(test->name, COLOR_BLACK, "%u seconds left",
								wait->seconds);
		return TRUE;
	}

	print_progress(test->name, COLOR_BLACK, "waiting done");

	wait->func(wait->user_data);

	free(wait);

	return FALSE;
}
Exemplo n.º 23
0
static void
cb_success_test (CutRunContext  *run_context,
                 CutTest        *test,
                 CutTestContext *context,
                 CutTestResult  *result,
                 CutConsoleUI   *console)
{
    if (console->verbose_level < CUT_VERBOSE_LEVEL_NORMAL)
        return;
    print_progress(console, CUT_TEST_RESULT_SUCCESS, ".");
    fflush(stdout);
}
Exemplo n.º 24
0
static void od_mask_block(void *_ctx,const unsigned char *_data,int _stride,
 int _bi,int _bj){
#if PRINT_PROGRESS
  if(_bi==0&&_bj==0){
    print_progress(stdout,"od_mask_block");
  }
#endif
  if(_bi==0&&_bj==0){
    intra_stats_ctx *ctx;
    ctx=(intra_stats_ctx *)_ctx;
    image_data_mask(&ctx->img,_data,_stride);
  }
}
Exemplo n.º 25
0
static void
cb_error_test (CutRunContext  *run_context,
               CutTest        *test,
               CutTestContext *test_context,
               CutTestResult  *result,
               CutConsoleUI   *console)
{
    if (console->verbose_level < CUT_VERBOSE_LEVEL_NORMAL)
        return;
    print_progress(console, CUT_TEST_RESULT_ERROR, "E");
    print_progress_in_detail(console, result);
    fflush(stdout);
}
Exemplo n.º 26
0
static void od_print_block(void *_ctx,const unsigned char *_data,int _stride,
 int _bi,int _bj){
  intra_stats_ctx *ctx;
  (void)_data;
  (void)_stride;
#if PRINT_PROGRESS
  if(_bi==0&&_bj==0){
    print_progress(stdout,"od_print_block");
  }
#endif
  ctx=(intra_stats_ctx *)_ctx;
  image_data_print_block(&ctx->img,_bi,_bj,stderr);
}
Exemplo n.º 27
0
static void test_result(enum test_result result)
{
	struct test_case *test;

	if (!test_current)
		return;

	test = test_current->data;

	if (test->stage != TEST_STAGE_RUN)
		return;

	if (test->timeout_id > 0) {
		g_source_remove(test->timeout_id);
		test->timeout_id = 0;
	}

	test->result = result;
	switch (result) {
	case TEST_RESULT_PASSED:
		print_progress(test->name, COLOR_GREEN, "test passed");
		break;
	case TEST_RESULT_FAILED:
		print_progress(test->name, COLOR_RED, "test failed");
		break;
	case TEST_RESULT_NOT_RUN:
		print_progress(test->name, COLOR_YELLOW, "test not run");
		break;
	case TEST_RESULT_TIMED_OUT:
		print_progress(test->name, COLOR_RED, "test timed out");
		break;
	}

	if (test->teardown_id > 0)
		return;

	test->teardown_id = g_idle_add(teardown_callback, test);
}
Exemplo n.º 28
0
void RandomSampler::sample() {
    crt_cnt = 0;
    
    PPReader& reader = handler->get_reader();
    
    // init stage: just pick up first K samples
    // as samples added, responsibilities should be updated accordingly.
    for (uint i = 0; i < K; i++) {
        point* p = reader.get();
        if (!p) return;     // no more data
        
        sampled.push_back(*p);

        crt_cnt++;
        delete p;
        if (does_print_progress && crt_cnt % 100 == 0) print_progress();
    }
    
    
    // Swap stage: swap with previous elements with a certain probability.
    point *p;
    for (int i = 0; (p = reader.get()); i++) {
        int n = 1;
        int m = i+1;
        int ri = n + rand() % (int) (m - n + 1);
        
        if (ri <= K) {
            sampled[ri-1] = *p;
        }

        
        crt_cnt++;
        delete p;
        if (does_print_progress && crt_cnt % 100 == 0) print_progress();
    }
    
    if (does_print_progress) clear_line();
}
Exemplo n.º 29
0
int main(int argc, char **argv)
{
  int i;
  int deadlock;
  deadlock = 0;

  srand(time(NULL));

  set_table();

  do {
    /*
     * Let the philosophers do some thinking and eating
     */
    sleep(5);

    /*
     * Check for deadlock (i.e. none of the philosophers are
     * making progress)
     */
    deadlock = 0;

    if (check_for_deadlock()) {
      deadlock = 1;
      break;
    }

    /*
     * Print out the philosophers progress
     */
    print_progress();
  } while (!deadlock);

  stop = 1;
  printf ("Reached deadlock\n");

  /*
   * Release all locks so philosophers can exit
   */
  for (i = 0; i < NUM_CHOPS; i++)
    pthread_mutex_unlock(&chopstick[i]);

  /*
   * Wait for philosophers to finish
   */
  for (i = 0; i < NUM_PHILS; i++)
    pthread_join(diners[i].thread, NULL);

  return 0;
}
Exemplo n.º 30
0
Arquivo: sf.c Projeto: heuripedes/sf
static void perform() {

    fd_set fdread, fdwrite, fdexcep;
    int ret;
    int maxfd;
    int connections = 0;

    select_timeout.tv_sec  = 0;
    select_timeout.tv_usec = 50000;

    do {
        do {
            ret = check_multi(curl_multi_perform(curlm, &connections),
                              "curl_multi_perform() failed");
        } while (ret == CURLM_CALL_MULTI_PERFORM);

        if (show_progress) {
            print_progress();
        }

        if (connections) {
            size_t i;

            for (i = 0; i < num_slices; ++i) {
                if (slices[i].finished)
                    slice_finalize(&slices[i]);
            }

            FD_ZERO(&fdread);
            FD_ZERO(&fdwrite);
            FD_ZERO(&fdexcep);

            check_multi(curl_multi_fdset(curlm, &fdread, &fdwrite, &fdexcep, &maxfd),
                        "curl_multi_fdset() failed");

            ret = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &select_timeout);

            if (ret == -1)
                die("select() error: %s\n", strerror(errno));
        }

    } while (connections);

    size_t i;
    for (i = 0; i < num_slices; ++i) {
        if (slices[i].curl)
            slice_finalize(&slices[i]);
    }
}