source: git/ntl/doc/tour-tips.html @ 6ce030f

spielwiese
Last change on this file since 6ce030f was 26e030, checked in by Hans Schönemann <hannes@…>, 15 years ago
*hannes: update to 5.5.1 git-svn-id: file:///usr/local/Singular/svn/trunk@11949 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.8 KB
Line 
1<html>
2<head>
3<title>
4A Tour of NTL: Tips for Getting the Best Performance out of NTL
5</title>
6</head>
7
8<body bgcolor="#fff9e6">
9<center>
10<a href="tour-win.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
11 <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> 
12<a href="tour-impl.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
13</center>
14
15<h1> 
16<p align=center>
17A Tour of NTL: Tips for Getting the Best Performance out of NTL
18</p>
19</h1>
20
21<p> <hr> <p>
22
23<ol>
24
25<li>
26Build NTL using GMP as the primary long integer package.
27This is extremely important, as the GMP implementation
28of long integer arithmetic is <i>much</i> faster
29than the default implementation.
30Go <a href="tour-gmp.html">here</a> for details.
31
32<p>
33<li>
34On many machines that optionally offer 64-bit integer arithmetic
35(recent Mac OSX machines, for instance),
36you should
37compile using <tt>gcc</tt> with the option <tt>-m64</tt>
38to get the full benefit.
39To do this,
40pass <tt>"CFLAGS=-O2 -m64"</tt>
41to the <tt>configure</tt> script (note the use of quotes).
42If you are using NTL with GMP on such a machine,
43you <i>must</i> do this to get compatible code.
44
45<p>
46<li>
47On Sparcs,
48pass the argument <tt>"CFLAGS=-O2 -mcpu=v8"</tt>
49to the <tt>configure</tt> script.
50On more recent, 64-bit sparcs, pass <tt>"CFLAGS=-O2 -mcpu=v9 -m64"</tt>
51to get the full instruction set and 64-bit code.
52
53<p>
54<li>
55Make sure you run the configuration wizard when you install NTL.
56This is the default behaviour in the makefile
57in the Unix distribution, so don't change this;
58in the Windows distribution, there is unfortunately no
59easy way to run the wizard.
60
61<p>
62<li>
63In time-critical code, avoid creating unnecessary temporary
64objects.
65For example, instead of
66<pre>
67ZZ InnerProduct(const ZZ *a, const ZZ *b, long n)
68{
69   long i;
70   ZZ res;
71   for (i = 0; i < n; i++)
72      res += a[i] * b[i];
73   return res;
74}
75</pre>
76write this as
77<pre>
78ZZ InnerProduct(const ZZ *a, const ZZ *b, long n)
79{
80   long i;
81   ZZ res, t;
82   for (i = 0; i < n; i++) {
83      mul(t, a[i], b[i]);
84      add(res, res, t);
85   }
86   return res;
87}
88</pre>
89The first version of <tt>InnerProduct</tt>
90creates and destroys a temporary object, holding the value
91<tt>a[i]*b[i]</tt>, in every loop iteration.
92The second does not.
93
94
95
96
97<p>
98<li>
99If you use the class <tt>ZZ_p</tt>, try to avoid switching the modulus
100too often, as this can be a rather expensive operation.
101If you <i>must</i> switch the modulus often,
102use the class <tt>ZZ_pContext</tt> to save the information
103associated with the modulus (see <a href="ZZ.txt">ZZ.txt</a>).
104
105
106
107</ol>
108
109<p>
110
111<center>
112<a href="tour-win.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
113 <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> 
114<a href="tour-impl.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
115</center>
116
117
118</body>
119</html>
Note: See TracBrowser for help on using the repository browser.