NERSC logo National Energy Research Scientific Computing Center
  A DOE Office of Science User Facility
  at Lawrence Berkeley National Laboratory
 
PackagePlatformVersionModule Docs
VAC/C++ seaborg 5.0.2.7 xlc/5.0.2.7  Vendor
VAC/C++ seaborg 6.0.0.4 xlc  Vendor
VAC/C++ seaborg 6.0.0.5 not needed  Vendor
(*) Denotes limited support

IBM C/C++ Compilers

This describes the IBM implementation of the C and C++ compilers on Seaborg.

Contents

Related Information


Invoking the Compiler

The IBM C compiler is described in the IBM C for AIX User's Manual and the IBM C++ compiler is described in the IBM Visual Age C++ Batch Compiler manual. Both of these manuals are on line.

As with the IBM XL Fortran compiler, there are several different commands that invoke the C or C++ compilers, each of which is really an alias for the main C or C++ command packaged with a set of commonly used options.

The most basic C compile is of the form

% xlc source.c

This will produce an executable named a.out. The other C Compiler modes are described below in the section C Compiler Modes.

The most basic C++ compile is of the form

%	xlC source.C

This will produce an executable named a.out. The other C++ Compiler modes are described below in the section C++ Compiler Modes.

Note: There is no on-line man page for the C++ compiler on the SP. "man xlC" brings up the man page for the C compiler. For complete documentation of C++ specific options and conventions see the on-line C++ manual. The commands xlc, mpcc, and mpCC all have on-line man pages on the SP.

C Compiler Modes

There are four basic compiler invocations for C compiles: xlc, cc, c89, and mpcc. All but c89 have one or more subinvocations with different defaults.

xlc

xlc invokes the compiler for C with an ansi language level. This is the basic invocation that IBM recommends.

These are the two most useful subinvocations of xlc:

xlc_r

This invokes the thread safe version of xlc. It should be used when any kind of multi-threaded code is being built. This is equivalent to invoking the compiler as xlc -D_THREAD_SAFE and the loader as xlc -L/usr/lib/threads -Lusr/lib/dce -lc_r -lpthreads.

xlc128

This is equivalent to invoking the compiler as xlc -qldbl128 -lC128. It increases the size of long double data types from 64 to 128 bits.

cc

cc invokes the compiler for C with an extended language level. This is for source files with legacy C code that IBM refers to as "RT compiler extensions". This include older pre-ansi features such as those in the Kernighan and Ritchie's "The C Programming Language".

The two most useful subinvocations are cc_r which is the cc equivalent of xlc_r and cc128 which is the cc equivalent of xlc128.

c89

c89 should be used when strict conformance to the C ANSI ANSI standard (ISO/IEC 9899:1990) is desired. There are no subinvocations associated with this compiler invocation.

mpcc

mpcc is a shell script that compiles C programs with the cc compiler while linking in the Partition Manager, Message Passing Interface (MPI), and/or Message Passing Library (MPL). Flags are passed by mpcc to the xlc command, so any of the xlc options can be used with mpcc as well. When mpcc is used to link a program the Partition Manager and message passing interface are automatically linked in. The script creates an executable that dynamically binds with the message passing libraries.

There is one subinvocation with mpcc, mpcc_r which is the mpcc equivalent of cc_r. This invocation also links in the Partition Manager, the threaded implementation of Message Passing Interface (MPI), and Low-level Applications Programming Interface (LAPI).

ANSI compliance can be achieved by compiling with the option -qlanglvl=ansi.

Compiler summary

This table summarizes the features of several different C compiler invocations:

Compiler Name Functionality
C defaults DM Parallel SM Parallel
xlcansiNoNo
xlc_ransiNoYes
xlc128ansiNoNo
ccextendedNoNo
cc_rextendedNoYes
cc128extendedNoNo
c89strictNoNo
mpccextended*YesNo
mpcc_rextended*YesYes
* ANSI compliance can be achieved by compiling with the option -qlanglvl=ansi.

In the table above, C defaults indicates the default C standards behavior of the compiler.

DM Parallel refers to distributed-memory parallelism through the MPI library.

SM Parallel refers to shared-memory parallelism, available through OpenMP, IBM tasking directives, automatic parallelization by the compiler, or the pthreads API.

C++ Compiler Modes

There are two basic compiler invocations for C++ compiles: xlC and mpCC. If a program consists of source code modules in different program languages, it must be linked with a form of one of these invocations in order to use the correct C++ run time libraries.

All of the C++ invocations will compile source files with a .c suffix as ansi C source files unless the -+ option to the C++ compiler is specified. Any of the C compiler invocations will also compile a file with the appropriate suffix as a C++ file.

xlC

Among the subinvocations of xlC are:

  • xlC_r: the xlC equivalent of xlc_r
  • xlC128: the xlC equivalent of xlc128
  • xlC128_r: this combines the features of the xlC_r and xlC128 subinvocations.

mpCC

mpCC is a shell script that compiles C++ programs with the xlC compiler while linking in the Partition Manager, Message Passing Interface (MPI), and/or Message Passing Library (MPL). Flags are passed by mpCC to the xlC command, so any of the xlC options can be used on the mpCC shell script. When mpCC is used to link a program the Partition Manager and message passing interface are automatically linked in. The script creates an executable that dynamically binds with the message passing libraries.

There is one mpCC subinvocation, mpCC_r. This invokes a shell script that compiles C++ programs while linking in the Partition Manager, the threaded implementation of Message Passing Interface (MPI), and Low-level Applications Programming Interface (LAPI).

Source Files and Preprocessing

All of the C and C++ compiler invocations process assembler source files and object files as well as preprocessing and compiling C and C++ source files. Unless the -c option is specified, they also call the linkage editor to produce a single executable object file.

All invocations of the C or C++ compilers follow these suffix conventions for input files:

  • .C, .cc, .cpp, or .cxx - C++ source file.
  • .c - C source file
  • .i - preprocessed C source file
  • .so - shared object file
  • .o - object file for ld command
  • .s - assembler source file

By default, the preprocessor is run on both C and C++ source files.

Default Datatype Sizes

These are the default sizes of the standard C/C++ datatypes on the SP.

Type Length (bytes)
bool11
char1
wchar_t12
short 2
int 4
long 4 /8 2
float 4
double 8
long double 8 /163
1C++ only.
264 bit mode -q64.
3 128 suffix compiling mode.

Distributed-Memory Parallelism

Invoking any of the compilers starting with "mp" enables the program for running across several nodes of the SP. Of course, you are responsible for using a library such as MPI to arrange communication and coordination in such a program. Any of the mp compilers sets the include path and library paths to pick up the MPI library.

To use the MPI with C++ or to use the MPI I/O subroutines, the thread-safe version of the compiler must be used.

% mpcc_r a.c
% mpCC_r -cpp a.C

The example, hello.c, demonstrates the use of MPI from a C code.

The example, hello.C, demonstrates the use of MPI from a C++ code.

Shared-Memory Parallelism

The IBM C and C++ compilers support a variety of shared-memory parallelism.

OpenMP

OpenMP directives are fully supported by the IBM C and C++ compilers when one of the invocations with _r suffix is used. See Using OpenMP on seaborg for details.

Automatic Parallelization

The IBM C compiler will attempt to automatically parallelize simple loop constructs. Use the option "-qsmp" with one of the _r invocations:

% xlc_r -qsmp a.c

64 Bit Addressing

Both the IBM C and C++ compilers can support 64 bit addressing through the -q64 option. Using this option causes all pointers to be 64 bits in length and increases the length of long datatypes from 32 to 64 bits. It does not change the default size of any other datatype. The default mode for both compilers is 32 bit addressing.

The following points should be kept in mind if -q64 is used:

  • If you have some object files that were compiled in 32-bit mode and others compiled in 64-bit mode the objects will not bind. You must recompile to ensure that all objects are in the same mode.
  • Your link options must reflect the type of objects you are linking. If you compiled 64-bit objects, you must also link these objects with the -q64 option.

Optimization

The default for all IBM compilers is for there to be no optimization. The NERSC/IBM recommended optimization options for both C and C++ compiles are -O3 -qstrict -qarch=pwr3 -qtune=pwr3.

There is a discussion of compiler optimization options at IBM Compiler Optimization Flags.


LBNL Home
Page last modified: May 17 2004 14:04:13.
Page URL: http://www.nersc.gov/nusers/resources/software/ibm/xlc.php
Contact: webmaster@nersc.gov
Privacy and Security Notice
DOE Office of Science