<?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>memory layout on Wonderings of a SAT geek</title>
    <link>https://www.msoos.org/tags/memory-layout/</link>
    <description>Recent content in memory layout on Wonderings of a SAT geek</description>
    <generator>Hugo</generator>
    <language>en-US</language>
    <lastBuildDate>Wed, 30 Mar 2016 00:30:12 +0000</lastBuildDate>
    <atom:link href="https://www.msoos.org/tags/memory-layout/feed.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Memory layout of clauses in MiniSat</title>
      <link>https://www.msoos.org/2016/03/memory-layout-of-clauses-in-minisat/</link>
      <pubDate>Wed, 30 Mar 2016 00:30:12 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/?p=2925</guid> 
      <description>&lt;p&gt;I have been trying to debug why some &lt;a href=&#34;https://github.com/niklasso/minisat&#34;&gt;MiniSat&lt;/a&gt;-based solvers perform better at &lt;a href=&#34;https://en.wikipedia.org/wiki/Unit_propagation&#34;&gt;unit propagation&lt;/a&gt; than CryptoMiniSat. It took me exactly 3 full days to find out and I&amp;rsquo;d like to share this tidbit of information with everyone, as I think it might be of interest and I hardly believe many understand it.&lt;/p&gt;
&lt;p&gt;The mystery of the faster unit propagation was that I tried my best to make my solver behave exactly as MiniSat to debug the issue, but even though it was behaving almost identically, it was still slower. It made no sense and I had to dig deeper. You have to understand that both solvers use their own memory managers. In fact, CryptoMiniSat had a memory manager before MiniSat. Memory managers are used so that the clauses are put close to one another so there is a chance that they are in the same memory page, or even better, close enough for them not to waste memory in the cache. This means that a contiguous memory space is reserved where the clauses are placed.&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>On variable renumbering</title>
      <link>https://www.msoos.org/2013/12/on-variable-renumbering/</link>
      <pubDate>Wed, 18 Dec 2013 01:34:15 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/?p=2198</guid> 
      <description>&lt;p&gt;Variable renumbering in SAT solvers keeps a mapping between the external variable numbers that is visible to the users and the internal variable numbers that is visible the to the system. The trivial mapping that most SAT solvers use is the one-to-one mapping where there is no difference between outer and internal variables. A smart mapping doesn&amp;rsquo;t keep track of all data related to variables that have been set or eliminated internally, so the internal datastructures can be smaller.&lt;/p&gt;</description>
    </item>
    <item>
      <title>CryptoMiniSat 3.3 released</title>
      <link>https://www.msoos.org/2013/07/cryptominisat-3-3-released/</link>
      <pubDate>Wed, 10 Jul 2013 18:52:36 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/?p=1812</guid> 
      <description>&lt;p&gt;This is just a short note that CryptoMiniSat 3.3 has been &lt;a href=&#34;https://gforge.inria.fr/frs/?group_id=1992&#34;&gt;released&lt;/a&gt;. This is mainly a bugfix release. I have managed to make a fuzzer that simulates library usage of the system by interspersing the CNF with &amp;ldquo;c Solver::solve()&amp;rdquo; calls and then checking the intermediate solutions. Checking is either performed by verifying that all clauses are satisfied, or if the solution is UNSAT, by using a standard SAT solver (I use &lt;a href=&#34;http://fmv.jku.at/lingeling/&#34;&gt;lingeling&lt;/a&gt;). This turned up a surprising number of bugs. I have also fixed the web-based statistics printing which should now work without a hitch.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Delayed updates</title>
      <link>https://www.msoos.org/2011/02/delayed-updates/</link>
      <pubDate>Sat, 05 Feb 2011 21:38:50 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/?p=652</guid> 
      <description>&lt;p&gt;In this post I will try to explain how &lt;a href=&#34;http://en.wikipedia.org/wiki/Locality_of_reference&#34;&gt;locality of reference&lt;/a&gt; could be exploited by grouping operations that access different memory locations. In the SAT solver program I write, there is a loop that does a something called propagation. The goal of propagation is to set a number of variables to a given value through a pretty cache-intensive process. While doing this, as the variables are set, some statistics are calculated. For example, I used to have something like this called for every variable set:&lt;/p&gt;</description>
    </item>
    <item>
      <title>On the New Watchlist Scheme</title>
      <link>https://www.msoos.org/2011/01/on-the-new-watchlist-scheme/</link>
      <pubDate>Sun, 23 Jan 2011 10:12:24 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/?p=640</guid> 
      <description>&lt;p&gt;All right, so I am not so cool because I work on weekends, but I got &lt;a href=&#34;https://www.msoos.org/changing-the-watchlist-scheme&#34;&gt;this&lt;/a&gt; new watchlist scheme implemented. First off, let me say it was relatively easy to implement, which is a testament to the extensibility of CryptoMiniSat: it only took me ~4 hours to get it done. Secondly, I realised that I have forgotten XOR clauses when I thought through the new scheme. I used to store the current value of the XOR clause at the XOR clause itself (using the sings of the literals, being the hacker I am), and update it at every call to propXorClause(). Since we need to keep XOR clauses static just like normal clauses, this is no longer possible, so a separate data-structure needs to be built up for this. However, it won&amp;rsquo;t need too many updates, so all is fine, but it does make things a tad more complicated.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Changing the Watchlist Scheme</title>
      <link>https://www.msoos.org/2011/01/changing-the-watchlist-scheme/</link>
      <pubDate>Fri, 14 Jan 2011 12:18:59 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/?p=613</guid> 
      <description>&lt;p&gt;Okay, what if we changed the &lt;a href=&#34;http://www.ece.ucsb.edu/bears/class/256bd/RCFB256B3450-Zchoff.pdf&#34;&gt;watchlist scheme&lt;/a&gt;&amp;hellip; a bit? The way the watchlist scheme operates in SAT solvers is the following. We have a set of literals &lt;code&gt;lit1, lit2, lit3, lit4&lt;/code&gt; that defines the clause we want to be watched for propagation and conflict. We take two literals from this set of literals, and put them in a datastructure. It&amp;rsquo;s not important which ones we take, but we have to know which are the ones we took. So, we take the 1st and the 2nd (because we are lazy), and we put them in a set of lists called the watchlists. We now have a pointer to the clause in &lt;code&gt;watchlist[~lit1]&lt;/code&gt; and in &lt;code&gt;watchlist[~lit2]&lt;/code&gt;, where &lt;code&gt;~&lt;/code&gt; is the binary negation. If we now set &lt;code&gt;lit1 = false&lt;/code&gt; we have to have a look at the clauses in &lt;code&gt;watchlist[~lit1]&lt;/code&gt;, see if any of the clauses forces a propagation. If not, then we remove the corresponding &lt;code&gt;lit1&lt;/code&gt; from the watchlist, find another literal that is unset, e.g. &lt;code&gt;lit3&lt;/code&gt;, and put that into the watchlist[~lit3]. It is important that &lt;code&gt;lit3&lt;/code&gt; must not be &lt;code&gt;lit1&lt;/code&gt; or &lt;code&gt;lit2&lt;/code&gt;. Obviously, we know what &lt;code&gt;lit1&lt;/code&gt; is (we are visiting its watchlist, after all), but how could we know what &lt;code&gt;lit2&lt;/code&gt; is? Well, we always update the clause such that &lt;code&gt;lit1&lt;/code&gt; and &lt;code&gt;lit2&lt;/code&gt; are the first two literals. We do this for every clause in every watchlist, and until a conflict is found, or all clauses are satisfied.&lt;/p&gt;</description>
    </item>
    <item>
      <title>How to bit-stuff pointers</title>
      <link>https://www.msoos.org/2010/06/how-to-bit-stuff-pointers/</link>
      <pubDate>Wed, 30 Jun 2010 07:22:00 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/wordpress/?p=12</guid> 
      <description>&lt;p&gt;In my &lt;a href=&#34;?p=13&#34;&gt;last post&lt;/a&gt; I have described a small problem I had regarding a C++ union that had to store a pointer and a value at the same time, plus an indicator that told us which of the two was active:&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;class WhatLeadHere {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;public:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    bool wasPointer;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    union{Clause* pointer; uint32_t lit;};
&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;Martin Maurer has wrote this enlightening email regarding this:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The Clause * pointer is [..] located at least on a 4 byte boundary (at least when not forced by e.g. #pragma). If it is not at least on a 4 byte boundary, CPU must (at least some of them) do two accesses: one lower DWORD, one upper DWORD, and merge both together, which reduces speed.&lt;/p&gt;
&lt;p&gt;So the lower two bits are always zero :-) Why not move the &amp;ldquo;wasPointer&amp;rdquo; to lower two bits (i think you need only one, have one spare bit). Of course before accessing the &amp;ldquo;pointer&amp;rdquo; (Clause *), you must &amp;ldquo;and&amp;rdquo; the two lower bits back to zero.&lt;/p&gt;
&lt;/blockquote&gt;</description>
    </item>
    <item>
      <title>Propagating binary clauses</title>
      <link>https://www.msoos.org/2010/06/propagating-binary-clauses/</link>
      <pubDate>Sun, 27 Jun 2010 17:48:00 +0000</pubDate>
       <guid isPermaLink="false">http://www.msoos.org/wordpress/?p=13</guid> 
      <description>&lt;p&gt;Binary clauses are somewhat special. They are clauses that look like:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;-v1 or v20 = true&lt;/code&gt;&lt;br&gt;
&lt;code&gt;-v1 or v21 = true&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;which basically mean: if &lt;code&gt;v1&lt;/code&gt; is TRUE, then both &lt;code&gt;v20&lt;/code&gt; and &lt;code&gt;v21&lt;/code&gt; must be TRUE. We put these clauses into a special datastructure, that looks like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;watchlist[-v1] = v20,v21, ...&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This makes us all very happy, since this datastructure is very simple: just literals (negated or non-negated variables) one after the other, in a very trivial list. This makes the whole thing very compact, and very efficient.&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>
