22#ifndef MPS_THREADING_H_
23#define MPS_THREADING_H_
25#define MPS_THREAD_JOB_EXCEP -1
26#define MPS_MAX_CORES 8192
28#define mps_with_lock(pmutex, code) { \
29 pthread_mutex_lock (&pmutex); \
31 pthread_mutex_unlock (&pmutex); \
37typedef void * (*mps_thread_work)(
void *);
340 pthread_mutex_t work_completed_mutex;
341 pthread_cond_t work_completed_cond;
358void * mps_thread_mainloop (
void * thread_ptr);
367 unsigned int concurrency_limit);
405#define mps_thread_get_spar2(s, n_thread) (s->spar2 + (s->deg + 2) * (n_thread))
411#define mps_thread_get_mfpc2(s, n_thread) (s->mfpc2 + (s->deg + 1) * (n_thread))
417#define mps_thread_get_dap2(s, n_thread) (s->dap2 + (s->deg + 2) * (n_thread))
Cluster held in a mps_clusterization.
Definition: cluster.h:72
this struct holds the state of the mps computation
Definition: context.h:55
This struct represent a root inside of a mps_cluster.
Definition: cluster.h:30
Struct holding a job queue.
Definition: threading.h:76
mps_root * root
Next root to iterate on.
Definition: threading.h:97
int iter
Iterations that is being performed right now.
Definition: threading.h:92
mps_cluster_item * cluster_item
Element of s->clusterization that we are iterating on.
Definition: threading.h:103
pthread_mutex_t mutex
Internal mutex of the queue used to guarantee exclusive access.
Definition: threading.h:109
unsigned int n_roots
Number of the roots of this problem (i.e. degree of the polynomial).
Definition: threading.h:87
unsigned int max_iter
Maximum number of iteration to perform before raising an exeption.
Definition: threading.h:81
A new job for mps_thread_fsolve(), mps_thread_dsolve() or mps_thread_msolve().
Definition: threading.h:44
int iter
The iteration that will be performed on this root.
Definition: threading.h:53
int i
The index if the root to iterate on.
Definition: threading.h:48
mps_cluster_item * cluster_item
cluster_item The cluster element of s->clusterization that we are iterating on.
Definition: threading.h:59
An item that can be inserted and/or extracted from a mps_thread_pool_queue.
Definition: threading.h:265
mps_thread_pool_queue_item * next
The next item in the queue.
Definition: threading.h:279
mps_thread_work work
The actual job that should be performed.
Definition: threading.h:269
void * args
The args that shall be passed to the work function.
Definition: threading.h:274
A queue of work items that thread can consume.
Definition: threading.h:285
mps_thread_pool_queue_item * last
Pointer to the last item of the queue, or NULL if the queue is empty.
Definition: threading.h:296
mps_thread_pool_queue_item * first
Pointer to the first item of the queue, or NULL if the queue is empty.
Definition: threading.h:290
A thread pool that contains a set of mps_thread and allow to manage them as a set of worker.
Definition: threading.h:303
unsigned int n
The numer of thread in the thread pool.
Definition: threading.h:307
unsigned int concurrency_limit
Limit to the maximum spawnable number of threads. This can be set to 0 that means "No limit"....
Definition: threading.h:318
pthread_mutex_t queue_changed_mutex
Mutex associated to the queue_changed condition.
Definition: threading.h:333
mps_thread * first
A pointer to the first thread in the thread pool.
Definition: threading.h:323
pthread_cond_t queue_changed
Condition that is notified when the queue changes.
Definition: threading.h:338
mps_boolean strict_async
When this vaulue is set to true every call to mps_assign_job returns immediately.
Definition: threading.h:353
mps_thread_pool_queue * queue
Queue of the work that shall be consumed by the threads.
Definition: threading.h:328
Data packed to be passed to a new thread that will perform floating point, dpe or multiprecision iter...
Definition: threading.h:116
int n_threads
The total number of threads.
Definition: threading.h:148
mps_context * s
The pointer to the mps_context struct.
Definition: threading.h:138
pthread_mutex_t * gs_mutex
Global state mute used to synchronize some (hopefully not so many) global operation.
Definition: threading.h:186
mps_thread_job_queue * queue
Pointer to the mps_thread_job_queue that the thread may query for other work.
Definition: threading.h:192
pthread_mutex_t * aberth_mutex
Array of n mutexes where n = s->n, i.e. is the total number of roots of the polynomial.
Definition: threading.h:167
pthread_mutex_t * global_aberth_mutex
Global aberth mutex used to coordinate all aberth computations.
Definition: threading.h:173
int thread
The index of this thread.
Definition: threading.h:143
volatile int * nzeros
Pointer to the integer that holds the number of zeros computed until now.
Definition: threading.h:121
int required_zeros
The number of well approximated roots required to stop iteration packet.
Definition: threading.h:127
pthread_mutex_t * roots_mutex
Array of n mutexes that gets locked when a thread start to iterate over a root. This is done to ensur...
Definition: threading.h:180
volatile int * it
Pointer to the integer that holds the number of iterations performed until now.
Definition: threading.h:133
volatile mps_boolean * excep
Pointer to the boolean excep value. Setting this to true cause the iteration to enter exception state...
Definition: threading.h:157
A thread that is part of a thread pool.
Definition: threading.h:198
pthread_cond_t start_condition
Condition that allow the thread to run. Before the thread finish the busy state (unlocking the busy m...
Definition: threading.h:239
void * args
The argument to be passed to the thread.
Definition: threading.h:258
mps_thread_work work
The routine that must be called when the thread starts.
Definition: threading.h:253
pthread_mutex_t busy_mutex
Busy mutex of the thread. This is locked when the thread is doing something, se we can emulate a join...
Definition: threading.h:231
mps_thread_pool * pool
Pool of which this thread is part.
Definition: threading.h:202
mps_boolean alive
A boolean value that is true if the thread must continue to poll, or false if it is required to exit....
Definition: threading.h:248
mps_thread_worker_data * data
The data assigned to this thread, that sets the worker that he has to do.
Definition: threading.h:219
pthread_t * thread
The pthread_t assigned to the worked.
Definition: threading.h:207
mps_boolean busy
True if the thread is busy.
Definition: threading.h:224
mps_thread * next
The next thread in the pool, or NULL if this is the last thread contained in it.
Definition: threading.h:213
void mps_thread_mpolzer(mps_context *s, int *nit, mps_boolean *excep, int required_zeros)
Drop-in threaded replacement for the stock mpolzer.
Definition: monomial-threading.c:541
void mps_thread_pool_free(mps_context *s, mps_thread_pool *pool)
Free a thread pool and all its threads, waiting for them to terminate.
Definition: threading.c:500
void *(* mps_thread_work)(void *)
A generic routine that can be performed by a mps_thread.
Definition: threading.h:37
void mps_thread_fpolzer(mps_context *s, int *nit, mps_boolean *excep, int required_zeros)
Drop-in replacement for the stock fpolzer routine. This version adds multithread support.
Definition: monomial-threading.c:134
void mps_thread_start_mainloop(mps_context *s, mps_thread *thread)
Start the thread mainloop.
Definition: threading.c:251
mps_thread_job_queue * mps_thread_job_queue_new(mps_context *s)
Create a new mps_thread_job_queue that can handle at most max_iter iterations for n_roots roots.
Definition: threading.c:101
void mps_thread_pool_set_concurrency_limit(mps_context *s, mps_thread_pool *pool, unsigned int concurrency_limit)
Limit the maximum number of threads that can be used in the thread pool.
Definition: threading.c:259
void mps_thread_pool_insert_new_thread(mps_context *s, mps_thread_pool *pool)
Create a new thread and add it to the specified thread pool.
Definition: threading.c:413
void mps_thread_free(mps_context *s, mps_thread *thread)
Free a thread asking it to stop.
Definition: threading.c:388
void mps_thread_pool_wait(mps_context *s, mps_thread_pool *pool)
Wait for a thread pool to complete its jobs.
Definition: threading.c:339
void mps_thread_dpolzer(mps_context *s, int *nit, mps_boolean *excep, int required_zeros)
Multithread version of mps_dpolzer ().
Definition: monomial-threading.c:306
mps_thread * mps_thread_new(mps_context *s, mps_thread_pool *pool)
Allocate a new mps_thread and start its mainloop.
Definition: threading.c:361
int mps_thread_get_core_number(mps_context *s)
Get number of logic cores on the local machine, or 0 if that information is not available with the me...
Definition: threading.c:49
mps_thread_job mps_thread_job_queue_next(mps_context *s, mps_thread_job_queue *q)
Obtain iter and i for the next available job.
Definition: threading.c:134
void mps_thread_pool_set_strict_async(mps_thread_pool *pool, mps_boolean strict_async)
Set the value of the internal field strict_async of the pool.
Definition: threading.c:451
mps_thread_pool * mps_thread_pool_new(mps_context *s, int n_threads)
Allocate a new thread pool and return a pointer to it, with a number of threads suitable for this sys...
Definition: threading.c:461
mps_thread_pool * mps_thread_pool_get_system_pool(mps_context *s)
Obtain a pointer to the default shared thread pool on this system.
Definition: threading.c:430