wiki:CompilingCloudyC07

Cloudy 07 - 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 enable_traps (in the file cpu.cpp) that will set the proper floating point environment for nearly all systems. However, not all platforms are covered. Most notably floating point traps will not be enabled on G4/G5 (PowerPC) based 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 TestSuite, 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. The MakefileDescription page describes how to use the make utility to compile Cloudy. A makefile is distributed with Cloudy, which uses features specific to GNU make. It is set up for g++. For other platforms/compilers edit the makefile to use the compiler options listed below.

Warnings with routine ParseCrashDo. This routine contains logic that is designed to cause the code to crash. Good compilers will detect dangerous code and create a warning about the use of an uninitialized variable. 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 (for links to these versions, see SupportLibraries). 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 may do 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 could reveal compiler problems that would go unnoticed otherwise.

Array bounds checking Versions C08 and later have the option to do array bounds checking. This is set with the compiler macro BOUNDS_CHECK - further details will be provided as the release time of this version approaches.

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++, but not version 3.4 (see below). The code is tested with g++ on a regular basis.

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.

Caveats

Starting with the C08 release, Cloudy no longer compiles correctly with g++ compilers from the 3.4.x series due to a serious compiler bug in this series. All g++ versions except 2.96 and 3.4.x will work OK. The compiler will issue an error when you try to compile with a g++ compiler from the 3.4.x series. Linux users with an old installation that contains a g++ 3.4.x compiler will have to upgrade to a newer g++ version, or use another compiler, like e.g. the Sun Studio compiler for Linux. For other UNIX systems you can either use the native compiler, or upgrade to a newer g++ version.

For Cygwin users the situation is more serious. There g++ 3.4.4 is the standard compiler and no newer versions are available. Cygwin users are strongly advised to downgrade their g++ compiler to version 3.3.3 which is being offered by Cygwin as an alternative.

To find out what version of g++ you have, issue the command "g++ -v".

Compiling the code on Itanium platforms may generate many warnings by the assembler that an "additional NOP may be necessary to work around the Itanium processor A/B step errata". These warnings appear to be benign.

Versions before 2.1 of the Linux glibc library 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. This should be OK unless you have a really ancient Linux installation.

debug compile
g++ -ansi -Wall -g -finline -c *.cpp
g++ -o cloudy.exe *.o

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

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

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; also certain versions of g++ on Itanium platforms may have trouble with this flag). If you see failures in the test suite, try recompiling the code without the -funsafe-math-optimizations flag. Usually this will solve the problem.


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 -DBOUNDS_CHECK -g -O2 -c *.cpp
pgCC -o cloudy.exe *.o

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

The -A option detects code that does not conform to the ANSI/ISO C++ standard. It produces many errors concerning header files in the PGI distribution we use. Many thanks to Mitchell Martin for testing this compiler.


Intel icc

We tested versions 9.x and 10.x 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 "-fp-model source -fp-model except -fp-speculation off" flags in order to disable those optimizations. The following options were used:

debug compile:
icc -ansi -w1 -g -O0 -c *.cpp
icc -o cloudy.exe *.o -lstdc++

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

optimized compile (icc 10.0 and later):
icc -ansi -w1 -O3 -fp-model source -fp-model except -fp-speculation off -c *.cpp
icc -o cloudy.exe *.o -lstdc++

optimized compile (prior to icc 10.0):
icc -ansi -w1 -O3 -mp -c *.cpp
icc -o cloudy.exe *.o -lstdc++

The icc 9.0 compiler needs an additional parameter "-O0" during the link stage to disable the multi-file optimizer.

Versions prior to icc 9.0 may not work correctly and require lower levels of optimization ("-O1 -mp" or even "-O0"). Make sure you run the test suite if you use such a compiler.

WARNING: Testing with the upcoming C08 release has shown that icc 10.1 is completely incapable of compiling the code correctly on IA32 platforms (even with -O0!). Use an older version of icc, or g++, or the Sun C++ compiler instead.

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


Sun Studio compiler for Linux

Sun provides a C++ compiler for Linux that can be obtained free of charge from the Sun Download Center. When downloaded as a tarball it has the advantage that it can be installed without any root privileges. It can produce code for both IA32 and AMD64/EM64T platforms. We tested the Sun Studio 12 compiler.

debug compile:
CC -g -ftrap=common -c *.cpp
CC -Yl,/usr/bin -o cloudy.exe *.o

optimized compile:
CC -fast -fnonstd -c *.cpp
CC -Yl,/usr/bin -o cloudy.exe *.o

The -Yl,/usr/bin flag is needed to work around an incompatibility between the (modified) linker supplied by Sun and the object file format in recent Linux distributions. It is only needed on 64-bit systems. See this bug report for further details.


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 - WARNING!!!

This version cannot compile C++ versions of Cloudy. Consider using the updated Visual C++ 2005 Express Edition which Microsoft offers for free at http://msdn.microsoft.com/vstudio/express/visualc/. Setup instructions will follow the full Visual Studio 2005 edition described below.


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. NB - 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. In project / properties / configuration properties / C/C++ / advanced / disable specific warnings enter "4996; 4512".


MAC Darwin

Donglai Gong first ran Cloudy on a Mac. The following is based on his experiences. MacOS X users will first need to download Apple Developer's Tools (free with registration from Apple's developer website) which includes a C++ compiler. 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. Douglai Gong stated that Apple's compiler suite (as of OS X 10.2) is basically the GNU compiler collection, version 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.

As an alternative you can also download the compilers that are included in the Fink project.

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

optimized compile (for PowerPC Mac):
c++ -ansi -c -Wall -no-cpp-precomp -O3 -fno-math-errno -funsafe-math-optimizations *.cpp
c++ -funsafe-math-optimizations -o cloudy.exe *.o

Megan Donahue found that several test cases ended with a seg fault on her G4. This was because the default kernel setup on her machine had a limited stacksize (512k). A solution is to issue the command "limit stacksize unlimited" (in tcsh) or "ulimit -s unlimited" (in bash) before executing Cloudy. That did the trick. The command should be included in the startup file for your shell on all operating systems.

Jane Rigby tested Cloudy on an Intel Mac Running OS X 10.4 with g++ 4.0.1. She found that the standard compilation options for Linux / g++ also work fine on this platform:

optimized compile (for Intel Mac):
g++ -ansi -c -Wall -O3 -fno-math-errno -funsafe-math-optimizations *.cpp
g++ -funsafe-math-optimizations -o cloudy.exe *.o

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


Sun Sparc stations running Solaris

With the Sun Studio compiler use the following options:

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

optimized compile:
CC -fast -c *.cpp
CC -fast -o cloudy.exe *.o

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 Sparc stations

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

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.

The code is tested on an Ultrasparc II 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 entire code with much optimization. We worked very hard to locate the source files which confused the compiler. We 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 the symbol __HP_aCC and you will find all places where we had to disable optimization. You might experiment with turning optimization back on to check if the compiler has been fixed.


IBM pSeries servers based on POWER4 and POWER5 processors

optimized compile:
xlC -O2 -qarch=auto -qtune=auto -c *.cpp
xlC -o cloudy.exe *.o

Performance may be significantly improved if the IBM Mathematical Acceleration Subsystem (MASS) library is used. This is available at http://www-306.ibm.com/software/awdtools/mass and is included by specifying the additional option "-lmass" in the first step.


RunCode describes how to run the code

Return to StepByStep instructions.

Return to nublado.org


Last modified 9 years ago Last modified on 2008-07-18T15:49:45Z