Sun WorkShop Compiler C 5.0 User's Guide

Overview

The MP C compiler generates parallel code for those loops that it determines are safe to parallelize. Typically, these loops have iterations that are independent of each other. For such loops, it does not matter in what order the iterations are executed or if they are executed in parallel. Many, although not all, vector loops fall into this category.

Because of the way aliasing works in C, it is difficult to determine the safety of parallelization. To help the compiler, MP C offers pragmas and additional pointer qualifications to provide aliasing information known to the programmer that the compiler cannot determine.

Example of Use

The following example illustrates the use of MP C and how parallel execution can be controlled. To enable parallelization of the target program, the option can be used as follows:

% cc -fast -xO4 -xautopar example.c -o example

This generates an executable called example, which can be executed normally. For more information see "-xautopar".

Environment Variable

If multiprocessor execution is desired, the PARALLEL environment variable needs to be set. It specifies the number of processors available to the program:

% setenv PARALLEL 2

This will enable the execution of the program on two threads. If the target machine has multiple processors, the threads can map to independent processors.

% example

Running the program will lead to creation of two threads that will execute the parallelized portions of the program.

Keyword

The keyword _Restrict can be used with MP C. Refer to the section "_Restrict Keyword" for details.