## Overview

Parallel raytracer / renderer that demonstrates the use of parallel_for.

This example includes software developed by John E. Stone. See here for copyright information.

This example is a 2-D raytracer/renderer that visually shows different parallel scheduling methods and their resulting speedup. The code was parallelized by speculating that each pixel could be rendered in parallel. The resulting parallel code was then checked for correctness by using Intel® Thread Checker, which pointed out where synchronization was needed. Minimal synchronization was then inserted into the parallel code. The resulting parallel code exhibits good speedup.

The following versions of the example are provided:

serial
  Original sequential version.
tbb1d
  Parallel version that uses Threading Building Blocks and blocked_range to parallelize over tasks that are groups of scan-lines.
  - By default, this version uses one thread per available processor. To change this default, set the TBB_NUM_THREADS environment variable to the desired number of threads before running.
  - This version uses the preview feature: auto_range_partitioner. No grain size is provided to blocked_range. The blocked_range class uses a default grain size of 1 when none is provided. However, the auto_range_partitioner controls the amount of range splitting dynamically at runtime, resulting in sub-ranges of varying sizes.
tbb
  Parallel version that uses Threading Building Blocks and blocked_range2d to parallelize over tasks that are rectangular sub-areas.
  - By default, this version uses one thread per available processor. To change this default, set the TBB_NUM_THREADS environment variable to the desired number of threads before running.
  - This version uses a reasonable task grain size by default. To change this default, set the TBB_GRAINSIZE environment variable to the desired grain size before running. The grain size corresponds to the number of pixels (in the X or Y direction, for a rectangular sub-area) in each parallel task.

## Files

src/video.cpp
  Source code for main program and GUI interfaces.
src/trace.serial.cpp
  Source code for original sequential version of example.
src/trace.tbb1d.cpp
  Source code for Threading Building Blocks blocked_range (scan-line) version of example.
src/trace.tbb.cpp
  Source code for Threading Building Blocks blocked_range2d (rectangular sub-area) version of example.
(src/*.cpp)
  Remainder of source code for example.
(src/*.h)
  Remainder of include files for example.
Makefile
  Makefile for building example.

## Directories

src
  Contains source code and include files for the example.
dat
  Contains data sets for running the example.
msvs
  Contains Microsoft* Visual Studio* 2005 workspace for building and running the example.
xcode
  Contains Xcode* IDE workspace for building and running the example.

## To Build

General build directions can be found here.

For Windows* systems, Microsoft* Visual Studio* projects are provided for each of the above versions.

The Makefile supports the following build targets (in addition to the general ones). Here, <version> is one of the above versions of the example, i.e., {serial, tbb1d, tbb}.

`make <version>[_debug]`
  Build and run a single version (release or debug). Equivalent to 'make build_<version>[_debug] run_<version>'.
`make build_<version>[_debug]`
  Compile and link a single version (release or debug). The resulting executable is left in the directory for the example.
`make run_<version>`
  Run a single version previously produced by one of the above commands.
`make [(above options or targets)] DATASET={820spheres, balls, balls3, lattice, model2, teapot, trypsin4pti}`
  Build and run as above, but run with the specified data set.
`make [(above options or targets)] ARGS=-D`
  Build and run as above, but run with disabled run-time display updating for use in making performance measurements (strongly recommended when measuring performance or scalability; see note below).
`make [(above options or targets)] UI={con, gdi, dd, x, mac}`
  Build and run as usual, but build with the specified GUI driver: console, GDI+*, Direct Draw*, X11, or OpenGL* (see the description of the common GUI code for more information on available graphics support). For Linux* and Mac OS* X systems, the best available driver is detected automatically by the Makefile. For Windows* systems, UI=gdi is the default GUI driver; compiling with UI=dd may offer superior performance, but can only be used if the Microsoft* Direct Draw* SDK is installed on your system and if overlay is supported by your graphics card. Use UI=con to build without the GUI for use in making performance measurements (strongly recommended when measuring performance or scalability; see note below).
`make [(above options or targets)] XARCH=x64`
  Build and run as above, but also specify XARCH=x64 (or XARCH=AMD64 for older compilers) when building the example on Windows* as a 64-bit binary.
`make [(above options or targets)] DDLIB_DIR=<specify path to library directory of Direct Draw* SDK here>`
  If you experience ddraw.lib linking problems, specify the correct library directory via this option.

## Usage

Building via the above make commands, or via Visual Studio projects on Windows* systems, produces executable files named tachyon.<version>.exe. To run these executables directly, use one or more of the following commands.

`tachyon.<version>.exe <dataset>`
  Run this version (release or debug), where <dataset> is the path/name of one of the *.dat files in the dat directory for the example.
`tachyon.<version>.exe -D <dataset>`
  Run this version (release or debug), but run with disabled run-time display updating for use in making performance measurements (strongly recommended when measuring performance or scalability; see note below).
To run a short version of this example, e.g., for use with Intel® Threading Tools:
  Build a debug version of the `tbb` example with the GUI turned off (e.g., `make UI=con tbb_debug`; see also the build directions above).
  Run it with a small dataset, e.g., `tachyon.tbb.exe -D dat/820spheres.dat`.

## Notes

- While running with the GUI display turned on should yield reasonable performance in most cases, running with the GUI display turned off is strongly recommended in order to demonstrate the full performance and scalability of the example.
- If using the X-windows (X11) GUI on Mac OS* X systems, X11 might not be installed on the system by default. To install X11 on Mac OS* X systems, use the operating system install disk, choose "Optional installs" and select X11 from the "Applications" list. Alternatively, if X11 is not available, build without the GUI (see build targets above).

Up to parent directory

Copyright © 2005-2010 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.

The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.