Compile the code with an ANSI C compiler

Instructions for various compilers are given below. In each case, from the command prompt, cd into the source directory and compile everything using the wildcards indicated below.

Floating point exceptions Compile options should be set so that the machine throws an exception ("crashes") on division by zero, overflow, and invalid operations. Underflow is inevitable and should not be trapped. The compiler options below should do this. Cloudy has code in routine SetFPEnv (in the file cdinit.c) that will set the proper floating point environment for nearly all systems.

A note on aggressive optimization: Safe levels of optimization, which we have seen work successfully, are shown in the following examples. If you try to use your compiler's very highest optimization levels you will just find compiler bugs, at least when compiling a code as large as Cloudy. Do a debug compile first, check that all went well by running the test suite (described here), and recompile with optimization and run the test suite again. If that fails you will need to do a binary search to find the routine the compiler could not handle, by compiling half the code in debug, and half in optimized mode, eventually tracing down which files could not be compiled with aggressive optimization. The compiler vendor may fix the bug if you can isolate it down to a few lines of code. They won't help if you just tell them that a 300k-line code does not work with their compiler. My experience is that aggressive optimization only gains another 5 to 15 percent speedup and is generally not worth the bother. People time is far more expensive than machine time.

makefiles: This page describes how to create a dependencies file and Makefile using gcc. For other platforms edit the makefile to use the compiler options listed below.

Warnings with routine CrashDo: This routine contains logic that is designed to cause the code to crash. Good compilers will detect dangerous code and create warnings. This is not a problem, it only means that you have a good compiler.

A note on LAPACK: A translated C version of some LAPACK routines is included in the source distribution (the file lapack.c). Your machine may have a precompiled and optimized version of this library that is faster than mine. Cloudy actually calls a wrapper for LAPACK that is resolved to either the internal routines (which have slightly changed names to avoid collisions with the real LAPACK) or your system's LAPACK library. If you set the macro LAPACK on the compiler command line (usually with the option -DLAPACK) then the wrappers will resolve to your system's LAPACK library. If the vendor worked hard to generate optimized code then this may be faster than the version obtained by simply compiling the source that comes with the distribution. You may have to include an additional library on the link step to actually load your version of LAPACK.

The assert macro. Asserts are a feature of safe computer languages. They provide for a simple way to insure that variables have sane values. They do slow down the calculation a bit. They can be turned off if you are confident that your compiler produces an executable that behaves properly. Asserts are turned off with the command-line option -DNDEBUG. You would write the compiler command line as something like "gcc <other compiler options> -DNDEBUG *.c" on the compile step. (The compiler probably does this automatically when high levels of optimization are used.) If you wish to turn off asserts it you should first run the test suite with optimized code and the asserts enabled. Once the test suite completes successfully the -DNDEBUG parameter can be added and the code recompiled. NB - It is important to run the test suite at least once with the asserts included - this is how we discovered that the icc compiler does not produce correct optimized code.

The remainder of this page gives advice on compiling the code on various platforms. Note that in the command lines shown below the "o" or "O" is the letter "oh" not the number zero.


This is the preferred compiler.

Make sure that you do not have version 2.96. This version of gcc is broken, will not work, and is the version included in many older Linux distributions. To find out which version of gcc you have type "gcc -v". If you have version 2.96 then you may also have kgcc, an older version of gcc that is capable of compiling the Linux kernel (version 2.96 couldn't even do that). Use kgcc in this case. Versions of Cloudy downloaded after 2002 Feb 27 include code to check for gcc 2.96, and will refuse to execute if that compiler is used.

3.0.x versions of gcc may not produce correct code in non-optimized mode on Intel boxes (see this bug report), but we have obtained excellent results with version 3.1 or later of gcc. The code is currently (mid 2006) tested with version 3.4 on a regular basis.

Versions before 2.1 of the gcc library glibc have problems with floating point precision on Intel processors. Make sure that you have version 2.1 or later if you plan to work on an Intel box.

There is a major bug in some versions of the math library that comes with gcc on Dec Alphas. If you are running Linux on an Alpha please read this.

Peter van Hoof found a way to disable gradual underflows when using gcc on ultrasparcs - this results in a major speedup. See the comments around the macro "HAVE_SUNMATH" in setfpenv.c.

Recent versions of gcc produce a series of compiler warnings in routine ParseCrashDo?. It detects unsafe code which is designed to implement the crash command. The warnings include "dereferencing type-punned pointer" and the use of uninitialized variables. This is expected.

Enabling floating point exceptions: Cloudy has code in routine SetFPEnv (in the file cdinit.c) that will set the proper floating point environment for nearly all systems. Not all distributions of gcc include fpu_control.h (the Cygwin distribution that I use does not) so this piece of code may create problems on some systems.

debug compile
gcc -ansi -Wall -g -c *.c
gcc -o cloudy.exe *.o -lm

optimized compile
gcc -ansi -c -O3 -fno-math-errno -funsafe-math-optimizations -Wall *.c
gcc -funsafe-math-optimizations -o cloudy.exe *.o -lm

optimized compile on AMD64/EM64T compatible
gcc -ansi -c -O3 -fno-math-errno -Wall *.c
gcc -o cloudy.exe *.o -lm

The code is tested with gcc on a regular basis. However it is not feasible to test every version of the code against every version of gcc on every platform. For certain combinations, using the -funsafe-math-optimizations flag may cause problems (the AMD64/EM64T platform is a known example). If you see failures in the test suite, try recompiling the code without the -funsafe-math-optimizations flag. Usually this will solve the problem.

MAC Darwin

Donglai Gong first ran Cloudy on a Mac. He writes "for MacOS X users, they'll first need to download Apple Developer's Tools (free with registration from Apple's developer website) which includes gcc. When you get to this web site go to the Download section and follow the link to Mac OS X, you'll see the developer tools listed. I should also say that Apple's current cc (as of OS X 10.2) is basically gcc 3.1. All Macs shipping with Mac OS X 10.2 supposedly have the developer tools included on one of the install CD's, although it's not installed by default."

Compiling Cloudy on MacOS X 10.2/Darwin 6.0.1

Peter van Hoof suggests the following for an optimized compile:
cc -ansi -c -Wall -no-cpp-precomp -O3 -fno-math-errno -funsafe-math-optimizations *.c
cc -funsafe-math-optimizations -o cloudy *.o -lm

Megan Donahue found that several test cases ended with a seg fault on her g4. This was because tcsh on OS X has a limited stacksize (512k). A solution is to include the command
limit stacksize unlimited
just before executing Cloudy. That did the trick. The problem is with tcsh and the command should be included in startup files for this shell on all operating systems.

Many thanks to Donglai Gong and Megan Donahue for testing the code on this platform & Peter van Hoof for suggesting compiler options.

Sun Solaris

debug compile:
cc -Xc -g -c *.c
cc -g -o cloudy.exe *.o -lm

optimized compile:
cc -Xc -fast -c *.c
cc -fast -o cloudy.exe *.o -lm

The -Xc option tells the compiler to expect "maximally conformant ANSI C code.

Beware that there are actually two versions of cc on Solaris machines. One resides in /usr/ucb/cc, and is a wrapper to make the C compiler BSD compatible. This version uses a non-standard sprintf function that returns a pointer to the string buffer instead of an int containing the number of bytes written. If you are using this version then prtcomment.c will fail to compile. The code will compile correctly with the regular version of the C compiler, usually located in /opt/SUNWspro/bin/cc (the location may vary, contact your system manager for further information). You can find out which version you are using by typing "which cc". If this returns "/usr/ucb/cc", change your path to point to /opt/SUNWspro/bin/cc, or use gcc."

The warning "/usr/include/ieeefp.h", line 123: warning: dubious reference to enum typedef: fp_rnd" appears to be benign.

Optimized compile with gcc on Sun

gcc -ansi -c -O3 -fno-math-errno -funsafe-math-optimizations -Wall *.c
gcc -funsafe-math-optimizations *.o -lm

With gcc 3.1 and later, the option -funsafe-math-optimizations will disable gradual underflow. This will lead to a 10 to 20% speedup of the code.

We don't have any Suns any more. The code is tested on this platform on irregular intervals.


This machine uses the Itanium 64 bit processor.

debug compile:
cc -c -g -Aa +e +z -DLAPACK +DD64 *.c
cc +FPZO +FPZ -o cloudy.exe *.o -lm

optimized compile
cc -Aa -O -c +z -DLAPACK +DD64 +e *.c
cc +FPZO +FPZ -o cloudy.exe *.o -lm

The code is very well tested on this platform. The University of Kentucky HP cluster is described here.

IBM pSeries servers based on POWER4 and POWER5 processors

optimized compile

xlc -O3 -qarch=auto -qtune=auto -lmass -lm

where xlc is the C compiler and -lmass links to the IBM Mathematical Acceleration Subsystem (MASS) library which can be downloaded from

Portland Group pgcc

This compiler is one of the very few that includes native array bounds checking in a C/C++ code. The compiler web site is here. A debug compile with array bounds checking is done with

debug compile with array bounds checking
pgcc -Minform=warn -Mbounds -g -O2 -c *.c
pgcc -o cloudy.exe *.o -lm

optimized compile
pgcc -Minform=warn -Munroll -O3 -c *.c
pgcc -o cloudy.exe *.o -lm

The -Xa option detects code that does not conform to the C standard. It produces many thousands of comments concerning header files in the Linux distribution we use. Many thanks to Mitchell Martin for testing this compiler.

MS Visual Studio 6

Create a new "win32 console application". Add all the source files to the project. Select the "disable language extensions" option under projects\settings\c++\customize tab. I also set the "warning level" under projects\settings\c++\general to 4 but this is not necessary. With this IDE the debug and optimized versions are referred to as "debug" and "release".

MS Visual Studio Dot Net 2003 & 2005

Create a new new project from the file/new project option. In "Project Types" select "Visual C++ Projects". Under "templates" select "Win32 Project" and enter a name for the project. Click OK Next the Win32 Application Wizard opens. Click "application settings". Select "console application" and "empty project" then click on "finish". Now add all the source and header files to the project with the "project/add existing files" option.. I also set the "warning level" under projects\settings\c++\general to 4 but this is not necessary. With this IDE the debug and optimized versions are referred to as "debug" and "release".

The code is developed on this platform. This PDF file has screen shots showing the compile-time options I use to produce debug code. ND - the code dependencies will not be detected unless you go to project/properties c/c++ / Code generation, and make sure that "enable minimal rebuild" is set to "no". minimal rebuild checks for changes in classes. There are no classes in C so changes were not detected.

Intel icc on non-AMD64/EM64T machines

We tested version 9.1 of icc. The default level of optimization enables rather aggressive forms of floating-point optimization that interfere with the correct execution of Cloudy. It is essential to use the -mp flag in order to disable those optimizations.. The following options were used:

debug compile:
icc -ansi -w1 -c -O0 *.c
icc -o cloudy.exe *.o -lm

Note that the -O0 command line option needs to given explicitly since the default level of optimization is -O2, and not -O0 as with other compilers.

optimized compile:
icc -ansi -w1 -c -O3 -mp *.c
icc -o cloudy.exe *.o -lm

Version 9.0 of icc and prior will not pass the test suite with -O3 -mp on IA64, use -O1 -mp. Version 9.1 did pass. All versions of icc passed with -O3 -mp on IA32

Many thanks to Peter van Hoof and Ryan Porter for testing this compiler.

Intel ICC on AMD64/EM64T - WARNING!!!

We tested version 9.1 if icc.

debug compile:
icc -ansi -w1 -c -O0 *.c
icc -o cloudy.exe *.o -lm

Note that the -O0 command line option needs to given explicitly since the default level of optimization is -O2, and not -O0 as with other compilers.

optimized compile:
we were not able to get the test suite to pass with any optimization in version 9.1. We were able to get the test suite to pass with -O3 -mp with version 9.0 and before.

We do not recommend icc on AMD64/EM64T. We were able to get the test suite to pass with the low level of optimization shown above: We recommend gcc on this platform - it produces faster working code.

Many thanks to Peter van Hoof for testing this compiler.

Dec/Compac?/HP/??? Alpha

This concerns the native C compiler on Tru64. See the gcc section above if you are using gcc. On a Linux alpha cc is aliased to gcc, and the native compiler is called ccc.

debug compile with bounds checking
cc -g -std1 -trapuv -check_bounds -c *.c
cc -o cloudy.exe *.o -lm

These options will trap uninitialized variables, array bounds overruns, and floating point exceptions (the -check_bounds option may not be supported by older versions of the compiler). This will run considerably more slowly than the following normal compile.

debug compile (normal)
cc -std1 -g -c *.c
cc -g -o cloudy.exe *.o -lm

optimized compile:
cc -std1 -c -fast *.c
cc -o cloudy.exe *.o -lm

In all of these the -std1 option says that the code is ANSI C

We used an alpha to test the code until April 2006. It had a fine compiler, one of the few with native array bounds checking. It will be missed.


debug compile:
cc -ansi -c -w -g -O0 -DEBUG:trap_uninitialized *.c
cc -g -O0 -o cloudy.exe *.o -lm

To include array bounds checking, change the DEBUG statement to the following:

optimized compile:
cc -ansi -c -Ofast -w -TARG:exc_max=OZV -TARG:exc_min=OZV -TENV:X=1 *.c
cc -o cloudy.exe -IPA *.o -lm

I no longer have access to an SGI machine and very few true SGI cpus & compilers still exist. Modern SGI is a vendor for Intel chips and compilers. See the warnings about icc above for notes on this compiler.

RunCode describes how to run the code

Return to StepByStep instructions.

Return to