<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Optimisation on Wonderings of a SAT geek</title>
    <link>https://www.msoos.org/tags/optimisation/</link>
    <description>Recent content in Optimisation on Wonderings of a SAT geek</description>
    <generator>Hugo</generator>
    <language>en-US</language>
    <lastBuildDate>Sun, 16 Nov 2014 17:46:28 +0000</lastBuildDate>
    <atom:link href="https://www.msoos.org/tags/optimisation/feed.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Faster cleaning of the learnt clause database</title>
      <link>https://www.msoos.org/2014/11/cleaning-the-learnt-clause-database-faster/</link>
      <pubDate>Sun, 16 Nov 2014 17:46:28 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/?p=2674</guid> 
      <description>&lt;p&gt;In SAT solvers, removing unneeded learnt clauses from the clause database sounds like a trivial task: we somehow determine which clauses are not needed and we call remove() on them. However, in case performance is an issue, it can get a bit more more complicated.&lt;/p&gt;
&lt;h3 id=&#34;the-problem&#34;&gt;The problem&lt;/h3&gt;
&lt;p&gt;The issue at hand is that clauses are stored in two places: as a list of pointers to the clauses and in a list of lists called the watchlist. Removing clauses from either list can be an &lt;span class=&#34;katex&#34;&gt;&lt;span class=&#34;katex-mathml&#34;&gt;&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&#34;false&#34;&gt;(&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mo stretchy=&#34;false&#34;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&#34;application/x-tex&#34;&gt;O(n^2)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&#34;katex-html&#34; aria-hidden=&#34;true&#34;&gt;&lt;span class=&#34;katex-base&#34;&gt;&lt;span class=&#34;katex-strut&#34; style=&#34;height:1.0641em;vertical-align:-0.25em;&#34;&gt;&lt;/span&gt;&lt;span class=&#34;mord mathnormal&#34; style=&#34;margin-right:0.0278em;&#34;&gt;O&lt;/span&gt;&lt;span class=&#34;mopen&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mord&#34;&gt;&lt;span class=&#34;mord mathnormal&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;msupsub&#34;&gt;&lt;span class=&#34;vlist-t&#34;&gt;&lt;span class=&#34;vlist-r&#34;&gt;&lt;span class=&#34;vlist&#34; style=&#34;height:0.8141em;&#34;&gt;&lt;span style=&#34;top:-3.063em;margin-right:0.05em;&#34;&gt;&lt;span class=&#34;pstrut&#34; style=&#34;height:2.7em;&#34;&gt;&lt;/span&gt;&lt;span class=&#34;katex-sizing reset-size6 size3 mtight&#34;&gt;&lt;span class=&#34;mord mtight&#34;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;mclose&#34;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; operation if we e.g. remove every element from the list, one by one. In fact, an old version of the most popular SAT solver, &lt;a href=&#34;http://minisat.se/downloads/minisat2-070721.zip&#34;&gt;MiniSat2&lt;/a&gt;, used to do exactly this:&lt;/p&gt;</description>
    </item>
    <item>
      <title>On using less memory for binary clauses in lingeling&#39;s watchlists</title>
      <link>https://www.msoos.org/2014/08/on-using-less-memory-for-binary-clauses-in-lingeling/</link>
      <pubDate>Mon, 18 Aug 2014 18:28:06 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/?p=2592</guid> 
      <description>&lt;p&gt;&lt;a href=&#34;http://fmv.jku.at/biere/&#34;&gt;Armin Biere&lt;/a&gt; gave a lecture at the &lt;a href=&#34;http://www.pragmaticsofsat.org/2014/&#34;&gt;Pragmatics of SAT workshop&lt;/a&gt; (proceeedings &lt;a href=&#34;http://www.easychair.org/publications/?page=624307&#34;&gt;here&lt;/a&gt;) in Vienna about all the things inside &lt;a href=&#34;http://fmv.jku.at/lingeling/&#34;&gt;lingeling&lt;/a&gt; which won a lot of awards[ &lt;a href=&#34;http://satcompetition.org/2014/SAT-COMP.pdf&#34;&gt;PDF&lt;/a&gt;] this year. If you weren&amp;rsquo;t there, you missed an amazing presentation. In this blog post I&amp;rsquo;ll reflect on a particular part of the presentation dealing with a memory trickery that has been intriguing me for a long while but I did not implement. Before I begin let me say: the presentation was awesome, and it&amp;rsquo;s not by chance that lingeling won so many awards.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Why it&#39;s hard to eliminate variables</title>
      <link>https://www.msoos.org/2014/04/why-its-hard-to-eliminate-variables/</link>
      <pubDate>Wed, 16 Apr 2014 15:39:47 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/?p=2434</guid> 
      <description>&lt;p&gt;Let&amp;rsquo;s examine why it&amp;rsquo;s hard to eliminate variables. I remember the code I looked at in &lt;a href=&#34;http://minisat.se/SatELite.html&#34;&gt;SatElite&lt;/a&gt; that did it: it was crazy clean code and looked like it was pretty easy to perform. In this post I&amp;rsquo;ll examine how that simple code became more than a 1&#39;000 lines of code today.&lt;/p&gt;
&lt;h3 id=&#34;what-needs-to-be-done-at-first-sight&#34;&gt;What needs to be done, at first sight&lt;/h3&gt;
&lt;p&gt;At first sight, variable elimination is easy. We just:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Build occurrence lists&lt;/li&gt;
&lt;li&gt;Pick a variable to eliminate&lt;/li&gt;
&lt;li&gt;Resolve every clause having the positive literal of the variable with negative ones.&lt;/li&gt;
&lt;li&gt;Add newly resolved clauses into the system&lt;/li&gt;
&lt;li&gt;Remove original clauses.&lt;/li&gt;
&lt;li&gt;Goto 2.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These are all pretty simple steps at first sight, and one can imagine that implementing them is maybe 50-100 lines of code, no more. So, let&amp;rsquo;s examine them one-by-one to see how they get complicated.&lt;/p&gt;</description>
    </item>
    <item>
      <title>CryptoMinisat 3.1 released</title>
      <link>https://www.msoos.org/2013/04/cryptominisat-3-1-released/</link>
      <pubDate>Sun, 14 Apr 2013 17:29:50 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/?p=1624</guid> 
      <description>&lt;p&gt;CryptoMinisat 3.1 has been &lt;a href=&#34;https://gforge.inria.fr/frs/?group_id=1992&amp;amp;release_id=8008&#34;&gt;released&lt;/a&gt;. The short changelog is:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ git diff cryptoms-3.0 cryptoms-3.1 --shortstat
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; 84 files changed, 3079 insertions(+), 2751 deletions(-)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The changes made were threefold. First, memory usage has been greatly reduced. This is crucial, because memory usage was over 7GB on certain instances. Secondly, the implication cache wasn&amp;rsquo;t very well-used and an idea that came to my mind &lt;em&gt;greatly&lt;/em&gt; improved performance on most problems. Finally, time limiting of some inprocessing techniques on certain types of problems has been improved.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Implicit binary clauses</title>
      <link>https://www.msoos.org/2010/10/implicit-binary-clauses/</link>
      <pubDate>Wed, 27 Oct 2010 22:14:57 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/?p=508</guid> 
      <description>&lt;p&gt;I have lately been trying to get CryptoMiniSat to use implicit binary clauses. The idea is that since binary clauses are very trivial (just two literals), and they don&amp;rsquo;t really need to keep state (like clause activity), they don&amp;rsquo;t really need to be stored at a separate location. Instead, they can be stored &lt;a href=&#34;https://www.msoos.org/propagating-faster&#34;&gt;directly&lt;/a&gt; in the watchlists. There are a number of advantages and disadvantages that come with this approach.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.msoos.org/wordpress/wp-content/uploads/2010/10/implicit_bin_clauses1.png&#34;&gt;&lt;img loading=&#34;lazy&#34; src=&#34;https://www.msoos.org/wordpress/wp-content/uploads/2010/10/implicit_bin_clauses1.png&#34;&gt;&lt;/a&gt; The main advantage is a notable reduction of memory usage and memory fragmentation. The first is obvious: since we don&amp;rsquo;t allocate space for binary clauses separately, the memory usage of the program should go down. This is especially true since SAT problems usually contain a huge number of binary clauses. The secondary benefit, that of reduced memory fragmentation is not really that much of an advantage if someone uses, e.g. the &lt;a href=&#34;http://www.boost.org/doc/libs/release/libs/pool/doc/&#34;&gt;boost pool&lt;/a&gt; library.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Asymmetric branching</title>
      <link>https://www.msoos.org/2010/07/asymmetric-branching/</link>
      <pubDate>Wed, 28 Jul 2010 11:38:00 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/wordpress/?p=6</guid> 
      <description>&lt;p&gt;Asymmetric branching is an algorithm that shortens CNF clauses in SAT Solvers. A clause, for instance &lt;code&gt;v1 V v2 V v3 V v4&lt;/code&gt; (where letters are binary variables and &lt;code&gt;V&lt;/code&gt; represents binary OR) could possibly be shortened to &lt;code&gt;v1 V v2 V v3&lt;/code&gt;. To find out if it can be, all we have to do is to put &lt;code&gt;-v1,-v2&lt;/code&gt; and &lt;code&gt;-v3&lt;/code&gt; into the propagation queue and then propagate. If we receive a conflict from the propagation engine, we can learn the clause &lt;code&gt;v1 V v2 V v3&lt;/code&gt;, which (incidentally, though this was the point), subsumes the original clause, so we can simply remove variable &lt;code&gt;v4&lt;/code&gt; from the original clause.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Propagating faster</title>
      <link>https://www.msoos.org/2010/07/propagating-faster/</link>
      <pubDate>Mon, 26 Jul 2010 16:13:00 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/wordpress/?p=7</guid> 
      <description>&lt;p&gt;Propagation (BCP) in SAT is the single most expensive operation. The algorithm essentially does the following:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;while (queue_head &amp;lt; trail.size()) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  Literal p = trail[queue_head];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  vector&amp;lt;Watch&amp;gt;&amp;amp; thiswatch = watches[p];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  for (i = thiswatch.begin(); i!=thiswatch[p].end(); i++) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    confl = prop_confl(i-&amp;gt;clause);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    if (confl != NULL) return confl;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  queue_head++;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;where the function &lt;code&gt;prop_confl()&lt;/code&gt; executes the propagation or returns a conflict, if necessary.&lt;/p&gt;
&lt;p&gt;The problem with the above function is that clauses come in all shapes and sizes. In &lt;a href=&#34;http://planete.inrialpes.fr/%7Esoos/CryptoMiniSat2/index.php&#34;&gt;CryptoMiniSat&lt;/a&gt;, there are two kinds of clauses, normal clauses and XOR clauses. Naturally, these need to be handled differently. Furthermore, if the clause&amp;rsquo;s size is small, it is more efficient to handle it differently. The way CryptoMiniSat has done this before was to have a separate &amp;quot; &lt;code&gt;watches&lt;/code&gt;&amp;quot; for each of these. As you can guess, this is very suboptimal.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Optimisations, take two</title>
      <link>https://www.msoos.org/2010/06/optimisations-take-two/</link>
      <pubDate>Sat, 12 Jun 2010 19:50:00 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/wordpress/?p=14</guid> 
      <description>&lt;p&gt;I have talked about &lt;a href=&#34;http://msoos.blogspot.com/2010/04/optimisations.html&#34;&gt;optimisations&lt;/a&gt; before and I mentioned that there are a few left to describe. In this post I will talk about two of them.&lt;/p&gt;
&lt;p&gt;The first optimisation I would like to talk about concerns compilation flags. Somehow, everyone seems obsessed with them, like if they could somehow make a slow program fast. Alas, this is not the case. Firstly, and this is quite funny: the &lt;a href=&#34;http://gcc.gnu.org/&#34;&gt;gcc&lt;/a&gt; flag &amp;ldquo;&lt;a href=&#34;http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html&#34;&gt;-O3&lt;/a&gt;&amp;rdquo; usually turns on all extra flags that people tend to give. One should really ponder upon this when looking at desperate attempts to speed up code. However, there is exactly one flag-combo that is very-very useful besides &amp;ldquo;-O3&amp;rdquo;: it&amp;rsquo;s &amp;ldquo;-fprofile-generate&amp;rdquo; and &amp;ldquo;-fprofile-use&amp;rdquo;. To understand why these are useful, we must first understand that one of the challenges faced by an optimising compiler is to try to guess how many times a loop will be executed,and how many times a branch will be taken. Given a good set of guesses, the loop can be unwound (or not) and the branches can be taken by default (or not). If compiled with &amp;ldquo;-fprofile-generate&amp;rdquo;, the program generates such information on-the-fly, which later can be used by &amp;ldquo;-fprofile-use&amp;rdquo;. The speedup achieved with such an approach in the realms of DPLL-based SAT solvers is relatively high, in the order of ~5-10%. I believe many SAT solvers&amp;rsquo; binaries don&amp;rsquo;t use this trick, even though it&amp;rsquo;s cheap to use. I personally compile with &amp;ldquo;-fprofile-generate&amp;rdquo;, then run an example problem like &lt;a href=&#34;http://www.cril.univ-artois.fr/SAT09/results/bench.php?idev=29&amp;amp;idbench=71050&#34;&gt;UTI-20-10p1&lt;/a&gt; on it, and then recompile with &amp;ldquo;-fprofile-use&amp;rdquo;. An important aspect, by the way, is to execute your problem with a very typical scenario: strange or non-normal scenarios will produce spurious branching and loop data which will actually slow down the program most of the time instead of speeding it up.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Optimisations</title>
      <link>https://www.msoos.org/2010/04/optimisations/</link>
      <pubDate>Thu, 22 Apr 2010 12:10:00 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/wordpress/?p=26</guid> 
      <description>&lt;p&gt;There are plenty of optimisations that I have tried with CryptoMiniSat. I will try to list a few that I finally didn&amp;rsquo;t consider using, but could be implemented later to get around 4-8% speedup each.&lt;/p&gt;
&lt;p&gt;It seems a good idea to use a separate &lt;a href=&#34;http://http://en.wikipedia.org/wiki/Conjunctive_normal_form&#34;&gt;CNF&lt;/a&gt; simplifier such as &lt;a href=&#34;http://http://minisat.se/SatELite.html&#34;&gt;SatELite&lt;/a&gt; before executing the SAT solver. The reasoning is, that even though one can import (or copy-paste) the code from SatELite, the memory will stay fragmented: &lt;a href=&#34;http://minisat.se/downloads/SatELite_slides.pdf&#34;&gt;variable elimination&lt;/a&gt; might remove half the variables, and so the arrays that store variable values will have unused bytes in them, using a larger footprint than necessary, thus causing cache misses. Though this is true, SatELite is not exactly perfect. For instance, it can be seen in certain instances of the SAT Competition of 2009 that &lt;a href=&#34;http://www.lri.fr/%7Esimon/glucose/&#34;&gt;GLUCOSE&lt;/a&gt; sometimes had very bad performance in comparison with other solvers exactly because SatELite took, e.g. &lt;a href=&#34;http://www.cril.univ-artois.fr/SAT09/results/trace.php?idev=29&amp;amp;idjob=1774624&#34;&gt;130 seconds&lt;/a&gt;, but the solving only took 2 seconds. So SatELite slowed down the solving of this instance. Also, SatELite has some limitations, e.g. it cannot handle more than 4&#39;800&#39;000 clauses otherwise it might take just too much time. These are huge drawbacks, and in fact CryptoMiniSat (and, e.g. &lt;a href=&#34;http://fmv.jku.at/precosat/&#34;&gt;PrecoSat&lt;/a&gt;) overcomes all of these. The memory fragmentation issue remains, though. It could be treated, but that would require about 2-3 weeks of time to get corrected, and I simply don&amp;rsquo;t have that much time. P.S.: Easy solution: rename the variables everywhere. Hard (but less error-prone) solution: use different datastructure for variable values.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
