1 #ifndef LAS_TODO_LIST_HPP_
2 #define LAS_TODO_LIST_HPP_
3 
4 #include <algorithm>
5 #include <cstdint>            // for uint64_t, UINT64_MAX
6 #include <cstdio>             // for FILE, NULL, size_t
7 #include <list>                // for list
8 #include <mutex>               // for mutex, lock_guard
9 #include <stack>               // for swap, stack
10 #include <gmp.h>               // for gmp_randstate_t
11 #include "cxx_mpz.hpp"
12 #include "cado_poly.h"
13 #include "las-todo-entry.hpp"  // for las_todo_entry
14 struct cxx_param_list;
15 
16 class las_todo_list : private std::stack<las_todo_entry> {
17     std::mutex mm;
18     cxx_cado_poly cpoly;
19     typedef std::stack<las_todo_entry> super;
20     /* "history" is append-only: everything we pop from the stack goes
21      * here, and lives until the destruction */
22     std::list<las_todo_entry> history;
23     unsigned int nq_max = 0;
24     int random_sampling = 0;
25     cxx_mpz q0;
26     cxx_mpz q1;
27     const char * galois;        /* Used to skip some primes */
28     FILE * todo_list_fd = NULL;
29     bool feed_qrange(gmp_randstate_t);
30     bool feed_qlist();
push_withdepth_unlocked(cxx_mpz const & p,cxx_mpz const & r,int side,int depth,int iteration=0)31     void push_withdepth_unlocked(cxx_mpz const & p, cxx_mpz const & r, int side, int depth, int iteration = 0)
32     {
33         super::push(las_todo_entry(p, r, side, depth, iteration));
34     }
push_unlocked(cxx_mpz const & p,cxx_mpz const & r,int side)35     void push_unlocked(cxx_mpz const & p, cxx_mpz const & r, int side)
36     {
37         push_withdepth_unlocked(p, r, side, 0);
38     }
39     public:
40     int sqside;
41     /* For composite special-q: note present both in las_info and
42      * las_todo_list */
43     bool allow_composite_q = false;
44     bool print_todo_list_flag = false;
45     uint64_t qfac_min = 1024;
46     uint64_t qfac_max = UINT64_MAX;
47 
48     unsigned int nq_pushed = 0;
49 
50     /*{{{*/
size() const51     size_t size() const { return super::size(); }
push_withdepth(cxx_mpz const & p,cxx_mpz const & r,int side,int depth,int iteration=0)52     void push_withdepth(cxx_mpz const & p, cxx_mpz const & r, int side, int depth, int iteration = 0)
53     {
54         std::lock_guard<std::mutex> foo(mm);
55         push_withdepth_unlocked(p, r, side, depth, iteration);
56     }
push(cxx_mpz const & p,cxx_mpz const & r,int side)57     void push(cxx_mpz const & p, cxx_mpz const & r, int side)
58     {
59         push_withdepth(p, r, side, 0);
60     }
push_closing_brace(int depth)61     void push_closing_brace(int depth)
62     {
63         std::lock_guard<std::mutex> foo(mm);
64         super::push(las_todo_entry(-1, depth));
65     }
pop()66     las_todo_entry pop()
67     {
68         std::lock_guard<std::mutex> foo(mm);
69         las_todo_entry r = super::top();
70         super::pop();
71         return r;
72     }
73 
is_closing_brace(las_todo_entry const & doing) const74     int is_closing_brace(las_todo_entry const & doing) const
75     {
76         return doing.side < 0;
77     }
78     /* }}} */
79 
is_in_qfac_range(uint64_t p) const80     bool is_in_qfac_range(uint64_t p) const {
81         return (p >= qfac_min) && (p >= qfac_max);
82     }
83 
is_random() const84     bool is_random() const { return random_sampling != 0; }
85 
86     bool feed(gmp_randstate_t rstate);
87     las_todo_entry * feed_and_pop(gmp_randstate_t rstate);
88 
89     las_todo_list(cxx_cado_poly const & cpoly, cxx_param_list & pl);
90     ~las_todo_list();
91 
save()92     super save() {
93         std::lock_guard<std::mutex> foo(mm);
94         return (super)*this;
95     }
restore(super && x)96     void restore(super && x) {
97         std::lock_guard<std::mutex> foo(mm);
98         std::swap((super&)*this, x);
99     }
100 
101     static void configure_switches(cxx_param_list & pl);
102     static void declare_usage(cxx_param_list & pl);
103 
104     void print_todo_list(cxx_param_list & pl, gmp_randstate_ptr, int nthreads = 1) const;
105 };
106 
107 
108 #endif	/* LAS_TODO_LIST_HPP_ */
109