Yep, the idea behind openMP is related to what you normally call directives or pragmas[1]. OpenMP offers a set of such directives so you can choose ways to parallelize *chunks* of your code accordingly to the best option you want. List of pragmas here [2].<div>
<br></div><div>The very basic example is a parallel for:</div><div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-style-span" style="font-family: monospace, 'Courier New'; font-size: 13px; "><pre class="de1" style="font-family: monospace, 'Courier New' !important; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-top-color: white; border-right-color: white; border-bottom-color: white; border-left-color: white; color: black; background-color: initial; line-height: normal; font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: top; background-position: initial initial; background-repeat: initial initial; ">
<span class="kw4" style="color: rgb(153, 51, 51); ">int</span> main<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="kw4" style="color: rgb(153, 51, 51); ">int</span> argc<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw4" style="color: rgb(153, 51, 51); ">char</span> <span class="sy0" style="color: rgb(51, 153, 51); ">*</span>argv<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span> <span class="br0" style="color: rgb(0, 153, 0); ">{</span>
<span class="kw4" style="color: rgb(153, 51, 51); ">const</span> <span class="kw4" style="color: rgb(153, 51, 51); ">int</span> N <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="nu0" style="color: rgb(0, 0, 221); ">100000</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span>
<span class="kw4" style="color: rgb(153, 51, 51); ">int</span> i<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> a<span class="br0" style="color: rgb(0, 153, 0); ">[</span>N<span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span>
<span class="co2" style="color: rgb(51, 153, 51); ">#pragma omp parallel for</span>
<span class="kw1" style="color: rgb(177, 177, 0); ">for</span> <span class="br0" style="color: rgb(0, 153, 0); ">(</span>i <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="nu0" style="color: rgb(0, 0, 221); ">0</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span> i <span class="sy0" style="color: rgb(51, 153, 51); "><</span> N<span class="sy0" style="color: rgb(51, 153, 51); ">;</span> i<span class="sy0" style="color: rgb(51, 153, 51); ">++</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>
a<span class="br0" style="color: rgb(0, 153, 0); ">[</span>i<span class="br0" style="color: rgb(0, 153, 0); ">]</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> 2 <span class="sy0" style="color: rgb(51, 153, 51); ">*</span> i<span class="sy0" style="color: rgb(51, 153, 51); ">;</span>
<span class="kw1" style="color: rgb(177, 177, 0); ">return</span> <span class="nu0" style="color: rgb(0, 0, 221); ">0</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span>
<span class="br0" style="color: rgb(0, 153, 0); ">}</span></pre></span></div><div><br></div><div>And yes, you only type "<span class="Apple-style-span" style="font-family: monospace, 'Courier New'; font-size: 13px; color: rgb(51, 153, 51); line-height: 15px; white-space: pre; ">#pragma omp parallel for" </span>before the "for" statement. Nothing more. You can test within your systems for the results. </div>
<div><br></div><div>Now just a final, very important notice: I am no openMP expert, just looking for interesting ways of speeding things up, there are other as mentioned in this list, several other times.</div><div><br></div>
<div>[1] <a href="http://books.google.pt/books?id=MeFLQSKmaJYC&printsec=frontcover&dq=openMP&source=bl&ots=5yWLnT441E&sig=ckzBbxx3u_EbWPNxaf9MkFn-CFM&hl=pt-PT&ei=6h39TPHeIY6j4QaWprypBw&sa=X&oi=book_result&ct=result&resnum=8&ved=0CGAQ6AEwBw#v=onepage&q&f=false">http://books.google.pt/books?id=MeFLQSKmaJYC&printsec=frontcover&dq=openMP&source=bl&ots=5yWLnT441E&sig=ckzBbxx3u_EbWPNxaf9MkFn-CFM&hl=pt-PT&ei=6h39TPHeIY6j4QaWprypBw&sa=X&oi=book_result&ct=result&resnum=8&ved=0CGAQ6AEwBw#v=onepage&q&f=false</a></div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br></div><div><br></div><div>[2] <meta http-equiv="content-type" content="text/html; charset=utf-8"><a href="http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlcpp8l.doc/compiler/ref/ruprpdir.htm">http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlcpp8l.doc/compiler/ref/ruprpdir.htm</a><br>
<br><div class="gmail_quote">On Mon, Dec 6, 2010 at 3:09 PM, Mathieu Bouchard <span dir="ltr"><<a href="mailto:matju@artengine.ca">matju@artengine.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Mon, 6 Dec 2010, Claude Heiland-Allen wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
NB: while it does use more than one core, I just compared with the single core version of gridflow without openmp and it uses only 25% of my cpu (on one core) while the openmp version uses 145% of my cpu (spread over two cores). So, it's no magic bullet...<br>
</blockquote>
<br></div>
I don't know how OpenMP works, but is there a way to apply it selectively to only part of a project ? I'm just guessing that it could make a big difference, e.g. if you don't apply it to numop*.cxx but you do apply it to much of the rest (perhaps also exclude gridflow.cxx itself because it contains the BitPacking class).<br>
<br>
I just had this idea because of what you told me on the #dataflow chat.<br>
<br>
_______________________________________________________________________<br><font color="#888888">
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Pedro Lopes (MSc)<br>contact: <a href="mailto:pedro.lopes@ist.utl.pt" target="_blank">pedro.lopes@ist.utl.pt</a><br>website: <a href="http://web.ist.utl.pt/Pedro.Lopes" target="_blank">http://web.ist.utl.pt/Pedro.Lopes</a> <br>
</div>