1 /*
2  * Normaliz
3  * Copyright (C) 2007-2021  W. Bruns, B. Ichim, Ch. Soeger, U. v. d. Ohe
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  * As an exception, when this program is distributed through (i) the App Store
18  * by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play
19  * by Google Inc., then that store may impose any digital rights management,
20  * device limits and/or redistribution restrictions that are required by its
21  * terms of service.
22  */
23 
24 #include <cstdlib>
25 #include <csignal>
26 
27 #include "libnormaliz/general.h"
28 
29 namespace libnormaliz {
30 
31 bool verbose = false;
32 
33 volatile sig_atomic_t nmz_interrupted = 0;
34 const long default_thread_limit = 8;
35 long thread_limit = default_thread_limit;
36 bool parallelization_set = false;
37 
38 // bool test_arithmetic_overflow = false;
39 // long overflow_test_modulus = 15401;
40 
41 size_t GMP_mat = 0;
42 size_t GMP_hyp = 0;
43 size_t GMP_scal_prod = 0;
44 size_t TotDet = 0;
45 
46 bool int_max_value_dual_long_computed = false;
47 bool int_max_value_dual_long_long_computed = false;
48 bool int_max_value_primary_long_computed = false;
49 bool int_max_value_primary_long_long_computed = false;
50 
51 vector<vector<vector<long> > > CollectedAutoms(default_thread_limit); // for use in nmz_nauty.cpp
52 
53 #ifdef NMZ_EXTENDED_TESTS
54 bool test_arith_overflow_full_cone = false;
55 bool test_arith_overflow_dual_mode = false;
56 bool test_arith_overflow_descent = false;
57 bool test_arith_overflow_proj_and_lift = false;
58 bool test_simplex_parallel = false;
59 bool test_small_pyramids = false;
60 bool test_large_pyramids = false;
61 bool test_linear_algebra_GMP = false;
62 #endif
63 
64 #ifdef NMZ_NAUTY
65 void kill_nauty();
66 #endif
67 
interrupt_signal_handler(int signal)68 void interrupt_signal_handler(int signal) {
69     nmz_interrupted = 1;
70 #ifdef NMZ_NAUTY
71     kill_nauty();
72 #endif
73 }
74 
75 namespace {
76 std::ostream* verbose_ostream_ptr = &std::cout;
77 std::ostream* error_ostream_ptr = &std::cerr;
78 }  // namespace
79 
setVerboseDefault(bool v)80 bool setVerboseDefault(bool v) {
81     // we want to return the old value
82     bool old = verbose;
83     verbose = v;
84     return old;
85 }
86 
set_thread_limit(long t)87 long set_thread_limit(long t) {
88     long old = thread_limit;
89     parallelization_set = true;
90     thread_limit = t;
91     CollectedAutoms.resize(t);
92     return old;
93 }
94 
setVerboseOutput(std::ostream & v_out)95 void setVerboseOutput(std::ostream& v_out) {
96     verbose_ostream_ptr = &v_out;
97 }
98 
setErrorOutput(std::ostream & e_out)99 void setErrorOutput(std::ostream& e_out) {
100     error_ostream_ptr = &e_out;
101 }
102 
verboseOutput()103 std::ostream& verboseOutput() {
104     return *verbose_ostream_ptr;
105 }
106 
errorOutput()107 std::ostream& errorOutput() {
108     return *error_ostream_ptr;
109 }
110 
111 } /* end namespace libnormaliz */
112