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.cpp) 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.

makefilesThis page describes how to create a dependencies file and Makefile using g++.  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.cpp).  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 "g++ <other compiler options> -DNDEBUG *.cpp" 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.

g++

This is the preferred compiler.  We recommend version 3.1 or later of g++. The code is currently (mid 2006) tested with version 3.4 on a regular basis.

Versions before 2.1 of the g++ 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.  

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

Recent versions of g++ 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.cpp) that will set the proper floating point environment for nearly all systems.  Not all distributions of g++ 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
g++ -ansi -Wall -g -c *.cpp
g++ -o cloudy.exe *.o -lm

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

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

The code is tested with g++ on a regular basis. However it is not feasible to test every version of the code against every version of g++ 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 g++. 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 g++ 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 *.cpp
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 *.cpp
CC -g -o cloudy.exe *.o -lm

optimized compile:
CC -Xc -fast -c *.cpp
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.cpp 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 g++."

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

Optimized compile with g++ on Sun

g++ -ansi -c -O3 -fno-math-errno -funsafe-math-optimizations -Wall *.cpp
g++ -funsafe-math-optimizations *.o -lm

With g++ 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.

HP SDX

This machine uses the Itanium 64 bit processor.

debug compile:
CC -c -g -Aa +e +z -D_HPUX_SOURCE +DD64 *.cpp
CC +FPZO +FPZ -o cloudy.exe *.o -lm

optimized compile
CC -Aa -O -c +z -D_HPUX_SOURCE +DD64 +e *.cpp
CC +FPZO +FPZ -o cloudy.exe *.o -lm

The code was well tested on this platform until Feb 2007.  The HP compiler optimizer was very buggy and could not compile the code with much optimization.  We worked very hard to locate which source files confused the compiler and introduced pragmas to disable optimization in the problematic files.  It is possible that HP will have fixed these bugs after our machine was turned off.  Search the code for preprocessor strings with the symbol "__HP_aCC" and you will find all places where we had to disable optimization.  You might experiment with turning optimization back on if the compiler has been fixed.

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 http://www-306.ibm.com/software/awdtools/mass

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 -Ktrap=fp -Mbounds -g -O2 -c *.cpp
pgCC -o cloudy.exe *.o -lm

optimized compile
pgCC -Ktrap=fp -Munroll -O3 -c *.cpp
pgCC -o cloudy.exe *.o -lm

Many thanks to Mitchell Martin for testing this compiler.

Pathscale EKOPath compiler - WARNING!!!

This compiler can produce code for both IA32 and AMD64/EM64T platforms.

debug compile:
pathCC -c -g -Wall *.cpp
pathCC -o cloudy.exe *.o

optimized compile:
We were not able to get the test suite to pass with any optimization using version 2.3.1 of the compiler either in 32-bit or 64-bit mode.

We do not recommend using the Pathscale EKOPath compiler on either IA32 or AMD64/EM64T platforms. We were able to get the test suite to pass only with the low level of optimization shown above. We recommend g++ on these platforms.

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 *.cpp
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 *.cpp
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 of icc.

debug compile:
icc -ansi -w1 -c -O0 *.cpp
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 g++ on this platform - it produces faster working code. 

Many thanks to Peter van Hoof for testing this compiler.

Next step: execute the code. 

Hit Counter
Last changed 02/18/07.
Return to the Cloudy Home Page.
Copyright 1978-2006 Gary J. Ferland