TSGL: A Thread-Safe Graphics Library for Creating Multithreaded Visualizations

advertisement
TSGL: A Thread-Safe Graphics Library for Creating Multithreaded Visualizations
Joel Adams, Patrick Crain, Mark Vander Stel, Dept of Computer Science, Calvin College
https://github.com/Calvin-CS/TSGL
Abstract
Methods
Examples
Mandelbrot set with eight threads
Intermediate
Thanks to the ACM/IEEE CS Curriculum
2013 recommendations, parallel computing
is now in the undergraduate core computer
science (CS) curriculum. CS educators thus
face a new challenge: teaching parallel
computing concepts to undergraduates. One
way to meet this challenge is to create
parallel programs that use real-time graphics
to help students visualize the program’s
underlying parallel behavior.
Dependencies:
TSGL was built on top of OpenGL using GLFW
[1] as the window manager. It uses to libpng [2]
and libjpeg [3] to load images.
TSGL UML Diagram:
•  Provide a simple abstraction by which multiple threads
can draw to the screen in real-time.
•  Make all methods thread safe in C++11, OpenMP, etc.
•  Support drawing points, lines, shapes, …, plus the
manipulation of PNG, JPG, and BMP images.
•  Provide an easy mechanism for drawing and plotting
on Cartesian coordinate systems.
cos(x)dx
−1.5 π
Above: Cosine integration with 8 threads partway
through their computations, each thread coloring its
piece of the area with a different color in real-time.
Above: The Mandelbrot set being drawn by 8 threads;
threads 0, 1, 6, and 7 are finished; 2, 3, 4, and 5 are not.
Below: The same figure: after all threads finish, each
draws a different-colored bounding box around its piece
of the figure, outlining its contribution.
Completed
Below: The same figure, all threads finished.
Completed
Interfaces:
•  A Canvas class provides a window to draw on.
•  A CartesianCanvas class (a subclass of Canvas)
simplifies the task of plotting functions on a
Cartesian coordinate system.
•  A Shape class hierarchy includes subclasses for
the various shapes that can be drawn.
•  A Function class hierarchy includes subclasses
for commonly-used functions.
•  Provide simple tools to time a computation.
•  Permit simple extension of the Canvas and Shapes
classes for any type of drawing or image manipulation.
•  A Color class facilitates giving each thread a
distinct color for drawing.
CSinParallel.org
Intermediate
∫
•  A Timer class facilitates delaying a thread for a
specified interval, to slow the rendering
sufficiently to visualize the actions of individual
threads.
•  Use a separate thread for rendering to avoid blocking a
computation’s main thread.
Cosine integration with eight threads
+1.5 π
TSGL is a free, platform-independent C++
graphics library designed to make it easier
for anyone to create visual representations of
multithreaded behavior. The library provides
2D Canvas classes within which different
threads can safely manipulate different parts
of a digital image, and/or draw shapes using
different colors. The library can thus be used
to extend a multithreaded application with a
visualization that shows what each thread is
contributing to the problem’s solution. The
library includes several examples (e.g.,
image-processing, the Mandelbrot set, etc.)
that illustrate its use.
Objectives
In figures like the Mandelbrot set (right) and
numerical integration (below), different threads
can show their contribution to the computation.
In a figure showing four Langton’s ants, each
ant’s trail is drawn by a different thread:
Langton’s ants with four threads
Conclusions
TSGL provides an easy-to-use library for creating
2D visualizations of parallel computations, using
real-time rendering to show how different threads
are performing different parts of the computation.
References
[1] GLFW: http://www.glfw.org/
[2] libpng: http://www.libpng.org/pub/png/libpng.html
[3] libjpeg: http://libjpeg.sourceforge.net/
This work made possible by NSF DUE #1225739.
Download