示例#1
0
/**
 * @brief Free all the data allocated with <code>mps_allocate_data()</code>
 *
 * @param s The <code>mps_context</code> of the computation.
 */
void
mps_free_data (mps_context * s)
{
  int i;

  if (s->debug_level & MPS_DEBUG_MEMORY)
    {
      MPS_DEBUG (s, "Deallocating data");
    }

  if (s->bmpc)
    {
      mpc_vclear (s->bmpc, s->n * s->pool->n);
      free (s->bmpc);
      s->bmpc = NULL;
    }

  mps_clusterization_free (s, s->clusterization);
  free (s->order);

  for (i = 0; i < s->n; i++)
    mps_approximation_free (s, s->root[i]);
  free (s->root);

  for (i = 0; i <= s->deg; i++)
    mpc_clear (s->mfpc1[i]);
  mpc_vfree (s->mfpc1);

  cplx_vfree (s->fppc1);
  for (i = 0; i <= s->deg; i++)
    {
      mpc_clear (s->mfppc1[i]);
    }

  free (s->mfppc1);

  /* free temporary vectors */
  free (s->spar1);
  free (s->h);
  free (s->again_old);

  free (s->oldpunt);
  free (s->clust_aux);
  free (s->punt_aux);
  free (s->punt_out);
  free (s->clust_out);

  free (s->fap1);
  free (s->fap2);

  rdpe_vfree (s->dap1);
  cdpe_vfree (s->dpc1);
  cdpe_vfree (s->dpc2);

  free (s->partitioning);
  free (s->fradii);
  rdpe_vfree (s->dradii);

  mps_thread_pool_free (s, s->pool);
}
示例#2
0
int main (int argc, char ** argv)
{
  mps_context * s = mps_context_new ();
  mps_thread_pool * pool = mps_thread_pool_new (s, 0);
  int i[N_THREADS];
  int j;

  for(j = 0; j < N_THREADS; j++)
    i[j] = j;
  j = 0;

  printf (" => Created a thread pool with %d threads\n", pool->n);

  printf (" => Asking the threads to print an integer (from 0 to %d)...\n", N_THREADS - 1);
  
  for (j = 0; j < N_THREADS; j++)
    mps_thread_pool_assign (s, pool, (mps_thread_work) work, i + j);

  mps_thread_pool_wait (s, pool);
  printf ("\n => All the threads have completed their work\n");

  printf (" => Doing it again (testing re-usability of the thread pool)\n");

  for (j = 0; j < N_THREADS; j++)
    mps_thread_pool_assign (s, pool, (mps_thread_work) work, i + j);

  mps_thread_pool_wait (s, pool);

  printf ("\n => Trying to stop all the threads..."); 
  mps_thread_pool_free (s, pool); 
  printf ("done\n"); 
}
示例#3
0
文件: context.c 项目: akobel/MPSolve
/**
 * @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);
}