Esempio n. 1
0
int
MPIR_Attr_delete_c_proxy(
    MPI_Comm_delete_attr_function* user_function,
    int handle,
    int keyval,
    MPIR_AttrType attrib_type,
    void* attrib,
    void* extra_state
    )
{
    void *attrib_val = NULL;
    int ret;

    /* Make sure that the attribute value is delieverd as a pointer */
    if (MPIR_ATTR_KIND(attrib_type) == MPIR_ATTR_KIND(MPIR_ATTR_INT))
        attrib_val = &attrib;
    else
        attrib_val = attrib;

    /* user functions might call other MPI functions, so we need to
     * release the lock here. This is safe to do as GLOBAL is not at
     * all recursive in our implementation. */
    MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
    ret = user_function(handle, keyval, attrib_val, extra_state);
    MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);

    return ret;
}
Esempio n. 2
0
static void callback(nmeap_context_t * context, void *data,
                     void *dont_care)
{
    nmeap_rmc_t *rmc = (nmeap_rmc_t *) data;
    user_function(rmc->warn, rmc->time, rmc->latitude, rmc->longitude,
                  rmc->speed, rmc->course);
}
Esempio n. 3
0
int newton_raphson (double estimate, double tolerance, int max_iterations, 
                    int & iterations, double & root, double & value, 
                    char err_string[]) 
{ 
  double deriv;

  for (iterations = 1; iterations <= max_iterations; iterations++)
  {    
    value = user_function(estimate);
    deriv = user_derivative(estimate);
    
    if (fabs(deriv) < 1.0e-10)
    {
      strcpy(err_string, "Slope was zero at some point");
      return 1;
    }
   
    if (fabs(value) <= tolerance)
    { 
      // The root has been found
      root = estimate;
      return 0;
    }
    else
    {
      estimate -= value / deriv;
    }
  }
 
  strcpy(err_string, "Maximum number of iterations was exceeded");
  return 1;
}
Esempio n. 4
0
double trapeze (double lowerx, double upperx, int intervals)
{
  double result, gap, x;
    
  gap    = (upperx - lowerx) / intervals;
  result = user_function(lowerx) + user_function(upperx);
  x      = lowerx + gap;
  
  for (int i = 1; i < intervals; i++)
  {
    result += (2.0 * user_function(x));
    x      += gap;
  }
  
  result *= (gap / 2.0);
  return result;
}
Esempio n. 5
0
void
ASTfunction_call::print (std::ostream &out, int indentlevel) const 
{
    ASTNode::print (out, indentlevel);
#if 0
    if (is_user_function()) { 
        out << "\n";
        user_function()->print (out, indentlevel+1);
        out << "\n";
    }
#endif
}
Esempio n. 6
0
void UI_CHECKBOX::process(int focus)
{
	int OnMe, oldposition;

	if (disabled_flag) {
		position = 0;
		return;
	}

	if (my_wnd->selected_gadget == this)
		focus = 1;

	OnMe = is_mouse_on();

	oldposition = position;

	if ( B1_PRESSED && OnMe ) {
		position = 1;
	} else  {
		position = 0;
	}

	if (my_wnd->keypress == hotkey )	{
		position = 2;
		my_wnd->last_keypress = 0;
	}
		
	if ( focus && ((my_wnd->keypress == KEY_SPACEBAR) || (my_wnd->keypress == KEY_ENTER)) )
		position = 2;

	if (focus)
		if ( (oldposition == 2) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER]) )
			position = 2;

	pressed_down = 0;

	if (position == 0) {
		if ( (oldposition == 1) && OnMe ){
			pressed_down = 1;
		}
		if ( (oldposition == 2) && focus ){
			pressed_down = 1;
		}
	}

	if (pressed_down && user_function )	{
		user_function();
	}

	if (pressed_down)
		flag = !flag;
}
void UI_KEYTRAP::process(int focus)
{
	pressed_down = 0;

	if (disabled_flag) {
		return;
	}

	if (my_wnd->keypress == hotkey)	{
		pressed_down = 1;
		my_wnd->last_keypress = 0;
	}

	if (pressed_down && user_function)	{
		user_function();
	}
}
Esempio n. 8
0
/**
 * Description not yet available.
 * \param
 */
void function_minimizer::pre_user_function(void)
{
  if (lapprox)
  {
    if (lapprox->hesstype==2)
    {
      lapprox->separable_calls_counter=0;
    }
  }
  user_function();
 /*
  if (lapprox)
  {
    if (lapprox->hesstype==2)
    {
      lapprox->nested_shape.trim();
      cout << lapprox->nested_shape;
      lapprox->nested_indices.allocate(lapprox->nested_shape);
      lapprox->separable_calls_counter=0;
      user_function();
    }
  }
 */
}
Esempio n. 9
0
// process() is called to process the button, which amounts to:
//   If mouse is over button, hilight it
//   If highlighted and mouse button down, flag button as down
//   If hotkey pressed, flag button as down
//   If hotkey_if_focus pressed, and button has focus, flag button as down
//   Set various BF_JUST_* flags if events changed from last frame
//
void UI_BUTTON::process(int focus)
{
	int mouse_on_me, old_flags;

	old_flags = m_flags;
	frame_reset();

	// check mouse over control and handle hilighting state
	mouse_on_me = is_mouse_on();

	// if gadget is disabled, force button up and return
	if (disabled_flag) {
		if (old_flags & BF_DOWN){
			m_flags |= BF_JUST_RELEASED;
		}

		if (!hidden && !my_wnd->use_hack_to_get_around_stupid_problem_flag) {
			if (mouse_on_me && B1_JUST_PRESSED){
				gamesnd_play_iface(SND_GENERAL_FAIL);
			}

			if ( (hotkey >= 0) && (my_wnd->keypress == hotkey) ){
				gamesnd_play_iface(SND_GENERAL_FAIL);
			}
		}

		// do callback if the button is disabled
		if (mouse_on_me && B1_JUST_PRESSED){
			if (m_disabled_function != NULL) {
				m_disabled_function();
			}
		}

		return;
	}

	// check focus and derived focus with one variable
	if (my_wnd->selected_gadget == this) {
		focus = 1;
	}

	// show alternate cursor, perhaps?
	maybe_show_custom_cursor();

	if ( !mouse_on_me ) {
		next_repeat = 0;
	} else {
		m_flags |= BF_HIGHLIGHTED;
		if ( !(old_flags & BF_HIGHLIGHTED) ) {
			int do_callback = 1;
			m_flags |= BF_JUST_HIGHLIGHTED;
			// if a callback exists, call it
			if (m_just_highlighted_function) {

				if ( m_flags & BF_SKIP_FIRST_HIGHLIGHT_CALLBACK ) {
					if ( first_callback ) {
						do_callback = 0;
					}
				}

				first_callback = 0;						
				if ( do_callback ) {
					m_just_highlighted_function();
				}
			}
		}
	}

	// check if mouse is pressed
	if ( B1_PRESSED && mouse_on_me )	{
		m_flags |= BF_DOWN;
		capture_mouse();
	}

	// check if hotkey is down or not
	if ( (hotkey >= 0) && (my_wnd->keypress == hotkey) ) {
		m_flags |= BF_DOWN | BF_CLICKED;
	}

	// only check for space/enter keystrokes if we are not ignoring the focus (this is the
	// default behavior)
	if ( !(m_flags & BF_IGNORE_FOCUS) ) {
		if ( focus && (hotkey_if_focus >= 0) ) {
			if (my_wnd->keypress == hotkey_if_focus)
				m_flags |= BF_DOWN | BF_CLICKED;

			if ( (hotkey_if_focus == KEY_SPACEBAR) && (my_wnd->keypress == KEY_ENTER) )
				m_flags |= BF_DOWN | BF_CLICKED;
		}
	}

	// handler for button not down
	if ( !(m_flags & BF_DOWN) ) {
		next_repeat = 0;
		if ( (old_flags & BF_DOWN) && !(old_flags & BF_CLICKED) )  // check for release of mouse, not hotkey
			m_flags |= BF_JUST_RELEASED;

		// non-repeating buttons behave sort of uniquely..  They activate when released over button
		if (!(m_flags & BF_REPEATS)) {
			if ( (m_flags & BF_JUST_RELEASED) && (m_flags & BF_HIGHLIGHTED) )
				m_flags |= BF_CLICKED;
		}

		return;
	}

	// check if button just went down this frame
	if ( !(old_flags & BF_DOWN) ) {
		m_flags |= BF_JUST_PRESSED;
		m_press_linger = timestamp(100);
		if (user_function)
			user_function();

		if (m_flags & BF_REPEATS) {
			next_repeat = timestamp(B_REPEAT_TIME * 3);
			m_flags |= BF_CLICKED;
		}
	}

	// check if a repeat event should occur
	if ( timestamp_elapsed(next_repeat) && (m_flags & BF_REPEATS) ) {
		next_repeat = timestamp(B_REPEAT_TIME);
		m_flags |= BF_CLICKED;
		m_press_linger = timestamp(100);
	}

	// check for double click occurance
	if (B1_DOUBLE_CLICKED && mouse_on_me) {
		m_flags |= BF_DOUBLE_CLICKED;
		m_press_linger = timestamp(100);
	}
}
Esempio n. 10
0
void UI_RADIO::process(int focus)
{
	int OnMe, oldposition;

	if (disabled_flag)	{
		position = 0;
		return;
	}

	if (my_wnd->selected_gadget == this)
		focus = 1;

	OnMe = is_mouse_on();

	oldposition = position;

	if (B1_PRESSED && OnMe) {
		position = 1;
	} else  {
		position = 0;
	}

	if (my_wnd->keypress == hotkey)	{
		position = 2;
		my_wnd->last_keypress = 0;
	}
		
	if ( focus && ((my_wnd->keypress == KEY_SPACEBAR) || (my_wnd->keypress == KEY_ENTER)) )
		position = 2;

	if (focus)
		if ( (oldposition == 2) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER]) )
			position = 2;

	pressed_down = 0;

	if (position) {
		if ( (oldposition == 1) && OnMe )
			pressed_down = 1;
		if ( (oldposition == 2) && focus )
			pressed_down = 1;
	}

	if (pressed_down && user_function) {
		user_function();
	}

	if (pressed_down && (flag == 0)) {
		UI_GADGET *tmp = (UI_GADGET *) next;
		UI_RADIO *tmpr;

		while (tmp != this)	{
			if (tmp->kind == UI_KIND_RADIO) {
				tmpr = (UI_RADIO *) tmp;
				if ((tmpr->group == group) && tmpr->flag) {
					tmpr->flag = 0;
					tmpr->pressed_down = 0;
				}
			}

			tmp = tmp->next;
		}

		flag = 1;
	}
}