<!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"/> <title>linbox: examples/dot-product.C</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.4 --> <script type="text/javascript"> function hasClass(ele,cls) { return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')); } function addClass(ele,cls) { if (!this.hasClass(ele,cls)) ele.className += " "+cls; } function removeClass(ele,cls) { if (hasClass(ele,cls)) { var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)'); ele.className=ele.className.replace(reg,' '); } } function toggleVisibility(linkObj) { var base = linkObj.getAttribute('id'); var summary = document.getElementById(base + '-summary'); var content = document.getElementById(base + '-content'); var trigger = document.getElementById(base + '-trigger'); if ( hasClass(linkObj,'closed') ) { summary.style.display = 'none'; content.style.display = 'block'; trigger.src = 'open.png'; removeClass(linkObj,'closed'); addClass(linkObj,'opened'); } else if ( hasClass(linkObj,'opened') ) { summary.style.display = 'block'; content.style.display = 'none'; trigger.src = 'closed.png'; removeClass(linkObj,'opened'); addClass(linkObj,'closed'); } return false; } </script> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">linbox</div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> </div> <div class="header"> <div class="headertitle"> <div class="title">examples/dot-product.C</div> </div> </div> <div class="contents"> <p>Timings on dot products of random vectors. </p> <dl class="author"><dt><b>Author:</b></dt><dd>Bradford Hovinen <<a href="mailto:hovinen@cis.udel.edu">hovinen@cis.udel.edu</a>></dd></dl> <p>Use of vectors meeting the <a class="el" href="namespace_lin_box.html" title="Namespace in which all linbox code resides.">LinBox</a> dense and sparse vector archetypes is illustrated and their dot-product times are benchmarked.</p> <p>Constructs random vectors and computes their dot product, giving the required time.</p> <div class="fragment"><pre class="fragment"><span class="comment">/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */</span> <span class="comment">// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s</span> <span class="comment">/* -*- mode: C++; style: linux -*- */</span> <span class="comment">/*</span> <span class="comment"> * examples/dot-product.C</span> <span class="comment"> *</span> <span class="comment"> * Copyright (C) 2002, 2010 Bradford Hovinen <hovinen@cis.udel.edu></span> <span class="comment"> *</span> <span class="comment"> * This file is part of LinBox.</span> <span class="comment"> *</span> <span class="comment"> * LinBox is free software: you can redistribute it and/or modify</span> <span class="comment"> * it under the terms of the GNU Lesser General Public License as</span> <span class="comment"> * published by the Free Software Foundation, either version 2 of</span> <span class="comment"> * the License, or (at your option) any later version.</span> <span class="comment"> *</span> <span class="comment"> * LinBox is distributed in the hope that it will be useful,</span> <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> <span class="comment"> * GNU Lesser General Public License for more details.</span> <span class="comment"> *</span> <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span> <span class="comment"> * License along with LinBox. If not, see</span> <span class="comment"> * <http://www.gnu.org/licenses/>.</span> <span class="comment"> */</span> <span class="preprocessor">#include "linbox/linbox-config.h"</span> <span class="preprocessor">#include <iostream></span> <span class="preprocessor">#include "<a class="code" href="field_2modular_8h.html" title="A Modular field is a representations of Z/mZ.">linbox/field/modular.h</a>"</span> <span class="preprocessor">#include "linbox/vector/vector-domain.h"</span> <span class="preprocessor">#include "<a class="code" href="stream_8h.html" title="Generation of sequences of random vectors.">linbox/vector/stream.h</a>"</span> <span class="preprocessor">#include "<a class="code" href="commentator_8h.html" title="Reports information to the user.">linbox/util/commentator.h</a>"</span> <span class="keyword">using namespace </span>LinBox; <span class="keyword">typedef</span> <a name="_a0"></a><a class="code" href="class_lin_box_1_1_modular_3_01uint32__t_01_4.html" title="Specialization of class Modular for uint32_t element type.">Modular<uint32_t></a> <a class="code" href="class_lin_box_1_1_modular_3_01uint32__t_01_4.html" title="Specialization of class Modular for uint32_t element type.">Field</a>; <span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) { <span class="comment">// Constants: we are working with an n x n matrix over GF(q)</span> <span class="keyword">const</span> <span class="keywordtype">int</span> n = 10000000; <span class="keyword">const</span> <span class="keywordtype">double</span> p = .001; <span class="keyword">const</span> <span class="keywordtype">int</span> q = 32749; commentator.<a name="a1"></a>setMaxDepth (1); commentator.<a name="a2"></a>setReportStream (std::cout); <a class="code" href="class_lin_box_1_1_modular_3_01uint32__t_01_4.html" title="Specialization of class Modular for uint32_t element type.">Field</a> F (q); <a name="_a3"></a><a class="code" href="class_lin_box_1_1_random_dense_stream.html" title="Random dense vector stream.">RandomDenseStream<Field, Vector<Field>::Dense</a>> factory1 (F, n); <a name="_a4"></a><a class="code" href="class_lin_box_1_1_random_sparse_stream.html" title="Random sparse vector stream.">RandomSparseStream<Field, Vector<Field>::SparseSeq</a>> factory2 (F, p, n); <a class="code" href="class_lin_box_1_1_random_sparse_stream.html" title="Random sparse vector stream.">RandomSparseStream<Field, Vector<Field>::SparsePar</a>> factory3 (F, p, n); Vector<Field>::Dense v1 (n), v2 (n); Vector<Field>::SparseSeq v3; Vector<Field>::SparsePar v4; factory1 >> v1 >> v2; factory2 >> v3; factory3 >> v4; VectorDomain<Field> VD (F); Field::Element res; commentator.<a name="a5"></a><a class="code" href="class_lin_box_1_1_commentator.html#a9b3772c898bc20f270af8d75ddc62090" title="Start an activity.">start</a> (<span class="stringliteral">"dense/dense dot product (1)"</span>); <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < 1; i++) VD.dot (res, v1, v2); commentator.<a name="a6"></a><a class="code" href="class_lin_box_1_1_commentator.html#a3a418a21b882e15baa44fe8bef7aca84" title="Stop an activity.">stop</a> (<span class="stringliteral">"done"</span>); commentator.<a class="code" href="class_lin_box_1_1_commentator.html#a9b3772c898bc20f270af8d75ddc62090" title="Start an activity.">start</a> (<span class="stringliteral">"dense/sparse sequence dot product (1000)"</span>); <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < 1000; i++) VD.dot (res, v1, v3); commentator.<a class="code" href="class_lin_box_1_1_commentator.html#a3a418a21b882e15baa44fe8bef7aca84" title="Stop an activity.">stop</a> (<span class="stringliteral">"done"</span>); commentator.<a class="code" href="class_lin_box_1_1_commentator.html#a9b3772c898bc20f270af8d75ddc62090" title="Start an activity.">start</a> (<span class="stringliteral">"dense/sparse parallel dot product (1000)"</span>); <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < 1000; i++) VD.dot (res, v1, v4); commentator.<a class="code" href="class_lin_box_1_1_commentator.html#a3a418a21b882e15baa44fe8bef7aca84" title="Stop an activity.">stop</a> (<span class="stringliteral">"done"</span>); <span class="keywordflow">return</span> 0; } </pre></div> </div> </div> <hr class="footer"/><address class="footer"><small>Generated on Tue Aug 30 2011 for linbox by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address> </body> </html>