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

spielwiese
Last change on this file since 6ce030f was 287cc8, checked in by Hans Schönemann <hannes@…>, 14 years ago
ntl 5.5.2 git-svn-id: file:///usr/local/Singular/svn/trunk@12402 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 16.3 KB
Line 
1<html>
2<head>
3<title>
4A Tour of NTL: Obtaining and Installing NTL for UNIX  </title>
5</head>
6
7<body bgcolor="#fff9e6">
8<center>
9<a href="tour-stdcxx.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
10 <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> 
11<a href="tour-win.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
12</center>
13
14<h1> 
15<p align=center>
16A Tour of NTL: Obtaining and Installing NTL for UNIX
17</p>
18</h1>
19
20<p> <hr> <p>
21
22This procedure should work on most Unix or Unix-like platorms
23(including Mac OSX, and Windows with Cygwin tools).
24
25<p>
26
27
28To obtain the source code and documentation for NTL,
29<a href="http://www.shoup.net/ntl/download.html">
30download <tt>ntl-xxx.tar.gz</tt></a>,
31placing it a directory, and then, working in this directory,
32do the following.
33Here, "<tt>xxx</tt>" denotes the current version number.
34
35
36
37<p>
38<pre>
39   % gunzip ntl-xxx.tar.gz
40   % tar xf ntl-xxx.tar
41   % cd ntl-xxx/src
42   % ./configure PREFIX=$HOME/sw
43   % make
44   % make check
45   % make install
46</pre>
47
48This will build, test, and install NTL in <tt>$HOME/sw</tt>.
49Of course, change <tt>$HOME/sw</tt> to whatever you want (the default is
50<tt>/usr/local</tt>).
51You will find the NTL header files in <tt>$HOME/sw/include/NTL</tt>
52 and the compiled binary
53in <tt>$HOME/sw/lib/libntl.a</tt>
54(this is a <i>static</i> library -- if you want a <i>shared</i>
55library, <a href="#shared">see below</a>).
56<p>
57If you really are interested in high-performace, you will
58<i>definitely</i> want to build NTL
59using  GMP (the GNU Multi-Precision package).
60If GMP has already been installed in a standard
61place, like <tt>/usr/local</tt>, then invoke <tt>configure</tt>
62above as
63<pre>
64   % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on
65</pre>
66and if GMP is installed somewhere else, say <tt>$HOME/sw</tt>, then
67either
68<pre>
69   % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on GMP_PREFIX=$HOME/sw
70</pre>
71or, more simply,
72<pre>
73   % ./configure DEF_PREFIX=$HOME/sw NTL_GMP_LIP=on
74</pre>
75does the job.
76Here, <tt>DEF_PREFIX</tt> is a variable that is used
77to specify the location of all software,
78and it defaults to <tt>/usr/local</tt>.
79<a href="tour-gmp.html">This page</a> provides more
80details.
81
82<p>
83If you want very high-performance for polynomial arithmetic
84over <i>GF(2)</i>, you may want to consider using the <tt>gf2x</tt> library.
85To do this, <tt>gf2x</tt> must already be installed somewhere.
86In addition, you should invoke <tt>configure</tt>
87with the option <tt>NTL_GF2X_LIB=on</tt>.
88If <tt>gf2x</tt> is installed in a standard location, this is
89all you need to do;
90otherwise, if <tt>gf2x</tt> is installed, say, in <tt>$HOME/sw</tt>,
91then you also need to pass the option <tt>GF2X_PREFIX=$HOME/sw</tt>.
92<a href="tour-gf2x.html">This page</a> provides more details.
93
94
95
96
97<p>
98Now suppose you want to compile a program that uses NTL.
99Suppose you are working in some directory and <tt>foo.c</tt>
100is your program.
101Assume that you have installed NTL in <tt>$HOME/sw</tt> as above.
102The following should work:
103<pre>
104   % g++  -I$HOME/sw/include foo.c -o foo  -L$HOME/sw/lib -lntl  -lm
105</pre>
106If you are using GMP, then:
107<pre>
108   % g++ -I$HOME/sw/include foo.c -o foo  -L$HOME/sw/lib -lntl -lgmp  -lm
109</pre>
110If you are using GMP and <tt>gf2x</tt>, then
111<pre>
112   % g++  -I$HOME/sw/include foo.c -o foo  -L$HOME/sw/lib -lntl -lgmp -lgf2x  -lm
113</pre>
114
115
116<p>
117<h2>
118More Details
119</h2>
120<p>
121What follows is a more detailed description of the installation process.
122
123
124
125
126<p>
127<b>Step 1.</b>
128Extract the source files by executing:
129<pre>
130   % gunzip ntl-xxx.tar.gz
131   % tar xvf ntl-xxx.tar
132</pre>
133
134<p>
135Note that this will unpack everything into a sub-directory <tt>ntl-xxx</tt>,
136creating this directory if necessary.
137Next:
138<pre>
139   % cd ntl-xxx
140   % ls
141</pre>
142You should see a file "<tt>README</tt>", and directories
143"<tt>include</tt>", "<tt>doc</tt>", and "<tt>src</tt>".
144The directory "<tt>doc</tt>" contains all the documentation.
145The file "<tt>doc/tour.html</tt>" contains a copy of the on-line documentation.
146The directory "<tt>include</tt>"
147contains all the header files within a subdirectory
148"<tt>include/NTL</tt>".
149The directory "<tt>src</tt>" contains everything else.
150Go there now:
151<pre>
152   % cd src
153</pre>
154
155<p>
156<b>Step 2.</b>
157Run the configuration script.
158
159<p>
160Execute the command
161<pre>
162   % ./configure [ variable=value ]...
163</pre>
164
165This configure script generates the file "<tt>makefile</tt>" and the file
166"<tt>../include/NTL/config.h</tt>", based upon the values assigned to the
167variables on the command line.
168
169
170<p>
171
172Here are the most important variables, and their default values.
173
174<p>
175<pre>
176CC=gcc               # The C compiler
177CXX=g++              # The C++ compiler
178CFLAGS=-O2           # C complilation flags
179CXXFLAGS=$(CFLAGS)   # C++ compilation flags (by default, same as CFLAGS)
180
181DEF_PREFIX=/usr/local # Default software directory
182PREFIX=$(DEF_PREFIX) # Directory in which to install NTL library components
183SHARED=off           # Generate a shared library (as well as static)
184
185NTL_STD_CXX=on       # ISO Mode switch
186
187NTL_GMP_LIP=off      # Switch to enable the use of GMP as primary
188                     #   long integer package
189
190GMP_PREFIX=$(DEF_PREFIX) # Directory in which GMP components are installed
191
192NTL_GF2X_LIB=off     # Switch to enable the use of the gf2x package
193                     #   for faster arithmetic over GF(2)[X]
194
195GF2X_PREFIX=$(DEF_PREFIX) # Directory in which gf2x components are installed
196</pre>
197
198<p>
199<i>Examples.</i>
200<p>
201
202<ul>
203<li>
204If you are happy with all the default values, run:
205<pre>
206   % ./configure
207</pre>
208Actually, the initially installed <tt>makefile</tt> and <tt>config.h</tt> files
209already reflect the default values, and you do not have to even run
210the configure script.
211
212<p>
213<li>
214If your C/C++ compilers are called cc/CC, run:
215<pre>
216   % ./configure CC=cc CXX=CC
217</pre>
218
219<p>
220<li>
221If you want to use, say, the options <tt>-g</tt> and <tt>-O</tt> for
222compiling <tt>C</tt> and <tt>C++</tt>, run:
223<pre>
224   % ./configure "CFLAGS=-g -O"
225</pre>
226Note the use of quotes to keep the argument in one piece.
227
228<p>
229<li>
230If <a href="tour-gmp.html">GMP (the GNU Multi-Precision package)</a> 
231is installed in a standard system directory, and you want to use it
232to obtain better performance for long integer arithemtic, run:
233<pre>
234   % ./configure NTL_GMP_LIP=on
235</pre>
236If GMP was installed in
237 <tt>$HOME/sw</tt>,
238run:
239<pre>
240   % ./configure NTL_GMP_LIP=on GMP_PREFIX=$HOME/sw
241</pre>
242Go <a href="tour-gmp.html">here</a> for complete details.
243
244
245<p>
246<li>
247If <a href="tour-gf2x.html"><tt>gf2x</tt></a> 
248is installed in a standard system directory, and you want to use it
249to obtain better performance for polynomial arithemtic over <i>GF(2)</i>,
250run:
251<pre>
252   % ./configure NTL_GF2X_LIB=on
253</pre>
254If <tt>gf2x</tt> was installed in
255 <tt>$HOME/sw</tt>,
256run:
257<pre>
258   % ./configure NTL_GF2X_LIB=on GF2X_PREFIX=$HOME/sw
259</pre>
260Go <a href="tour-gf2x.html">here</a> for complete details.
261
262<p>
263<li>
264If you want to use
265<a href="tour-stdcxx.html">traditional rather than ISO mode</a>, run:
266<pre>
267   % ./configure NTL_STD_CXX=off
268</pre>
269
270<p>
271<li>
272If you want to install NTL in the directory <tt>$HOME/sw</tt>,
273run:
274<pre>
275   % ./configure PREFIX=$HOME/sw
276</pre>
277</ul>
278
279<p>
280There are a number of more esoteric configuration variables that can be set.
281See <a href="config.txt"><tt>config.txt</tt></a> for a complete
282description.
283
284<p>
285Note that all of these configuration options can also be set
286by editing the two files <tt>makefile</tt>
287and <tt>../include/NTL/def_config.h</tt> by hand.
288These files are fairly simple and well documented, and so this is not
289too hard to do.
290
291<p>
292Note that the file "<tt>../include/NTL/def_config.h</tt>"
293contains a backup copy of the original <tt>config.h</tt> file,
294and that the file "<tt>def_makefile</tt>"
295contains a backup copy of the original <tt>makefile</tt> file.
296
297<p>
298This command is intended only as a convenience
299and -- more importantly -- to allow the configuration process
300to be script driven.
301This script does not perform any "magic", like finding out what
302the local C compiler is called, etc. 
303If the defaults are not
304correct for your platform, you have to set an appropriate variable.
305
306
307
308<p>
309<b>Step 3.</b>
310Execute <tt>make</tt>.
311
312<p>
313Just type:
314<pre>
315   % make
316</pre>
317
318<p>
319The build  process after this point is fully automatic.
320But here is a description of what happens.
321
322<p>
323
324<ol>
325<li>
326The makefile
327builds the file "<tt>../include/NTL/mach_desc.h</tt>", which defines some machine characteristics
328such as word size and machine precision.
329This is done by compiling and running a <tt>C</tt> program
330called <tt>MakeDesc</tt>
331that figures out these characteristics on its
332own, and prints some diagnostics to the terminal.
333
334<p>
335<li>
336A script is run that "automagically"
337determines the best way to write a timing function
338on your platform.
339It tries different routines in the files <tt>GetTime1.c</tt>,
340<tt>GetTime2.c</tt>, etc., and when it finds a good one,
341it copies the file into <tt>GetTime.c</tt>.
342
343<p>
344<li>
345The files "<tt>lip_gmp_aux_impl.h</tt>" and "<tt>../include/NTL/gmp_aux.h</tt>"
346are generated for use with GMP.
347If not using GMP, these files are still created, but they are empty.
348
349
350<p>
351<li>
352The configuration wizard script is run.
353This script works in a sub-directory,
354compiling several programs,
355and performing a number of timing experiments,
356in order to determine the optimal setting for a number of flags
357in the file <tt>../include/NTL/config.h</tt>.
358When the script finishes (it may take several minutes),
359you will be told what the wizard thinks are the best settings,
360and your <tt>config.h</tt> file will be automatically updated.
361Note that any flags you set in Step 2
362will be in
363effect while the wizard runs, and will be retained in the updated
364<tt>config.h</tt> file, with the exception of the flags
365<pre>
366   NTL_LONG_LONG NTL_AVOID_FLOAT NTL_TBL_REM NTL_AVOID_BRANCHING
367   NTL_SPMM_UL NTL_SPMM_ULL NTL_SPMM_ASM NTL_GF2X_NOINLINE NTL_GF2X_ALTCODE
368</pre>
369which are set by the wizard.
370Also note that if you <i>do not</i> want the wizard to run,
371you should pass <tt>WIZARD=off</tt> to the configure script;
372however, this is not recommended.
373
374<p>
375<li>
376The makefile will compile all the source files,
377and then creates the library "<tt>ntl.a</tt>" in the current directory.
378</ol>
379
380<p>
381Note that for finer control  you can optionally  break up this process
382into the five
383component steps:
384<pre>
385   % make setup1
386   % make setup2
387   % make setup3
388   % make setup4
389   % make ntl.a
390</pre>
391
392
393<p>
394
395<p>
396<b>After NTL is built.</b>
397
398<p>
399Executing <tt>make check</tt> runs a series of timing and test programs.
400It is a good idea to run this to see if everything really
401went well.
402
403<p>
404Executing <tt>make install</tt>
405copies a number of files to a directory <tt>&lt;prefix&gt;</tt> that you
406specify by passing <tt>PREFIX=&lt;prefix&gt;</tt>
407as an argument to <tt>configure</tt> at configuration time,
408or as an argument to <tt>make install</tt> at installation time.
409The default is <tt>/usr/local</tt>, so either you need root
410permissions, or you choose a <tt>&lt;prefix&gt;</tt> for which
411you have write permission.
412The files <tt>../include/NTL/*</tt> are copied into
413<tt>&lt;prefix&gt;/include/NTL</tt>.
414The file <tt>ntl.a</tt> is copied to <tt>&lt;prefix&gt;/lib/libntl.a</tt>.
415The files <tt>../doc/*</tt> are copied into
416<tt>&lt;prefix&gt;/share/doc/NTL</tt>.
417
418<p>
419You can also "fine tune" the installation procedure further.
420See the <a href="config.txt">configure documentation</a> for details.
421
422<p>
423Executing <tt>make uninstall</tt> undoes <tt>make install</tt>.
424
425
426<p>
427Executing <tt>make clobber</tt> essentially
428undoes <tt>make</tt>.
429<i>Make sure you do this if you re-build NTL for a different architecture!</i>
430
431<p>
432Executing <tt>make clean</tt> will remove object files, but not
433<tt>ntl.a</tt>.
434To rebuild after executing <tt>make clean</tt>, execute <tt>make ntl.a</tt>.
435
436
437<p>
438Assuming you have installed NTL as above,
439to compile a program <tt>foo.c</tt> that uses NTL,
440execute
441<pre>
442   g++  -I&lt;prefix&gt;/include foo.c -o foo  -L&lt;prefix&gt;/lib -lntl  -lm
443</pre>
444This compiles <tt>foo.c</tt> as a <tt>C++</tt> program
445and creates the binary <tt>foo</tt>.
446<p>
447If you built NTL using <a href="tour-gmp.html">GMP</a>, execute:
448<pre>
449   g++  -I&lt;prefix&gt;/include foo.c -o foo  -L&lt;prefix&gt;/lib -lntl  -L&lt;gmp_prefix&gt;/lib -lgmp  -lm
450</pre>
451<p>
452Of course, if <tt>&lt;prefix&gt;</tt> and <tt>&lt;gmp_prefix&gt;</tt>
453are the same, you do not need to  duplicate the <tt>-L</tt> 
454flags, and if either are standard directories, like <tt>/usr/local</tt>,
455you can leave out the corresponding <tt>-I</tt> and <tt>-L</tt>
456flags altogether.
457<p>
458Similarly, if you built NTL using <a href="tour-gf2x.html"><tt>gf2x</tt></a>,
459you should include flags
460<pre>
461   -L&lt;gf2x_prefix&gt;/lib -lgf2x
462</pre>
463on the command line.
464<p>
465This works even if you are not working in the directory
466in which you built NTL.
467If you <i>are</i> working in that directory, you can just execute
468<pre>
469   make foo
470</pre>
471
472<p>
473<h2>
474<a name="shared">
475Building a Shared Library
476</a>
477</h2>
478<p>
479
480
481By default, the above installation procedure builds
482a <i>static</i> library only.
483Static libraries are nice because the procedures for building
484and using them are nearly identical across various flavors
485of Unix.
486However, static libraries have their drawbacks, and sometimes
487it is desirable to build a <i>shared</i> library.
488This can be done (in theory) by simply passing <tt>SHARED=on</tt> to
489NTL's <tt>configure</tt>.
490
491<p>
492If you set <tt>SHARED=on</tt>, then behind the scenes,
493the procedure used by the <tt>makefile</tt> changes a bit.
494In particular, the magical GNU program <tt>libtool</tt> is used
495to deal with all idiosyncracies of shared libraries.
496You may need to set the
497configuration variable <tt>LIBTOOL</tt>, to point to another version of
498<tt>libtool</tt>
499For example, on <i>Mac OSX</i>, the built-in command called <tt>libtool</tt>
500is not
501actually the GNU <tt>libtool</tt> program;
502in this case, you will want to set
503<tt>LIBTOOL=glibtool</tt>
504On other systems, it may be necssary to download and
505install a fresh copy of the libtool program (which can be obtained from
506<a href="http://www.gnu.org/software/libtool">here</a>).
507Note that if <tt>SHARED=on</tt>, then
508in addition to using the <tt>libtool</tt> program, the <tt>makefile</tt> 
509relies on
510features specific to GNU make.
511
512<p>
513Note that if you want to build NTL as a shared library,
514then if you use them, GMP and <tt>gf2x</tt> must also
515be built and installed as shared libraries.
516Also note that to use a shared library version of NTL,
517you may have to do something special, like set a special
518shell variable:  the output generated by the <tt>libtool</tt>
519program during <tt>make install</tt> should give specific
520instructions.
521In addition, if NTL is built as a shared library, then
522you typically do not have to include <tt>-lgmp</tt> (if using GMP),
523or <tt>-lgf2x</tt> (if using <tt>gf2x</tt>), or corresponding
524<tt>-L</tt> flags, or <tt>-lm</tt> 
525on
526the command line when compiling programs that use NTL.
527
528
529<p>
530<h2>
531<a name="abi">
53232-bit and 64-bit ABIs
533</a>
534</h2>
535<p>
536
537
538An ABI (Application Binary Interface) defines the sizes of various
539<tt>C</tt> data types.
540Typically, with a 32-bit ABI, int's and long's are 32 bits,
541while on a 64-bit ABI, int's are 32 bits and long's are 64 bits.
542Some platforms
543support both 64-bit and 32-bit ABI's;
544typically in such settings, the 64-bit ABI will yield much better
545performance, while the 32-bit ABI is available for backward compatibility.
546In addition, the 64-bit ABI may <i>not</i> be the default:
547if you are using <tt>gcc</tt>, you need to pass the <tt>-m64</tt>
548flag to the compiler to get the 64-bit ABI.
549
550<p>
551When compiling NTL, you may want to try running <tt>configure</tt>
552with <tt>CFLAGS="-O2 -m64"</tt> to force a 64-bit ABI -- this
553may yield a very marked performance improvement.
554
555<p>
556If you are using NTL with either the GMP or <tt>gf2x</tt> libraries,
557then these must be built with the same ABI as NTL.
558The installation script for GMP will typically select the 64-bit ABI
559automatically if it is available.
560The installation script for <tt>gf2x</tt> may need some hints.
561
562<p>
563When compiling programs that use NTL, you must also ensure that
564the program is compiled with the same ABI as NTL.
565Again, if you want a 64-bit ABI, then just pass the flag <tt>-m64</tt>
566to the compiler.
567
568
569
570
571
572<p> <p>
573<p> <p>
574
575<center>
576<a href="tour-stdcxx.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
577 <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> 
578<a href="tour-win.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
579</center>
580
581</body>
582</html>
Note: See TracBrowser for help on using the repository browser.