Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Gastón Hillar

Dr. Dobb's Bloggers

Alice 3: Visualize Concurrent Code in Action

June 08, 2011

Carnegie Mellon University announced the beta release of Alice 3 in 2009. Almost two years later, this educational development environment is still in beta. However, the latest version is pretty stable and provides visual tools to teach students to think parallel.

It is easy to conceptualize that you need code running in parallel in order to show many actors performing actions concurrently. Think about two hares running a race. Which is the most natural way of coding the desired behavior for each hare? Figure 1 shows two instances of the Hare class on a grassy background as shown by the Alice 3 scene editor and its starting camera view.

[Click image to view at full size]
Figure 1: Two hares in the Alice 3 scene editor.

Each hare might have different energy and speed values. Each hare has to run using its own speed value while considering its remaining energy. In addition, each hare wants to win the race, and therefore, it will consider its rival's position to determine its necessary effort in each stage of the race. If you think in object-oriented code, each hare will use its own properties to animate its body and to advance positions in the 3D space.

The main code has to run some sort of loop in order to update the position for each hare. If each hare has a method that encapsulates the algorithm that updates its position, you might want to call the method for each hare in parallel. Think about real life: Each real hare would execute actions in parallel because the real world doesn't have a sequential execution. Thus, if you want to create animations that represent situations of the real world in virtual environments, the easiest way to code them is by creating blocks of code that run in parallel.

Alice 3 provides three blocks that allow you to organize statements to run in parallel (see Figure 2):

  • Do together: Run many statements or blocks of statements in parallel.
  • Each in _ together : For each object in the specified array of objects, run many statements or blocks of statements in parallel.
  • Do in thread: Run many statements in an independent thread that will execute concurrently with the main thread and other threads.

[Click image to view at full size]
Figure 2: Blocks that allow you to organize statements in Alice 3 visual code editor.

Alice 3 allows you to combine the aforementioned three blocks with other blocks that organize the sequential execution of statements. Thus, you can use a do together block to run two do in order blocks in parallel. Figure 3 shows a simple example of two do in order blocks that create sequential code that will run in parallel because they are included in a do together block. With just a few clicks, you can make two hares move toward the camera and orient to the sunlight in parallel.

[Click image to view at full size]
Figure 3: Two blocks of sequential code organized to run in parallel in the Alice 3 visual code editor.

You can run code in different threads and you can teach students to think parallel with Alice 3. Alice 3 doesn't include synchronization mechanisms and The Sims module still has a few significant bugs. However, once students learn the difference between sequential and parallel executions with actors moving on the rendered scenes, it is easier to understand more complex threads.

My wife has been using Alice 3 during the last year in the classroom, and she has been working with colleagues on the design of simple programs that run code in parallel by using different threads. (and yes, of course, she helped me in writing this post). I've been amazed with the results. Students learn to create and organize concurrent code because Alice 3 makes it easy to mix parallel code with sequential code. Students understand the complexities of parallelized code, visualize the problems, and can switch to more complex programming languages. If you want to create virtual worlds with actors performing actions in parallel, you will love Alice 3.

There are dozens of excellent books about Alice, and a couple bear mentioning here. Learning to Program with Alice, by Wanda P. Dann, Stephen Cooper, and the late Randy Pausch (Prentice Hall, 3rd Edition, 2011), is a must read if you want to understand the Alice programming language; and the book includes a sneak peek at Alice 3. The Alice 3 Cookbook, by Vanesa S. Olsen (Packt Publishing, 2011) includes dozens of exercises that combine sequential execution with parallel execution for Alice 3. As a disclaimer, I must note that Vanesa is my wife.

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.