Channels ▼
RSS

Parallel

RapidMind: C++ Meets Multicore

Source Code Accompanies This Article. Download It Now.


Control Flow

The Julia set program also illustrates control flow. The main computation encapsulated in the program object, a complex multiplication and addition, is repeated until a maximum number of iterations is reached or the norm of the complex number grows greater than four. Because the latter condition depends on a computation being performed in the program object, we cannot simply include a C++ for loop here. The for loop would attempt to determine the value of std::norm(z) < 4.0f as a bool, but the value of z is not yet determined because the program is merely being collected, not executed. You can use C++ for loops in program definitions, but their conditions need to be based on nonRapidMind types. For example, it's possible to run a loop that iterates a constant number of times and that unrolls the RapidMind computations it contains.

RapidMind does allow dynamic control flow in programs using constructs such as RM_FOR, RM_IF, and RM_WHILE. These constructs generally behave like their C++ counterparts, but are collected into the program. By letting you use control constructs, RapidMind exposes a Single Program Multiple Data (SPMD) programming model, as opposed to a Single Instruction Multiple Data (SIMD) model. This is one of the reasons why RapidMind has an explicit Program object. In systems where basic operations would be executed on arrays and those operations collected into program objects implicitly, control flow is difficult or impossible to express, reducing the generality of the programming model as well as posing performance problems.

The platform provides a number of other operations that let you express almost any kind of computation. In addition to functions and operators that can be used on values, the platform provides operations that affect entire arrays. For example, array contents can be rearranged using "access patterns" and "collective computations" over an entire array, so that finding the sum of all entries can be accomplished. Table 1 lists some of the types and functions.

Feature Description
Types Value, Array, Program, Bundle, Matrix, Exception, ...
Arithmetic +, -, *, /, %, ...
Trigonometric & Exponential sin, atan2, exp10, pow, ...
Geometry dot, cross, distance, ...
Logical <, >, &&, ||, cond, all, any, ...
Miscellaneous lerp, join, cast, ...
Control Flow RM_FOR, RM_IF, RM_WHILE, RM_DO, ...
Array Access [], (), read_data, boundary, adopt_array, ...
Access Patterns take, offset, shift, slice, ...
Virtual Arrays grid, dice, ...
Collective reduce, sum, min, max, count, exists, ...

Table 1: Some types and functions.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video