edit
[satlib.git] / glucose-syrup / parallel / ClausesBuffer.h
1 /***************************************************************************************[ClausesBuffer.h]
2  Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon
3                                 CRIL - Univ. Artois, France
4                                 LRI  - Univ. Paris Sud, France (2009-2013)
5                                 Labri - Univ. Bordeaux, France
6
7  Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon
8                                 CRIL - Univ. Artois, France
9                                 Labri - Univ. Bordeaux, France
10
11 Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of
12 Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 
13 is based on. (see below).
14
15 Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel
16 version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software
17 without restriction, including the rights to use, copy, modify, merge, publish, distribute,
18 sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 
19 furnished to do so, subject to the following conditions:
20
21 - The above and below copyrights notices and this permission notice shall be included in all
22 copies or substantial portions of the Software;
23 - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot
24 be used in any competitive event (sat competitions/evaluations) without the express permission of 
25 the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event
26 using Glucose Parallel as an embedded SAT engine (single core or not).
27
28
29 --------------- Original Minisat Copyrights
30
31 Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
32 Copyright (c) 2007-2010, Niklas Sorensson
33
34 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
35 associated documentation files (the "Software"), to deal in the Software without restriction,
36 including without limitation the rights to use, copy, modify, merge, publish, distribute,
37 sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
38 furnished to do so, subject to the following conditions:
39
40 The above copyright notice and this permission notice shall be included in all copies or
41 substantial portions of the Software.
42
43 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
44 NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
45 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
46 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
47 OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48  **************************************************************************************************/
49
50 #ifndef ClausesBuffer_h 
51 #define ClausesBuffer_h
52
53 #include "mtl/Vec.h"
54 #include "core/SolverTypes.h"
55 #include "core/Solver.h"
56
57 //=================================================================================================
58
59 namespace Glucose {
60     // index : size clause
61     // index + 1 : nbSeen
62     // index + 2 : threadId
63     // index + 3 : .. index + 3 + size : Lit of clause
64     class ClausesBuffer {
65         vec<uint32_t>  elems;
66         unsigned int     first;
67         unsigned int     last;
68         unsigned int     maxsize;
69         unsigned int     queuesize; // Number of current elements (must be < maxsize !)
70         unsigned int     removedClauses;
71         unsigned int     forcedRemovedClauses;
72         static const int  headerSize = 3;
73         int       nbThreads;
74         bool      whenFullRemoveOlder;
75         unsigned int fifoSizeByCore;
76         vec<unsigned int> lastOfThread; // Last value for a thread 
77
78         public:
79         ClausesBuffer(int _nbThreads, unsigned int _maxsize);
80         ClausesBuffer();
81
82         void setNbThreads(int _nbThreads);
83         unsigned int nextIndex(unsigned int i);
84         unsigned int addIndex(unsigned int i, unsigned int a); 
85         void removeLastClause(); 
86            
87         void noCheckPush(uint32_t x);
88         uint32_t noCheckPop(unsigned int & index);
89
90         // Return true if the clause was succesfully added
91         bool pushClause(int threadId, Clause & c);
92         bool getClause(int threadId, int & threadOrigin, vec<Lit> & resultClause, bool firstFound = false); 
93         
94         int maxSize() const {return maxsize;}
95         uint32_t getCap();
96         void growTo(int size) {
97             assert(0); // Not implemented (essentially for efficiency reasons)
98             elems.growTo(size); 
99             first=0; maxsize=size; queuesize = 0;last = 0;
100             for(int i=0;i<size;i++) elems[i]=0; 
101         }
102
103         void fastclear() {first = 0; last = 0; queuesize=0; } 
104
105         int  size(void)    { return queuesize; }
106
107         void clear(bool dealloc = false)   { elems.clear(dealloc); first = 0; maxsize=0; queuesize=0;}
108         inline  int  toInt     (Lit p)              { return p.x; } 
109
110     };
111 }
112 //=================================================================================================
113
114 #endif