Esempio n. 1
0
		recurse(Config * c, N_INDEX i, N_INDEX j) {
/* Should we change slice ? */
	if (j == 0) {
#if R_OPTIM5
		if (c->cardinal_x[i]+1 < c->cardinal_x[N-1]) {
			update_counter(5);
			return;
		}
#endif
#if R_MAX
		if ((c->cardinal_x[N-1]-1)*i + c->card > R_MAX) {
			return;
		}
#endif
		/* Are we at the end ? */
		if (i == 0) {
			if (c->card > c->best_card) {
				c->update_best();
			}
			update_counter(0);
			return;
		}
		Worker<false, true>::backtrack(c, i-1, N-1);
	} else {
		Worker<false, false>::backtrack(c, i, j-1);
	}
}
Esempio n. 2
0
void h8_timer8_channel_device::set_extra_clock_bit(bool bit)
{
	update_counter();
	extra_clock_bit = bit;
	update_tcr();
	recalc_event();
}
Esempio n. 3
0
static INT_PTR WINAPI warning_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    switch(msg) {
    case WM_INITDIALOG: {
        if(!init_warning_dialog(hwnd, (install_ctx_t*)lparam))
            EndDialog(hwnd, 0);
        return TRUE;
    }
    case WM_COMMAND:
        switch(wparam) {
        case ID_AXINSTALL_INSTALL_BTN: {
            install_ctx_t *ctx = GetPropW(hwnd, ctxW);
            if(ctx)
                ctx->cancel = FALSE;
            EndDialog(hwnd, 0);
            return FALSE;
        }
        case IDCANCEL:
            EndDialog(hwnd, 0);
            return FALSE;
        }
    case WM_TIMER:
        update_counter(GetPropW(hwnd, ctxW), hwnd);
        return TRUE;
    }

    return FALSE;
}
Esempio n. 4
0
static void main_window_load(Window *window) {
  // get information about the Window
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
  
  // set up a black background
  bg_layer = text_layer_create(
    GRect(0, 0, bounds.size.w, bounds.size.h));
  text_layer_set_background_color(bg_layer, GColorBlack);
  layer_add_child(window_layer, text_layer_get_layer(bg_layer));
  
  // set up time display layer
  time_layer = text_layer_create(
      GRect(0, 63, bounds.size.w, 36));
  text_layer_set_background_color(time_layer, GColorClear);
  text_layer_set_text_color(time_layer, GColorWhite);
  text_layer_set_text(time_layer, "00:00");
  text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_LECO_28_LIGHT_NUMBERS));
  text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(time_layer));
  
  // set up counter layer and draw initial ring
  draw_layer = layer_create(GRect(0, 0, 144, 168));
	layer_set_update_proc(draw_layer, updateScreen);
	layer_add_child(window_layer, draw_layer);

  int arc_slices = (int)end_time - (int)start_time;
  counter_config = create_arc_config(arc_slices);
  set_arc_offset(&counter_config, -angle_90);
  update_counter();
}
/**
 * eufi_apply_flatpak_ref_actions:
 * @installation: a #FlatpakInstallation
 * @state_counter_path: (type filename): path to the counter that records what
 *    actions have been applied
 * @actions: (element-type EuuFlatpakRemoteRefAction): actions to apply
 * @mode: the #EosUpdaterInstallerMode
 * @flags: any #EosUpdaterInstallerFlags
 * @error: return location for a #GError, or %NULL
 *
 * Apply the actions @actions, and update the state counter at
 * @state_counter_path to the last successfully applied action. The actions are
 * only actually performed if @mode is set to %EU_INSTALLER_MODE_PERFORM.
 *
 * Returns: %TRUE on success, %FALSE otherwise
 */
gboolean
eufi_apply_flatpak_ref_actions (FlatpakInstallation       *installation,
                                const gchar               *state_counter_path,
                                GPtrArray                 *actions,
                                EosUpdaterInstallerMode    mode,
                                EosUpdaterInstallerFlags   flags,
                                GError                   **error)
{
  gsize i;
  g_autoptr(GHashTable) new_progresses = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);

  g_return_val_if_fail (FLATPAK_IS_INSTALLATION (installation), FALSE);
  g_return_val_if_fail (state_counter_path != NULL, FALSE);
  g_return_val_if_fail (actions != NULL, FALSE);
  g_return_val_if_fail (mode != EU_INSTALLER_MODE_CHECK, FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  for (i = 0; i < actions->len; ++i)
    {
      EuuFlatpakRemoteRefAction *pending_action = g_ptr_array_index (actions, i);
      const gchar *source = pending_action->source;
      gboolean is_dependency = (pending_action->flags & EUU_FLATPAK_REMOTE_REF_ACTION_FLAG_IS_DEPENDENCY) != 0;

      /* Dependencies should not be passed through this function - they
       * were meant to be deployed earlier. Uninstall dependencies will
       * be handled implicitly. Allow them if we’re running
       * `eos-updater-flatpak-installer -mode deploy --pull` manually though. */
      g_assert (!is_dependency || flags & EU_INSTALLER_FLAGS_ALSO_PULL);

      /* Only perform actions if we’re in the "perform" mode. Otherwise
       * we just pretend to perform actions and update the counter
       * accordingly */
      if (mode == EU_INSTALLER_MODE_PERFORM &&
          !perform_action (installation, pending_action, flags, error))
        {
          /* If we fail, we should still update the state of the counter
           * to the last successful one before we get out. This is to ensure
           * that we don’t perform the same action again next time. */
          update_counter_complain_on_error (source,
                                            state_counter_path,
                                            new_progresses);
          return FALSE;
        }

      g_hash_table_replace (new_progresses,
                            (gpointer) source,
                            GINT_TO_POINTER (pending_action->serial));
    }

    /* Once we’re done, update the state of the counter, but bail out
     * if it fails */
    if (!update_counter (state_counter_path,
                         new_progresses,
                         error))
      return FALSE;

  return TRUE;
}
Esempio n. 6
0
uint64_t h8_timer8_channel_device::internal_update(uint64_t current_time)
{
	if(event_time && current_time >= event_time) {
		update_counter(current_time);
		recalc_event(current_time);
	}

	return event_time;
}
Esempio n. 7
0
UINT64 h8_timer8_channel_device::internal_update(UINT64 current_time)
{
	if(event_time && current_time >= event_time) {
		update_counter(current_time);
		if(0)
			logerror("%s: Reached event time (%ld), counter=%02x, dt=%d\n", tag(), long(current_time), tcnt, int(current_time - event_time));
		recalc_event(current_time);
	}

	return event_time;
}
static void
update_counter_complain_on_error (const gchar *failing_name,
                                  const gchar *counter_path,
                                  GHashTable  *new_progresses  /* (element-type filename gint32) */)
{
  g_autoptr(GError) error = NULL;

  if (!update_counter (counter_path, new_progresses, &error))
    complain_about_failure_to_update_system_installation_counter (failing_name,
                                                                  counter_path,
                                                                  error);
}
Esempio n. 9
0
void update_gen(double dataf[], int datai[], int elem_id,int resi, double resf)
{
    int res_into,temp,type_id;
    res_into = datai[elem_id+4];
    temp = (res_into-2)/3;
    if(temp%2==0)
        datai[temp/2]=resi;
    else
        dataf[(temp-1)/2]=resf;
    type_id = datai[elem_id+1];
    switch(type_id){
        case 1: update_rot2d(dataf,datai,(temp-1)/2); break;
        case 2: update_kick2d(dataf,datai); break;
        case 3: update_counter(dataf,datai); break;
    }
    
}
Esempio n. 10
0
void update_gen(double dataf[], int datai[], int elem_id,int resi, double resf)
{
    int res_into,temp,type_id,res_type;
    res_into = datai[elem_id+4];
    res_type = datai[elem_id+5];
    temp = (res_into-2)/3;
    if(temp%2==0)
        datai[temp/2]=resi;
    else
        dataf[(temp-1)/2]=resf;
    switch(res_type)
    {
        case rot2d_TYPE: 
            update_rot2d(dataf,datai,(temp-1)/2); break;
        case kick2d_TYPE: 
            update_kick2d(dataf, datai); break;
        case counter_TYPE:
            update_counter(dataf, datai); break;
    }  
}
Esempio n. 11
0
void AES::srtp_decode(BYTE* src, BYTE* dst, BYTE* key, BYTE* iv, int length){
    LOG_MSG("AES::srtp_decode(%s, %s, %s, %s, %d)",src,dst,key,iv,length);
    BYTE counter[BLOCK_SIZE] = {0};
    memcpy(counter, iv, BLOCK_SIZE);

    unsigned char round_key[ROUND_KEY_SIZE][BLOCK_SIZE];
    expand_key(key,round_key);
    
    int i = 0, j = 0;

    for( ; i < length; i+=BLOCK_SIZE){
        decode_block(counter, dst+i, round_key);
        xor_key(dst+i,dst+i,src+i);
        update_counter(counter);
    }

    BYTE last_block[BLOCK_SIZE];
    decode_block(counter, last_block, round_key);
    for(i=i-BLOCK_SIZE; i < length; i++, j++){
        dst[i] = last_block[j] ^ src[i];
    }
}
Esempio n. 12
0
static BOOL init_warning_dialog(HWND hwnd, install_ctx_t *ctx)
{
    BSTR display_uri;
    HRESULT hres;

    if(!SetPropW(hwnd, ctxW, ctx))
        return FALSE;

    hres = IUri_GetDisplayUri(ctx->uri, &display_uri);
    if(FAILED(hres))
        return FALSE;

    SetDlgItemTextW(hwnd, ID_AXINSTALL_LOCATION, display_uri);
    SysFreeString(display_uri);

    SendDlgItemMessageW(hwnd, ID_AXINSTALL_ICON, STM_SETICON,
            (WPARAM)LoadIconW(0, (const WCHAR*)OIC_WARNING), 0);

    ctx->counter = 4;
    update_counter(ctx, hwnd);
    ctx->timer = SetTimer(hwnd, 1, 1000, NULL);
    return TRUE;
}
Esempio n. 13
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  update_time();

  // todo: update only on day change
  update_counter();
}
Esempio n. 14
0
File: main.c Progetto: alohr/avr
int main(void)
{
    timer tping = { 0, 0 };
    decode_results r;
    state s;
    counter cping;

    memset(&r, 0, sizeof r);
    memset(&s, 0, sizeof s);

    memset(&cping, 0, sizeof cping);

    /*
     * PB0 ir receiver input
     * PB1 servo control out (OC1A)
     * PB2 motor2 enable (OC1B)
     * PB4 ping sensor
     *
     * PD3 motor1 control out A
     * PD4 motor1 control out B
     * PD6 motor2 control out A
     * PD7 motor2 control out B
     */

    DDRB = _BV(PB1) | _BV(PB2);
    PORTB = ~(_BV(PB1) | _BV(PB2) | _BV(PB4));  /* enable pull-ups, leave PB4 alone */

    DDRD = 0xd8;
    PORTD = 0x27; /* enable pull-ups */

    setup_timer0();
    setup_pwm1();
    setup_irrecv();

    for (;;) {
	if (irrecv_decode(&r)) {
	    irinterpret(&s, &r);
	    irrecv_resume();
	}

	// switch motor0 off after a short period of time
	if (s.run0 && millis() - s.timestamp0 > MOTOR0_TIMEOUT_MS)
	    s.run0 = 0;

	set_motor_pins(&s);
	set_servo_pins(&s);

	// ping every 50ms
	if ((tping.t = millis()) - tping.t0 > 50) {
	    tping.t0 = tping.t;

	    unsigned long us = ping(200);
	    if (us != ULONG_MAX) {
		// got a valid reading
 		unsigned long cm = us / ROUNDTRIP_CM_US;
		update_counter(&cping, cm);

		// motor1 running forward?
		if (s.run1 > MOTOR1_MIN) {
		    cm = average_counter(&cping);
		    if (cm < 40) {
			s.run1 = 0;
		    } else {
			int newrun1 = (cm - 40) / 4;
			if (newrun1 < s.run1)
			    if ((s.run1 = newrun1) < MOTOR1_MIN + 2)
				s.run1 = 0;
		    }
		    set_motor_pins(&s);
		}
 	    }
	}

    }

    return 0;
}
Esempio n. 15
0
uint8_t *session_get_outgoing(session_t *session, size_t *length, size_t max_length)
{
  packet_t *packet      = NULL;
  uint8_t  *result      = NULL;
  uint8_t  *data        = NULL;
  size_t    data_length = -1;

  /* Suck in any data we can from the driver. */
  poll_for_data(session);

  /* Don't transmit too quickly without receiving anything. */
  if(!can_i_transmit_yet(session))
    return NULL;

  /* It's pretty ugly, but I don't see any other way, since ping requires
   * special packets we have to handle it separately. */
  if(session->is_ping)
  {
    /* Read data without consuming it (ie, leave it in the buffer till it's ACKed) */
    data = buffer_read_remaining_bytes(session->outgoing_buffer, &data_length, max_length - packet_get_ping_size(), FALSE);
    packet = packet_create_ping(session->id, (char*)data);
    safe_free(data);

    LOG_INFO("In PING, sending a PING packet (%zd bytes of data...)", data_length);
  }
  else
  {
    switch(session->state)
    {
      case SESSION_STATE_NEW:
        LOG_INFO("In SESSION_STATE_NEW, sending a SYN packet (SEQ = 0x%04x)...", session->my_seq);

        packet = packet_create_syn(session->id, session->my_seq, (options_t)0);

        if(session->is_command)
          packet_syn_set_is_command(packet);

        if(session->name)
          packet_syn_set_name(packet, session->name);

        break;

      case SESSION_STATE_ESTABLISHED:
        /* Read data without consuming it (ie, leave it in the buffer till it's ACKed) */
        data = buffer_read_remaining_bytes(session->outgoing_buffer, &data_length, max_length - packet_get_msg_size(session->options), FALSE);
        LOG_INFO("In SESSION_STATE_ESTABLISHED, sending a MSG packet (SEQ = 0x%04x, ACK = 0x%04x, %zd bytes of data...)", session->my_seq, session->their_seq, data_length);

        if(data_length == 0 && session->is_shutdown)
          packet = packet_create_fin(session->id, "Stream closed");
        else
          packet = packet_create_msg_normal(session->id, session->my_seq, session->their_seq, data, data_length);

        safe_free(data);

        break;

      default:
        LOG_FATAL("Wound up in an unknown state: 0x%x", session->state);
        exit(1);
    }
  }

  if(packet)
  {
  /* Print packet data if we're supposed to. */
    if(packet_trace)
    {
      printf("OUTGOING: ");
      packet_print(packet, session->options);
    }

    update_counter(session);
    result = packet_to_bytes(packet, length, session->options);
    packet_destroy(packet);
  }

  return result;
}
Esempio n. 16
0
// START FUNC DECL
int 
approx_frequent (
		 int * x, 
		 char * cfld,
		 long long siz, 
		 long long min_freq, 
		 long long err, 
		 int * y, 
		 int * f, 
		 long long out_siz,
		 long long * ptr_len,
		 int * ptr_estimate_is_good
		 )
// STOP FUNC DECL
//-----------------------------------------------------------------------------
/* README: 

status = approx_frequent(x,cfld,siz,min_freq,err,y,f,out_siz,ptr_len,ptr_estimate_is_good) : The algorithm takes as input an array of integers, and lists out the "frequent" elements in the set approximately, where "frequent" elements are defined as elements occuring greater than or equal to "min_freq" number of times in the input. The approximated output has the following properties: 

(1) all elements in x occuring greater than or equal to min_freq number of times  will definitely be listed in y (THESE ARE THE FREQUENT ELEMENTS (definition) )
(2) their corresponding frequency in f will be greater than or equal to (min_freq-err), i.e., the maximum error in estimating their frequencies is err.
(3) no elements in x occuring less than (min_freq-err) number of times will be listed in y

The approximation is two fold: 
(i) the estimated frequencies of the "frequent" elements can be off by a maximum of err.
(ii) elements occuring between (min_freq-err) and (min_freq) number of times can also be listed in y.


For example: say min_freq = 500 and err = 100.  y will contain the id of all the elements occuring >= 500 definitely, and their corresponding estimated frequency in f would definitely be >= (500-100) = 400. No element in x which occurs less than 400 times will occur in y. Note that elements with frequency between 400 and 500 "can" be listed in y.

Author: Kishore Jaganathan

Algorithm: FREQUENT algorithm (refer to Cormode's paper "Finding Frequent Items in Data Streams")

NOTE: This implementation is a slight variant of the algorithm mentioned in the paper, so that some steps can be parallelized. 

INPUTS: 

x: The input array 

cfld: two options - (1) NULL: All elements of x are processed.
(2) non-NULL: Array of same size as x. Acts as a select vector (only those elements with non-zero values in cfld are processed). ex: If x has 10 elements and cfld is {0,0,1,0,0,0,1,0,1,0}, then only the 3rd, 7th and 9th element are chosen for processing.

siz: Number of elements in the input array x

min_freq: elements occuring greater than or equal to min_freq times in x (among the ones selected for processing) are considered frequent elements. All of their id's will definitely be stored in y.

err: the measured frequencies of the "frequent" elements in x (i.e., occuring >= min_freq times in x, among the ones selected for processing) will definitely be greater than or equal to min_freq-err, and will be stored in f (corresponding to the id stored in y). Also, no element with frequency lesser than (min_freq-err) in x (among the ones selected for processing) will occur in y. Note: Lesser the error, more memory is needed for computation

out_siz: number of integers that can be written in y and f (prealloced memory). See y and f for how much to allocate.


OUTPUTS:

y: array containing the id's of the "frequent" elements. Need to malloc beforehand by atleast (number of elements to be processed)/(min_freq-err) * sizeof(int). If cfld is NULL, number of elements to be processed is siz, else it is equal to the number of non-zero entries in cfld.

f: array containing the corresponding frequencies of the "frequent" elements. Need to malloc beforehand by atleast (number of elements to be processed)/(min_freq-err) * sizeof(int). If cfld is NULL, number of elements to be processed is siz, else it is equal to the number of non-zero entries in cfld.

out_siz: number of integers that can be written in y and f (prealloced memory). See y and f for how much to allocate.

ptr_len: the size of y and f used by the algorithm to write the ids and frequencies of estimated approximate "frequent" elements

ptr_estimate_is_good: pointer to a location which stores 1, -1, -2 or -3
1: approximate calculations were successful, results stored in y,f and ptr_len
-1: something wrong with the input data. Check if sufficient malloc was done beforehand to y and f, in case you forgot.
-2: need too much memory, hence didn't do the calculations. Can retry with one of the following two things : (i) increase MAX_SZ if you are sure you have more RAM available (ii) increase err (the approximation parameter). Increasing err will result in more approximation (hence answer being less accurate) but memory requirements will be lesser.

status: will return 0 or -1
0: two cases - (i) calculations are successful, ptr_estimate_is_good will be set to 1 (ii) need too much memory and hence didn't do the calculations, ptr_estimate_is_good will be set to -2.
-1: Something wrong with inputs, ptr_estimate_is_good will also be set to -1

 */
//-----------------------------------------------------------------------------
{

  int status = 0;

  int flag = 0; /* used to assist freeing mallocs */ 

  *ptr_estimate_is_good = -1; /* default */

  /* Check inputs */
  if ( x == NULL ) { go_BYE(-1); }
  if ( siz <= 0 ) { go_BYE(-1); }
  if ( err <= 0 ) { go_BYE(-1); } 
  if ( min_freq <= 0 ) { go_BYE(-1); }
  if ( min_freq - err <= 0 ) { go_BYE(-1); }
  if ( y == NULL ) { go_BYE(-1); }
  if ( f == NULL ) { go_BYE(-1); }
  if ( ptr_len == NULL ) { go_BYE(-1); }


  long long eff_siz = 0; /* number of entries to be considered */
  if ( cfld == NULL ) { eff_siz = siz; }
  else {

    for ( long long ii = 0; ii < siz; ii++ ) {
      if ( cfld[ii] == 0 ) { continue; }
      eff_siz++;
    }
    if ( eff_siz == 0 ) { go_BYE(-1); } /* cfld has all 0 entries */

  }

  double eps = (double) err/eff_siz; 
  /* parameter of FREQUENT algorithm, decides the error in approximation */
  if ( eps < pow(2,-50) ) { 
    *ptr_estimate_is_good = -2; 
    go_BYE(0); /* need too much memory */
  }

  if ( out_siz < eff_siz/(min_freq - err) ) { 
    *ptr_estimate_is_good = -1;
    go_BYE(-1);
    /* insufficient memory allocated to the outputs y and f */
  }

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

  /* The algorithm will be using (long long)(1/eps)+1 counters: stored in (cntr_id, cntr_freq) */

  int * cntr_id = NULL;
  int * cntr_freq = NULL;
  long long cntr_siz = (long long) (1/eps)+1;

  if ( cntr_siz < 10000 ) { cntr_siz = 10000; } /* can be removed */

  flag = 1; /* defined cntr_id and cntr_freq */

  if ( ( cntr_siz*(1+2+6) ) > MAX_SZ ) {
    *ptr_estimate_is_good = -2;
    go_BYE(0);
    /* Quitting if too much memory needed. Retry by doing one of the following:
       (i) Increase MAX_SZ if you think you have more RAM
       (ii) Increase eps (the approximation percentage) so that computations can be done within RAM
     */
  }
  
  int NUM_THREADS = 128;
  while ( (cntr_siz*(NUM_THREADS+2+6)) > MAX_SZ ) { NUM_THREADS = NUM_THREADS/2; } /* to promote parallel computing when possible, adapting NUM_THREADS to meet memory requirements */
 
  cntr_id = (int *)malloc( cntr_siz * sizeof(int) );
  return_if_malloc_failed(cntr_id);
  cntr_freq = (int *)malloc( cntr_siz * sizeof(int) );
  return_if_malloc_failed(cntr_freq);

  long long active_cntr_siz = 0; /* no of counters with non-zero frequencies */

#ifdef IPP
  ippsZero_32s((int *)cntr_id, cntr_siz);
  ippsZero_32s((int *)cntr_freq, cntr_siz);
#else
  assign_const_I4(cntr_id,cntr_siz,0);
  assign_const_I4(cntr_freq,cntr_siz,0);
#endif

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

  /* We will look at the incoming data as packets of size cntr_siz with sorted data (this would help speed up the update process a lot, this step is not mentioned in the paper - it's my improvization). Since the sorting has to be done within each packet separately, we can parallelize this step as follows: we divide the incoming data into blocks of size  = NUM_THREADS*cntr_siz (so that NUM_THREADS threads can be generated for each block and sorted separately in parallel using cilkfor) */

  /* "inputPacket" is a 2d array of size NUM_THREADS *cntr_siz: stores and sortes packets belonging to the same block in parallel using cilkfor. */

  int ** inputPackets = NULL;
  long long * inputPacketsUsedSiz = NULL;

  flag = 2;  /* inputPackets and inputPacketsUsedSiz are defined */

  inputPackets = malloc ( NUM_THREADS * sizeof(int*) );
  return_if_malloc_failed(inputPackets); 

  inputPacketsUsedSiz = malloc ( NUM_THREADS * sizeof(long long) );
  return_if_malloc_failed(inputPacketsUsedSiz);

  for ( long long ii = 0; ii < NUM_THREADS; ii++) {
    inputPacketsUsedSiz[ii] = 0;
  }

  for ( int ii = 0; ii < NUM_THREADS; ii++ ) {
    inputPackets[ii] =  (int *) malloc( cntr_siz * sizeof(int) );
  }

  flag = 3; /* inputPackets[ii] defined for ii = 0 to NUM_THREADS-1 */

  for ( int ii = 0; ii < NUM_THREADS; ii++ ) {
    return_if_malloc_failed(inputPackets[ii]);
#ifdef IPP
    ippsZero_32s((int *)inputPackets[ii],cntr_siz);
#else
    assign_const_I4(inputPackets[ii],cntr_siz,0);
#endif
  }

  //------------------------------------------------------------------------
  
  int * bf_id = NULL;
  int * bf_freq = NULL; /* temporary counters for processing */

  flag = 4;  /* bf_id and bf_freq are defined */

  bf_id = (int *)malloc( cntr_siz * sizeof(int) );
  return_if_malloc_failed(bf_id);

  bf_freq = (int *)malloc( cntr_siz * sizeof(int) );
  return_if_malloc_failed(bf_freq);

  long long current_loc_in_x = 0; /* start of input data */

  /* Do the following for each block, till you reach the end of input */
  while ( current_loc_in_x < siz ) { 

    /* A block of data ( containing NUM_THREADS packets, i.e NUM_THREADS * cntr_siz integers ) is processed inside this loop. For each packet, the following operations are done: 
     (1): Sort the packet (can be done in parallel using cilkfor)
     (2): Convert each sorted packet into (id, freq) i.e (key, count) format using sorted_array_to_id_freq(). 
     (3): Update the counter array using update_counter()
     
     Steps (1) and (2) can be done in parallel, but for some reason trying to do (2) in parallel is slowing down the code. So doing only (1) in parallel. */

    /* Copying input data into "inputPackets" buffers */

    if ( cfld == NULL || eff_siz == siz ) {

      //------------------------------------------------------------------
      for ( long long ii = 0; ii < NUM_THREADS; ii++) {
	inputPacketsUsedSiz[ii] = 0;
      }

      cilkfor ( int tid = 0; tid < NUM_THREADS; tid++ ) {

	long long lb = current_loc_in_x + tid * cntr_siz; 
	long long ub = lb + cntr_siz;
	if ( lb >= siz ) { continue; }
	if ( ub >= siz ) { ub = siz; }

	memcpy(inputPackets[tid], x+lb, (ub-lb)*sizeof(int));
	inputPacketsUsedSiz[tid] = (ub-lb);

      }

      for ( int tid = 0; tid < NUM_THREADS; tid++ ) {
	current_loc_in_x += inputPacketsUsedSiz[tid];
      }
      //------------------------------------------------------------------

    }
    else {

      //------------------------------------------------------------------
      /* NOTE: if cfld input is non-null, it means we are not interested in all the elements. In every iteration, we keep filling inputPackets buffer with only those data we are interested in using the helper variable "current_loc_in_x". */

      for ( long long ii = 0; ii < NUM_THREADS; ii++) {
	inputPacketsUsedSiz[ii] = 0;
      }
      int tid = 0;
      
      while ( current_loc_in_x < siz  && tid < NUM_THREADS ) {

	if ( cfld[current_loc_in_x] == 0 ) { current_loc_in_x++; }
	else {
	  inputPackets[tid][inputPacketsUsedSiz[tid]] = x[current_loc_in_x];
	  current_loc_in_x++; inputPacketsUsedSiz[tid]++;
	  if ( inputPacketsUsedSiz[tid] == cntr_siz ) { tid++; }
	}

      }
      //------------------------------------------------------------------

    }


    /* Step (1) can be done here in parallel using cilkfor */
    cilkfor ( int tid = 0; tid < NUM_THREADS; tid++ ) {
    
      if ( inputPacketsUsedSiz[tid] == 0 ) { continue; }

#ifdef IPP
      ippsSortAscend_32s_I(inputPackets[tid], inputPacketsUsedSiz[tid]);
#else
      qsort_asc_I4(inputPackets[tid], inputPacketsUsedSiz[tid], sizeof(int), NULL);
#endif

    }

    /* Steps (2) and (3) done here */

    for ( int tid = 0; tid < NUM_THREADS; tid++ ) {
    
      if ( inputPacketsUsedSiz[tid] == 0 ) { break; }
    
      long long bf_siz = 0;
      status = sorted_array_to_id_freq(inputPackets[tid],inputPacketsUsedSiz[tid],bf_id,bf_freq,&bf_siz); cBYE(status);

      status = update_counter(cntr_id,cntr_freq,cntr_siz,&active_cntr_siz,bf_id,bf_freq,bf_siz);
      cBYE(status);

    }


  }
Esempio n. 17
0
//! This function computes the number of files and/or directories in filtered file list
//! This function is not blocking. It will return after \<retry\> iteration if the result
//! is not yet computed.
//!
//! @param      fl_type       FL_ALL  To check all types (files and directories). <br>
//!                           FL_DIR  To check the directory presence. <br>
//!                           FL_FILE To check the file presence.
//!
//! @param      sz_filterext  Extension filter (ASCII format, e.g.: "txt" or "txt,d*,wk" ). <br>
//!                           If this argument in NULL, then it uses the default filter used by the filterlist. <br>
//!                           This argument is also ignored for b_type == FS_DIR.
//! @param      p_total       Pointer to the result which will be updated by the function (added).
//!                           Initialization shall be done before entering into this function.
//! @param      retry         Number of files seen before leaving the function. 0 means that the
//!                           function is blocking until the result is known.
//!
//! @return     number of files and/or directories present in filtered file list.
//!
bool   nav_filterlist_nb_ex( fl_type_t fl_type, const FS_STRING sz_filterext, uint16_t* p_total, uint8_t retry )
{
   static uint16_t   u16_save_position;
   bool   b_is_dir;

   // save current position
   if( *p_total==(uint16_t) -1 )
   {
      u16_save_position = fs_g_nav.u16_pos_filterlist;

      // Reset position
      if ( !nav_filterlist_reset())
         return true;

      if (fl_type == FL_DIR)
        nav_filelist_single_enable(FS_DIR);
      else if (fl_type == FL_FILE)
        nav_filelist_single_enable(FS_FILE);

      *p_total = 0;
   }

   // Scan all
   while( nav_filelist_set( 0, FS_FIND_NEXT ) )
   {
      b_is_dir = nav_file_isdir();

      // Check if its a file for FL_FILE mode
      if (fl_type == FL_FILE && b_is_dir)
      {
        if (!update_counter(&retry))
          return false;
        continue;
      }
      // Check if its a directory for FL_DIR mode
      if (fl_type == FL_DIR && !b_is_dir)
      {
        if (!update_counter(&retry))
          return false;
        continue;
      }
      // If the selection is on a file
      if (!b_is_dir)
      {
        // Check the extension of the file
        if (!((sz_filterext)?nav_file_checkext(sz_filterext):nav_file_checkext(fs_g_nav.sz_filterext)))
          if (!update_counter(&retry))
            return false;
      }

      (*p_total)++;
      if (!update_counter(&retry))
         return false;
   }

   nav_filelist_single_disable();

   // Restore previous position
   if ( u16_save_position != FS_NO_SEL )
   {
      nav_filterlist_reset();
   }else{
      // After operation, there are a file selected
      nav_filterlist_goto( u16_save_position );
   }
   return true;
}