Wednesday, December 31, 2008

Compiling GMP and MPFR

GMP (Gnu Multi-Precision Arithmetic library) and MPFR (Multi-Precision Floating-Point with Rounding) libraries are prerequisites for bootstrapping the GCC-4.x.x compiler suite. Many modern Unix/Linux systems may have compatible GMP and MPFR library versions already installed; however, if the libraries are not present or the versions are too old, you will need to download either a binary package for your system or the source tarball and compile them yourself. When in doubt, download the sources and compile them yourself to ensure that you have the latest, fastest, and most bug-free libraries.

Once you've downloaded the source tarballs from the websites listed in my previous post and expanded them in a build directory, be sure to read the README and INSTALL text file for the latest requirements and instructions for building the libraries. Both libraries use an Autotools (autoconf, automake, etc.) generated configure script to generate a Makefile for compiling. Make sure to run "./configure --help" in a terminal to see all available configure options. Both GMP and MPFR have options for building shared and static libraries. If you decide to build static-only libraries or if you think you may want to explicitly link a static library into a shared binary, make sure you put "--with-pic" in the list of configure options. Also, you may want to make sure the proper compiler is used to build the libraries by setting the environment variables for them (CC,CXX,FC,CFLAGS,etc.) as described in the "./configure --help" output.

Below are the configure options I used on an AMD Opteron cluster running CentOS 4.4:

GMP:
> ./configure --prefix=/usr/local/gmp422-mpfr231 \
--disable-shared --enable-static --with-pic \
--infodir=/usr/share/info --mandir=/usr/share/man
> make check
> su root
> make install

In this configuration for GMP, I set the installation directory with the '--prefix=/usr/local/gmp422-mpfr231' option. This allows me to keep matching versions together while retaining other version on the system. Also, I disabled building shared libraries to simplify executing on other computers the programs that link against GMP. Using the '--with-pic' option allows the static GMP library to be linked into executables that also link against shared libraries. And finally I included the '--infodir=/usr/share/info --mandir=/usr/share/man' options to install the man and info files in the proper directories for my system.

Compiling MPFR is similar to GMP with the addition of the '--with-gmp=/usr/local/gmp422-mpfr231' option to point to the location of our new GMP library:

MPFR:
> ./configure --prefix=/usr/local/gmp422-mpfr231 --with-gmp=/usr/local/gmp422-mpfr231 --with-pic --disable-shared --enable-static
> make check
> su root
> make install

Congratulation! You are now ready to bootstrap GCC-4.x.x. There are a lot of issues to cover with bootstrapping GCC so I may have to cover that in several posts.

Have a Happy New Year!

Tuesday, July 8, 2008

Bootstrapping GCC-4.x.x: Prerequisites

In this post, I will be discussing the general process of compiling GCC, along with how to obtain the necessary source code for GCC and its prerequisites.

Bootstrapping a compiler is the process of building the compiler from source code that is written in the target computing language itself with minimal external resources. Therefore, when bootstrapping GCC-4.x.x, the system must containing a working C compiler and some pre-requisite libraries.

For the GCC-4.3.x series of compilers, the pre-requisite libraries are the GNU Multi-Precision Arithmetic library (GMP-4.1+) and the Multi-Precision Floating-Point with Rounding library (MPFR-2.3.0+). Earlier version of GCC-4.x.x only required these libraries when building the GCC GFORTRAN compiler; however, in all recent GCC versions, these libraries are required for building the compiler. Many modern UNIX/Linux systems come with these libraries pre-installed, however you must be sure to check the version of the included libraries against the version requirements for the specific GCC-4.x.x compiler you desire to bootstrap. Some of the older versions of these libraries contain bugs that can adversely affect the accuracy of the resulting bootstrapped compiler. The version numbers for the preinstalled prerequisite libraries can be found in the header files, gmp.h and mpfr.h, respectively.

GCC-4.x.x is an open source compiler collection know as the Gnu Compiler Collection (GCC), whose homepage is locate at http://gcc.gnu.org. The GCC homepage contains a wealth of information straight from the developer and user community. To download the desired version of GCC, just follow the appropriate links on the GCC homepage to one of the many ftp or http mirror sites. The source code comes in the form of a compressed tarball ending in ".tar.bz2". Once the source has been downloaded to your computer, put it in a build folder with a name such as "BuildDir" and expand the tarball with the following command: "tar -xjvf gcc_tarball_name.tar.bz2".

The GMP is another opensource project, whose homepage is located at http://gmplib.org. Just following the links on the homepage to download the desired GMP source code. Move the tarball to your "BuildDir" and expand the tarball. If the tarball ends with ".tar.gz", it can be expanded with the command: "tar -xzvf source_name.tar.gz". Similarly, MPFR is also an open source project, with it's homepage located at http://www.mpfr.org. Again, follow the links to download the appropriate source, move it to your "BuildDir", and expand the tarball.

Congratulations, you now have all the necessary source code to bootstrap GCC. In my next post, I will walk you through compiling and checking both the GMP and the MPFR libraries. I will also shared some of my experiences and tips for avoiding trouble down the road.

Until next time, God Bless and Have a great day!!!

Sunday, June 29, 2008

Choosing a compiler - GCC-4.x.x, the GNU Compiler Collection

In order to compile or develop an HPC application, a solid compiler package is needed. From my experience, the GCC-4.x.x series of compilers offer the best balance of cost (FREE!!!), performance (competitive with commercial compilers from INTEL, IBM, PGI, PathScale, NAG, etc.), developer access (communication with developer community, rapid bug fixes, etc.), features, and standard compliance. In addition, the GCC-4.x.x compiler collection is the default compiler package on Linux, Unix, and Mac OS X operating systems. Commercial compilers from vendors such as those listed above offer their own unique advantages in certain areas; however, for my own personal (and professional) use the GCC-4.x.x is my compiler package of choice.
If the default compiler is sufficient (stability, features, performance, and relatively bug-free for your uses), then by all means use the default compiler on your system. However, if the system GCC installation is not sufficient for your needs (i.e. not a recent enough version , etc.), then your will need to either install a set of pre-built binaries or download the GCC source code of a more recent version and compile/bootstrap it yourself. In the near future, I plan to offer downloadable pre-built GCC binaries for a few select platforms (Mac OS X, RedHat Linux, Ubuntu Linux). In addition, future posts will descibe the process of downloading and compiling GCC-4.x.x along with its pre-requisite packages (GMP and MPFR). Once this is done, I will be discussing MPI package options and do a walk through of compiling and setting up OpenMPI. Until next time, may your clusters always crunch with minimal downtime! 

Tuesday, June 24, 2008

Intro to ClusterNut Notes

Hello and welcome to ClusterNut Notes! I am the ClusterNut and I will be writing on topics related to High Performance Computing (HPC), parallel computing clusters, MPI programming hints, and just about anything else related to scientific computing that crosses my mind. I am looking forward to sharing my knowledge and experience in the HPC field with you. Though I have quite a bit of experience in scientific computing and running clusters, I am by no means a guru and look forward to hearing your insight and suggestions as well.