Пример #1
0
void
mps_context_set_degree (mps_context * s, int n)
{
  if (s->initialized)
    {
      if (s->secular_equation != NULL)
	{
	  mps_secular_equation_free (s, MPS_POLYNOMIAL (s->secular_equation));
	  s->secular_equation = NULL;
	}

      mps_context_resize (s, n);
    }

  s->deg = s->n = n;

  /* Check if the numer of thread is greater of the number of roots,
     and in that case decrease it */
  if (s->n_threads > s->deg)
    {
      MPS_DEBUG_WITH_INFO (s, "Adjusting concurrency limit to %d", s->deg);
      mps_thread_pool_set_concurrency_limit (s, s->pool, s->deg);
    }
  
  /* If a secular equation is present in the old context we should free it
   * now so it will be reallocated on the first call to the algorithm. */
  if (s->secular_equation && MPS_POLYNOMIAL (s->secular_equation)->degree < n)
    mps_secular_equation_free (s, MPS_POLYNOMIAL (s->secular_equation));
  s->secular_equation = NULL;

}
Пример #2
0
/**
 * @brief Free a not more useful mps_context.
 *
 * @param s the mps_context struct pointer to free.
 */
void
mps_context_free (mps_context * s)
{
  if (s->initialized)
    mps_free_data (s);

  free (s->input_config);
  free (s->output_config);

  /* Check if secular equation or monomial poly need to be freed */
  if (s->active_poly != NULL)
    mps_polynomial_free (s, s->active_poly);
  s->active_poly = NULL;

  if (s->secular_equation)
    mps_secular_equation_free (s, MPS_POLYNOMIAL (s->secular_equation));

  /* Close input and output streams if they're not stdin, stdout and
   * stderr */
  if (s->instr != stdin && s->instr != NULL)
    fclose (s->instr);
  if (s->logstr != stderr && s->logstr != stdout && s->logstr != NULL) 
    fclose (s->logstr); 
   
   free (s);
}
Пример #3
0
/**
 * @brief Free a not more useful mps_context.
 *
 * @param s the mps_context struct pointer to free.
 */
void
mps_context_free (mps_context * s)
{
  /* Close input and output streams if they're not stdin, stdout and
   * stderr. For the case in which this context will re-used, set them
   * to their default values. */
  if (s->instr != stdin && s->instr != NULL)
    fclose (s->instr);
  if (s->logstr != stderr && s->logstr != stdout && s->logstr != NULL)
    fclose (s->logstr);

  s->instr = stdin;
  s->logstr = stderr;

  /* There's no need to resize bmpc since they will be allocated on demand.
   * We free them here to correct bad assumptions on the size of this
   * vector. */
  free (s->bmpc);
  s->bmpc = NULL;

  pthread_mutex_lock (&context_factory_mutex);

  if (context_factory_size < MPS_CONTEXT_FACTORY_MAXIMUM_SIZE)
    {
      context_factory = mps_realloc (context_factory,
                                     sizeof(mps_context*) * (context_factory_size + 1));
      context_factory[context_factory_size++] = s;
      pthread_mutex_unlock (&context_factory_mutex);
      return;
    }
  pthread_mutex_unlock (&context_factory_mutex);

  if (s->initialized)
    mps_free_data (s);

  mps_thread_pool_free (s, s->pool);

  free (s->input_config);
  free (s->output_config);

  s->active_poly = NULL;

  if (s->secular_equation)
    mps_secular_equation_free (s, MPS_POLYNOMIAL (s->secular_equation));

  free (s);
}