[Previous] [Up] [Next]

A Tour of NTL: Using NTL with the GF2X library


GF2X is a library for fast multiplication of polynomials over GF(2). The GF2X library was developed by Emmanuel Thomé, Paul Zimmermmann, Pierrick Gaudry, and Richard Brent.

Unlike NTL, which only imlements a version of Karatsuba multiplication, GF2X implements other algorithms that are faster for very large degree polynomials. If you use NTL if the GF2X library, then multiplication, division, GCD, and minimum polynomal calculations for the GF2X class will be faster for large degree polymials.

For example, based on benchmarks on an Intel Xeon Platinum 8175M (which is the server configuration of the Skylake microarchitecture), compared to NTL's default implementation, the GF2X library is 1.4x faster at multiplying polynomials of degree 1,000 over GF(2), and 2.1x faster at multiplying polynomials of degree 1,000,000.

Note: GF2X is thread safe, so you should feel free to use it in a thread-safe build of NTL. However, it is not entirely exception friendly (it may abort a running program, but only in some very extreme and unusal circumstances).

Downloading and building GF2X

Download GF2X from here. This is a gitlab page that allows you to clone a git repository. If you do not want to use git, you you can also just download gf2x-XXX.tar.gz (both options are accessible through the "code" tab on that page).

Assuming you have downloaded gf2x-XXX.tar.gz, do the following:

   % tar -xf gf2x-XXX.tar
   % cd gf2x-XXX
   % autoreconf -i
   % ./configure --prefix=$HOME/.local
   % make
   % make check
   % make install
Note the line "autoreconf -i". This is needed because GF2X is distributed without a configure script. Rather, the configure script has to be built using autoreconf, which is a part of the GNU autotools suite. Depending on your system, you may have to install GNU autotools before you can build GF2X.

This will build, test, and install GF2X in $HOME/.local. Of course, change $HOME/.local to whatever you want. You will find the GF2X header files in $HOME/.local/include and the compiled binaries in $HOME/.local/lib.

By default, this is will install both a static and shared library. You can supply the option --disable-shared to the configure script, if you only want static libraries. If you do this, you may also consider passing the --with-pic option if you want another shared library to be able to call functions in GF2X.

When building NTL with GF2X, you have to tell NTL that you want to use it. To do this, pass the argument NTL_GF2X_LIB=on to the NTL configure script when you are installing NTL.

You need to make sure that the NTL configure script knows where to find GF2X when you are builing NTL. You can do this by passing GF2X_PREFIX=$HOME/.local or DEF_PREFIX=$HOME/.local to NTL's configure script.

For example, if NTL, GMP, and GF2X are all being installed in $HOME/.local, invoke NTL's configure script like this:

   % ./configure DEF_PREFIX=$HOME/.local NTL_GF2X_LIB=on 

Also when you link and run a program that uses NTL, you have to make sure that the GF2X library is found at link time and, depending on the system, possibly at run time. The best way to see how to do this is to look at the file USER_MAKEFILE.txt installed in NTL's include directory — again, see here for details.

When using NTL with GF2X, as a user of NTL, you do not need to know or understand anything about the the GF2X library.


[Previous] [Up] [Next]