MPSolve 3.2.1
Loading...
Searching...
No Matches
context.h
Go to the documentation of this file.
1/*
2 * This file is part of MPSolve 3.2.1
3 *
4 * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa.
5 * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
6 *
7 * Authors:
8 * Leonardo Robol <leonardo.robol@unipi.it>
9 */
10
11#ifndef MPS_CONTEXT_H
12#define MPS_CONTEXT_H
13
14#include <mps/mps.h>
15#include <pthread.h>
16
17#ifdef __cplusplus
18extern "C"
19{
20#endif
21
32typedef void (*mps_mpsolve_ptr)(mps_context *status);
33
37typedef void* (*mps_callback)(mps_context * status, void * user_data);
38
39
40/*
41 * Macros for casting user functions
42 */
43#define MPS_FNEWTON_PTR(x) (mps_fnewton_ptr) & (x)
44#define MPS_DNEWTON_PTR(x) (mps_dnewton_ptr) & (x)
45#define MPS_MNEWTON_PTR(x) (mps_mnewton_ptr) & (x)
46#define MPS_CHECK_DATA_PTR(x) (mps_check_data_ptr) & (x)
47#define MPS_FSTART_PTR(x) (mps_fstart_ptr) & (x)
48#define MPS_DSTART_PTR(x) (mps_dstart_ptr) & (x)
49#define MPS_MPSOLVE_PTR(x) (mps_mpsolve_ptr) & (x)
50
51#ifdef _MPS_PRIVATE
59 mps_boolean error_state;
60
64 char * last_error;
65
74
80 mps_boolean resume;
81
88 mps_boolean chkrad;
89
95
99 void * user_data;
100
105 mps_operation operation;
106
112 mps_boolean initialized;
113
117 mps_debug_level debug_level;
118
122 mps_boolean over_max;
123
128
133
138
143
144 /*
145 * INPUT / OUTPUT STREAMS
146 */
147
154 mps_boolean DOLOG;
155
159 mps_boolean DOWARN;
160
165 mps_boolean DOSORT;
166
170 FILE *instr;
171
175 FILE *outstr;
176
180 FILE *logstr;
181
186 FILE *rtstr;
187
188 /*
189 * CONSTANT, PARAMETERS
190 */
191
196
201
207
212 long int mpwp_max;
213
218
223 pthread_mutex_t precision_mutex;
224
230
235 mps_boolean random_seed;
236
237 /*
238 * POLYNOMIAL DATA: SHARED VARIABLES
239 */
240
244 int n;
245
249 int deg;
250
251 /* Solution related variables */
252
256 mps_phase lastphase;
257
262 mps_phase starting_case;
263
268 mps_boolean best_approx;
269
277
281 int count[3];
282
287
291 int *order;
292
298
303 mps_boolean skip_float;
304
308 rdpe_t eps_in;
309
313 rdpe_t eps_out;
314
319
323 long int mpwp;
324
329
333 double sep;
334
345
352 cplx_t *fppc1;
353
360 cdpe_t *dpc1;
361
368 cdpe_t *dpc2;
369
376 mpc_t *mfpc1;
377
385 mpc_t *mfppc1;
386
395 mps_boolean *spar1;
396
403
413 double *fap1;
414
426 double *fap2;
427
437 rdpe_t *dap1;
438
445 mps_boolean *again_old;
446
447 /* SECTION -- Algorihtm selection */
448
453 mps_algorithm algorithm;
454
458 mps_starting_strategy starting_strategy;
459
464 void (*mpsolve_ptr)(mps_context *status);
465
470
475
480
485
490 mpc_t * bmpc;
491
496 mps_boolean jacobi_iterations;
497
501 const char * gnuplot_format;
502
503 /* DEBUG SECTIONS */
504
505 unsigned long int regeneration_time;
506 unsigned long int mp_iteration_time;
507 unsigned long int dpe_iteration_time;
508 unsigned long int fp_iteration_time;
509
510 mps_boolean exit_required;
511
512 long int minimum_gmp_precision;
513
522
532
539
540}; /* End of typedef struct { ... */
541
542#endif /* #ifdef _MPS_PRIVATE */
543
544/* Allocator, deallocator, constructors.. */
547
548/* Accessor functions (setters) */
549void mps_context_abort (mps_context * s);
550int mps_context_set_poly_d (mps_context * s, cplx_t * coeff,
551 long unsigned int n);
553int mps_context_set_poly_i (mps_context * s, int *coeff, long unsigned int n);
554void mps_context_select_algorithm (mps_context * s, mps_algorithm algorithm);
555void mps_context_set_degree (mps_context * s, int n);
556
557#ifdef _MPS_PRIVATE
558void mps_context_allocate_poly_inplace (mps_context * s, int n);
559#endif
560
561/* Accessor functions */
562long int mps_context_get_data_prec_max (mps_context * s);
563long int mps_context_get_minimum_precision (mps_context * s);
564int mps_context_get_degree (mps_context * s);
565int mps_context_get_roots_d (mps_context * s, cplx_t ** roots, double **radius);
566int mps_context_get_roots_m (mps_context * s, mpc_t ** roots, rdpe_t ** radius);
568mps_root_status mps_context_get_root_status (mps_context * ctx, int i);
569mps_boolean mps_context_get_over_max (mps_context * s);
572
573/* I/O options and flags */
574void mps_context_set_input_prec (mps_context * s, long int prec);
575void mps_context_set_output_prec (mps_context * s, long int prec);
576void mps_context_set_output_format (mps_context * s, mps_output_format format);
577void mps_context_set_output_goal (mps_context * s, mps_output_goal goal);
578void mps_context_set_starting_phase (mps_context * s, mps_phase phase);
579void mps_context_set_log_stream (mps_context * s, FILE * logstr);
580void mps_context_set_jacobi_iterations (mps_context * s, mps_boolean jacobi_iterations);
581void mps_context_select_starting_strategy (mps_context * s, mps_starting_strategy strategy);
582void mps_context_set_avoid_multiprecision (mps_context * s, mps_boolean avoid_multiprecision);
583void mps_context_set_crude_approximation_mode (mps_context * s, mps_boolean crude_approximation_mode);
585
586/* Debugging */
587void mps_context_set_debug_level (mps_context * s, mps_debug_level level);
588void mps_context_add_debug_domain (mps_context * s, mps_debug_level level);
589
590/* Get input and output config pointers */
593
594/* Error handling */
595mps_boolean mps_context_has_errors (mps_context * s);
597
598
599#ifdef __cplusplus
600}
601#endif
602
603#endif
int mps_context_set_poly_d(mps_context *s, cplx_t *coeff, long unsigned int n)
Set active polynomial as a real floating point coefficient polynomial of degree n with coefficient ex...
Definition: context.c:403
int mps_context_set_poly_i(mps_context *s, int *coeff, long unsigned int n)
Set active polynomial as a integer coefficient polynomial of degree n with coefficient exactly determ...
Definition: context.c:433
char * mps_context_error_msg(mps_context *s)
Return a copy of the string describing the error msg, or NULL if no error has been encountered.
Definition: context.c:821
int mps_context_get_roots_d(mps_context *s, cplx_t **roots, double **radius)
Set roots[i] to the i-th root of the polynomial and (if it is not NULL) radius[i] to the i-th inclusi...
Definition: context.c:466
mps_input_configuration * mps_context_get_input_config(mps_context *s)
Get a pointer to the input config stored in the given mps_context.
Definition: context.c:733
int mps_context_get_roots_m(mps_context *s, mpc_t **roots, rdpe_t **radius)
Get the roots computed as multiprecision complex numbers.
Definition: context.c:518
mps_root_status mps_context_get_root_status(mps_context *ctx, int i)
Retrieve the status of the root in position i.
Definition: context.c:850
void mps_context_set_output_prec(mps_context *s, long int prec)
Set the output precision for the roots.
Definition: context.c:624
void mps_context_set_starting_phase(mps_context *s, mps_phase phase)
Set the phase from which the computation should start.
Definition: context.c:771
void mps_context_set_crude_approximation_mode(mps_context *s, mps_boolean crude_approximation_mode)
Enable the "crude" only approximation mode of MPSolve.
Definition: context.c:881
void mps_context_select_algorithm(mps_context *s, mps_algorithm algorithm)
Select algorithm to use for computation.
Definition: context.c:56
void mps_context_select_starting_strategy(mps_context *s, mps_starting_strategy strategy)
Select the starting strategy used to dispose the initial approximations.
Definition: context.c:77
mps_approximation ** mps_context_get_approximations(mps_context *ctx)
Retrieve a pointer to the current approximations in the context.
Definition: context.c:566
void mps_context_set_debug_level(mps_context *s, mps_debug_level level)
Set the debug level in MPSolve.
Definition: context.c:702
void *(* mps_callback)(mps_context *status, void *user_data)
Pointer to the callback for the async version of mpsolve.
Definition: context.h:37
void mps_context_set_log_stream(mps_context *s, FILE *logstr)
Set logstr as the default output for logging.
Definition: context.c:758
int mps_context_get_zero_roots(mps_context *s)
Get the number of zero roots in the output. Must be called after mps_mpsolve() has complete.
Definition: context.c:783
mps_boolean mps_context_has_errors(mps_context *s)
Return true if mpsolve has encountered an error in the computation.
Definition: context.c:808
void mps_context_set_regeneration_driver(mps_context *s, mps_regeneration_driver *rd)
Select the regeneration driver implementation to use.
Definition: context.c:903
void mps_context_set_output_format(mps_context *s, mps_output_format format)
Set the desired output format that will be used when calling mps_output().
Definition: context.c:656
mps_boolean mps_context_get_over_max(mps_context *s)
Return true of the computation has passed the maximum admitted precision, and so was unable to reach ...
Definition: context.c:797
void mps_context_set_jacobi_iterations(mps_context *s, mps_boolean jacobi_iterations)
Set the value of the jacobi iterations switch in the MPSolve context.
Definition: context.c:689
void mps_context_set_input_poly(mps_context *s, mps_polynomial *p)
Set the monomial poly p as the input polynomial for the current equation.
Definition: context.c:345
void mps_context_add_debug_domain(mps_context *s, mps_debug_level level)
Add another debug domain to the ones displayed. This will enable debug if disabled and show message f...
Definition: context.c:721
void mps_context_free(mps_context *s)
Free a not more useful mps_context.
Definition: context.c:157
mps_output_configuration * mps_context_get_output_config(mps_context *s)
Get a pointer to the output config stored in the given mps_context.
Definition: context.c:745
mps_context * mps_context_new(void)
Allocate a new mps_context struct with default options.
Definition: context.c:118
mps_polynomial * mps_context_get_active_poly(mps_context *ctx)
Retrieve a pointer to the active polynomial being solved.
Definition: context.c:835
void(* mps_mpsolve_ptr)(mps_context *status)
Routine that performs the computation loop to solve the polynomial or the secular equation.
Definition: context.h:32
void mps_context_set_avoid_multiprecision(mps_context *s, mps_boolean avoid_multiprecision)
Set the internal flag "avoid_multiprecision" to the specified value.
Definition: context.c:867
void mps_context_set_input_prec(mps_context *s, long int prec)
Set the bits of precision of the input coefficients.
Definition: context.c:640
void mps_context_set_output_goal(mps_context *s, mps_output_goal goal)
Set the output goal for the computation.
Definition: context.c:674
Header file for libmps.
Definition: approximation.h:24
A list of mps_cluster.
Definition: cluster.h:100
this struct holds the state of the mps computation
Definition: context.h:55
rdpe_t eps_in
Input precision of the coefficients.
Definition: context.h:308
mps_boolean crude_approximation_mode
This flags enables the "crude" only approximation mode of MPSolve.
Definition: context.h:531
int max_pack
number of max packets of iterations
Definition: context.h:195
void * user_data
Pointer to user_data passed to the callback.
Definition: context.h:99
mps_boolean best_approx
Set to true if the approximation are the best that can be obtained with the current precision.
Definition: context.h:268
mps_phase starting_case
Selected starting case, can be 'd' for DPE or 'f' for floating point.
Definition: context.h:262
mps_boolean avoid_multiprecision
In case this field is set to true MPSolve will avoid a multiprecision phase, and exit instead.
Definition: context.h:521
mps_boolean over_max
True if the computation has reached the maximum allowed precision.
Definition: context.h:122
mps_output_configuration * output_config
Output configuration for MPSolve.
Definition: context.h:132
mps_boolean chkrad
True if check of radius should be performed at the end of the algorithm.
Definition: context.h:88
mps_boolean * again_old
Temporary vector containing the old value of again.
Definition: context.h:445
mpc_t * mfpc1
Multiprecision complex coefficients of the polynomial.
Definition: context.h:376
double sep
Log of the lower bound to the minumum distance of the roots.
Definition: context.h:333
mps_phase lastphase
Last computing phase.
Definition: context.h:256
int newtis
Newton isolation of the cluster.
Definition: context.h:137
const char * gnuplot_format
Char to be intersted after the with statement in the output piped to gnuplot.
Definition: context.h:501
mps_debug_level debug_level
Bytes containing the flags of debug enabled.
Definition: context.h:117
FILE * logstr
Default log stream.
Definition: context.h:180
double * fap1
Vector containing the moduli of the coefficients of the polynomial as floating point numbers.
Definition: context.h:413
mps_boolean just_raised_precision
True if this is the first iteration after the precision has been raised.
Definition: context.h:229
cdpe_t * dpc1
dpe complex coefficients of the polynomial.
Definition: context.h:360
FILE * outstr
Default output stream.
Definition: context.h:175
mps_starting_strategy starting_strategy
Strategy used to dispose the starting approximations.
Definition: context.h:458
mps_long_int_mt data_prec_max
Maximum precision reached during the computation.
Definition: context.h:217
mps_boolean initialized
This value is true if the data for the computation has been allocated by calling mps_allocate_data()....
Definition: context.h:112
mps_secular_equation * secular_equation
Pointer to the secular equation used in computations.
Definition: context.h:474
mps_input_configuration * input_config
Configuration of the input of MPSolve.
Definition: context.h:127
rdpe_t eps_out
Output precision of the roots.
Definition: context.h:313
mpc_t * mfppc1
Multiprecision complex coefficients of the first derivative of the polynomial.
Definition: context.h:385
int deg
input degree and allocation size.
Definition: context.h:249
long int mpwp
Bits of working precision that mpsolve is using.
Definition: context.h:323
FILE * instr
Default input stream.
Definition: context.h:170
mps_callback callback
Callback called when the async version of mps_mpsolve(), i.e. terminate the computation.
Definition: context.h:94
double * fap2
Vector containing the logarithm of the moduli of the coefficients of the polynomial as floating point...
Definition: context.h:426
mps_regeneration_driver * regeneration_driver
This is a pointer to the regeneration driver that performs the standard regeneration step....
Definition: context.h:538
cplx_t * fppc1
Standard complex coefficients of the polynomial.
Definition: context.h:352
mps_approximation ** root
Vector of points to the current root approximations.
Definition: context.h:297
int newtis_old
Old value for the newton isolation of the cluster.
Definition: context.h:142
mps_boolean skip_float
true if the float phase should be skipped, passing directly do dpe phase.
Definition: context.h:303
pthread_mutex_t precision_mutex
Precision operation give best results when done one thread at a time :)
Definition: context.h:223
char * last_error
The text describing the last error occurred.
Definition: context.h:64
mps_boolean jacobi_iterations
True if Jacobi-style iterations must be used in the secular algorithm.
Definition: context.h:496
mps_boolean random_seed
mps_boolean value that determine if we should use a random seed for starting points
Definition: context.h:235
int max_it
number of max iterations per packet
Definition: context.h:200
cdpe_t * dpc2
dpe complex coefficients of the polynomial.
Definition: context.h:368
mps_clusterization * clusterization
Clusterization object that represent the clusterization detected on the roots.
Definition: context.h:344
mps_boolean DOWARN
true if warning are needed.
Definition: context.h:159
mps_boolean * spar1
Vector representing sparsity of the polynomial in the same way that spar does.
Definition: context.h:395
void(* mpsolve_ptr)(mps_context *status)
Routine that performs the loop needed to coordinate root finding. It has to be called to do the hard ...
Definition: context.h:464
mps_boolean error_state
true if an error has occurred during the computation.
Definition: context.h:59
long int mpwp_max
Maximum allowed number of bits for mp numbers: used in high precision shift.
Definition: context.h:212
mps_boolean DOSORT
true if root sorting is desired. It will be performed with routines in mps_sort.c.
Definition: context.h:165
mps_boolean DOLOG
true if log are needed. They will be written to logstr
Definition: context.h:154
mps_operation operation
The operation running now. Can be used to debug what's happening event if mpsolve was launched withou...
Definition: context.h:105
rdpe_t * dap1
Vector containing the moduli of the coefficients of the polynomial as dpe numbers.
Definition: context.h:437
FILE * rtstr
Stream used to resume an interrupted computation or to load the approximations from a custom file.
Definition: context.h:186
mps_boolean resume
true if we are trying to resume previously interrupted.
Definition: context.h:80
int * order
Output index order.
Definition: context.h:291
mps_polynomial * active_poly
This is the polynomial that is currently being solved in MPSolve.
Definition: context.h:469
int * oldpunt
Old value of punt (temporary vector).
Definition: context.h:402
int count[3]
Vector containing count of in, out and uncertaing roots.
Definition: context.h:281
mps_thread_pool * self_thread_pool
This value is non NULL if mpsolve is launched via mps_mpsolve_async() and in that case holds a pointe...
Definition: context.h:73
int n
degree of zero-deflated polynomial.
Definition: context.h:244
mps_thread_pool * pool
The thread pool used for the concurrent part of MPSolve.
Definition: context.h:484
rdpe_t mp_epsilon
Current multiprecision epsilon.
Definition: context.h:328
mps_algorithm algorithm
This is used in the program to switch behavious based on the algorithm that is been used now.
Definition: context.h:453
mpc_t * bmpc
Auxiliary memory used in regeneation to avoid thread-safeness issues.
Definition: context.h:490
int n_threads
Number of threads to be spawned.
Definition: context.h:479
int max_newt_it
Number of max newton iterations for gravity center computations.
Definition: context.h:206
double lmax_coeff
Logarithm of the max modulus of the coefficients.
Definition: context.h:318
int zero_roots
Number of zero roots.
Definition: context.h:286
double last_sigma
shift in the angle in the positioning of the starting approximation for the last cluster....
Definition: context.h:276
Configuration for an input stream; this struct contains the information on how the input stream shoul...
Definition: options.h:151
A thread safe version of mps_boolean.
Definition: mt-types.h:46
Configuration for the output.
Definition: options.h:174
Struct that represents an abstract polynomial. All the other real polynomial implementations (such as...
Definition: polynomial.h:111
This type represent an abstract implementation of a driver for the regeneration step of the main algo...
Definition: regeneration-driver.h:31
Secular equation data.
Definition: secular-equation.h:63
A thread pool that contains a set of mps_thread and allow to manage them as a set of worker.
Definition: threading.h:303