<!-- HTML header for doxygen 1.8.4-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>Fermat: Sorting</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
    (function(i, s, o, g, r, a, m) {
        i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() {
            (i[r].q = i[r].q || []).push(arguments)
        }, i[r].l = 1 * new Date(); a = s.createElement(o),
  m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
    ga('create', 'UA-47310325-1', 'nvlabs.github.io');
    ga('send', 'pageview');
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Fermat
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="cugar_page.html">CUGAR</a></li><li class="navelem"><a class="el" href="basic_page.html">Basic Module</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Sorting </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><dl class="section user"><dt></dt><dd>The <a class="el" href="structcugar_1_1cuda_1_1_sort_enactor.html">SortEnactor</a> provides a convenient wrapper around the fastest CUDA sorting library available, allowing to perform both key-only and key-value pair sorting of arrays with the following data-types: </dd></dl>
<dl class="section user"><dt></dt><dd><ul>
<li>uint8</li>
<li>uint16</li>
<li>uint32</li>
<li>uint64</li>
<li>(uint8,uint32)</li>
<li>(uint16,uint32)</li>
<li>(uint32,uint32)</li>
<li>(uint64,uint32) </li>
</ul>
</dd></dl>
<dl class="section user"><dt></dt><dd>The way most parallel sorting algorithms work require having a set of ping-pong buffers that are exchanged at every pass through the data. In order to do this, and communicate where the sorted data lies after its work, <a class="el" href="structcugar_1_1cuda_1_1_sort_enactor.html">SortEnactor</a> employs an auxiliary class, <a class="el" href="structcugar_1_1cuda_1_1_sort_buffers.html">SortBuffers</a>. The following example shows their combined usage.</dd></dl>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> sort_test(<span class="keyword">const</span> uint32 n, uint32* h_keys, uint32* h_data)</div><div class="line">{</div><div class="line">    <span class="comment">// allocate twice as much storage as the input to accomodate for ping-pong buffers</span></div><div class="line">    <a class="code" href="structcugar_1_1vector.html">cugar::vector&lt;device_tag,uint32&gt;</a> d_keys( n * 2 );</div><div class="line">    <a class="code" href="structcugar_1_1vector.html">cugar::vector&lt;device_tag,uint32&gt;</a> d_data( n * 2 );</div><div class="line"></div><div class="line">    <span class="comment">// copy the test data to the host</span></div><div class="line">    thrust::copy( h_keys, h_keys + n, d_keys.begin() );</div><div class="line">    thrust::copy( h_data, h_data + n, d_data.begin() );</div><div class="line"></div><div class="line">    <span class="comment">// prepare the sorting buffers</span></div><div class="line">    cuda::SortBuffers&lt;uint32*,uint32*&gt; sort_buffers;</div><div class="line">    sort_buffers.keys[0] = <a class="code" href="namespacecugar.html#a3f6cb2c817f2ba065931cec569aa848b">raw_pointer</a>( d_keys );</div><div class="line">    sort_buffers.keys[1] = <a class="code" href="namespacecugar.html#a3f6cb2c817f2ba065931cec569aa848b">raw_pointer</a>( d_keys ) + n;</div><div class="line">    sort_buffers.data[0] = <a class="code" href="namespacecugar.html#a3f6cb2c817f2ba065931cec569aa848b">raw_pointer</a>( d_data );</div><div class="line">    sort_buffers.data[1] = <a class="code" href="namespacecugar.html#a3f6cb2c817f2ba065931cec569aa848b">raw_pointer</a>( d_data ) + n;</div><div class="line"></div><div class="line">    <span class="comment">// and sort the data</span></div><div class="line">    cuda::SortEnactor sort_enactor;</div><div class="line">    sort_enactor.sort( n, sort_buffers );</div><div class="line"></div><div class="line">    <span class="comment">// the sorted device data is now in here:</span></div><div class="line">    uint32* d_sorted_keys = sort_buffers.current_keys();</div><div class="line">    uint32* d_sorted_data = sort_buffers.current_values();</div><div class="line">    ...</div><div class="line">}</div></div><!-- fragment --> </div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
