Compiling
Home Up C94.00 Other versions Revision history The future etcetera Acknowledgements Contacts, Mailing list Links Site map, search

 

Home
Up
gcc on alphas
gcc
gcc

 

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. 

Compile options should be set so that the machine throws an exception on division by zero or overflow.  Underflow is inevitable and should not be trapped.  The examples below show how this can be done on various machines. Cloudy has code in the file setfpenv.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.  

A note on aggressive optimization:  If you try to use your compiler's highest optimization levels you will probably 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 then try the tests with the optimized code.  When 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 optimization.  The compiler vendor may repair the bug if you can isolate it down to a few lines of code.  My experience is that aggressive optimization only gains another 5 to 15 percent speedup and is not worth the bother.

makefilesThis page describes how to create a makefile using gcc.  For other platforms edit the makefile to use the compiler options listed below.

A note on routine CrashDo:  This routine contains logic designed to cause the code to crash. It is the implementation of the crash command. Good compilers will detect dangerous code in this routine and create warnings. This is by design, and so OK.

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.

gcc

This is the preferred compiler.  Make sure that you do not have version gcc 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 can'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. Use kgcc, gcc 2.95.x, 3.1, or later.

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.

The compiler warning "CrashDo:  ar1 might be used uninitialized in this function" is expected.

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

In all four command lines shown above the "o" or "O" is the letter "oh" not the number zero.

The code is tested on this platform on pretty regular intervals.

Dec/Compac/??? 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 -lm -Ipath -std1 -g -c *.c
link 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 The code is tested on this platform on pretty regular intervals.

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

Peter van Hoof writes
"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 -DSTD_ASSERT *.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.

The code is tested on this platform on irregular intervals.

SGI

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

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

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

I no longer have access to an SGI machine and so the code has not been tested on this platform in several years.  Good luck.  Please let me know what happens.

HP SDX

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

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

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

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

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.

MAC Darwin

I have never used this system, but Donglai Gong has.  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 being 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

Many thanks to Donglai Gong for testing the code on this platform.

Intel ICC

We have done some preliminary tests with version 7.1 of this compiler.  These suggest that gcc does produce slightly faster code.  The following options were used:

icc -ansi -Xc -c -O3 -tpp6 -xiM -ip -w1 *.c
icc *.o -lm

Many thanks to Peter van Hoof for testing this compiler.

Next step: how to execute the code. 

Hit Counter
Last changed 11/11/03.
Return to the Cloudy Home Page.
Copyright 1978-2003 Gary J. Ferland