Overview
Multicore Programming Fundamentals Whitepaper Series
Multicore Programming Fundamentals Whitepaper Series
Read this whitepaper to learn about the challenges facing today's multicore programmers. Specifically, this document discusses how LabVIEW handles thread synchronization seamlessly, and how visual debugging tools further aid in developing parallel software.
Table of Contents
Overcoming Multicore Programming Challenges with LabVIEW
This paper outlines several challenges facing multicore programmers and highlights features of the National Instruments LabVIEW 8.5 graphical programming environment, which NI designed to make multicore programming simple for engineers, scientists, and graphical system designers. Specifically, this paper discusses designing parallel application architectures, dealing with thread synchronization, and debugging multicore programs.
The Future of Multicore Technology
For years, processor manufacturers have been improving the performance of CPUs by increasing clock speed. The latest trend, however, in processor technology is multiple cores. Essentially, this means manufacturers are packing several CPUs on one chip. Forget about the commercial dual- and quad-core machines currently available - Intel has promised an 80-core machine in the next five years.

Figure 1 - CEO Paul Otellini Showcases Intel's 80 Core Prototype (Courtesy of slashgear.com)
It almost sounds too good to be true - a seemingly endless performance increase to run even the most demanding applications. And with this great increase, just imagine how fast existing programs will run. You might suspect that it is not quite this simple; you would be correct.
Programming applications to run on multicore processors is much tougher than programming for their single-core counterparts. While multiple applications can easily run on different cores, you must meticulously code applications to take advantage of multicore technology. This means that existing applications most likely see little performance increase, if any, when running on a modern multicore machine.
Designing Parallel Code
The first major challenge in programming a parallel application is identifying which sections of a given program can actually run in parallel with each other, and then implementing those sections in code. We can call each piece of code that is able to run in parallel with another piece a thread; therefore, an entire parallel application can be referred to as multithreaded.
Traditionally, text-based programmers have had to explicitly define these threads in their applications using APIs such as OpenMP or POSIX. Because text-based programming is inherently serial in nature, attempting to visualize parallelism in a multithreaded piece of code is difficult. On the other hand, by harnessing the graphical nature of NI LabVIEW, coders can easily visualize and program parallel applications. In addition, LabVIEW automatically generates threads for parallel sections of code, so engineers and scientists with little or no programming background can spend more time problem solving and less time worrying about low-level implementation of their applications.
[+] Enlarge Image
Figure 2 - Comparison of Multithreading in LabVIEW and Text-Based Languages
Thread Synchronization
A second challenge of multicore programming is thread synchronization. With tens or hundreds of threads running in a given application, you must ensure that all these threads work well together. For example, if two or more threads attempt to access a memory location at the same time, data corruption can occur. Clearly, identifying all possible conflicting pieces of code in an application is a daunting task.
By graphically creating a block diagram in LabVIEW, however, you can quickly take a specific task from idea to implementation without considering thread synchronization. Figure 2 shows an application in which both parallel sections of graphical code access a hard disk when writing a file. LabVIEW automatically handles the thread synchronization.
Figure 3 - Simple Application Demonstrating Automatic Thread Synchronization in LabVIEW
Debugging
Most programs do not function perfectly the first time they are executed. This is true for single-core as well as multicore applications. To logically determine where any functional errors occur in a given piece of code, you must rely on debugging tools in the development environment to produce the correct behavior.
Debugging poses a unique challenge in multicore applications. Not only must you trace execution of two pieces of code at once, you must also determine which piece of code is running on which processor. Additionally, if you program multithreaded applications frequently, you must deal with thread swapping and starvation issues, which need to be identified during the debugging process.
LabVIEW contains several features that greatly simplify debugging multicore applications. Specifically, you can use the execution highlighting feature to quickly and easily visualize the parallel execution of a program (LabVIEW is inherently based on data flow). For instance, observe the simple application in Figure 3. When execution highlighting is turned on, you can easily visualize parallel sections of code executing.
Figure 4 - Graphical Execution Highlighting in the LabVIEW Development Environment
In addition, the LabVIEW Real-Time Module provides both deterministic execution on multicore machines and extensive debugging information. New to LabVIEW 8.5, the Real-Time Execution Trace Toolkit allows you to visualize which processor a given thread is running on and to quickly identify issues such as thread starvation and swapping.
Figure 5 - LabVIEW 8.5 Execution Trace Toolkit
Summary
To conclude, multicore-savvy programmers must take into account the unique challenges of multithreading. A few of these challenges include, but are not limited to, parallel application architecture, thread synchronization, and debugging. As the number of cores per processor increases, it is increasingly important to employ correct parallel programming techniques in multithreaded applications.
More Resources on Multicore Programming
Multicore Programming Fundamentals Whitepaper Series
- www.ni.com/multicore
- Differences between Multithreading and Multitasking
- Understanding Parallel Hardware: Multiprocessors, Hyperthreading, Dual-Core, Multicore and FPGAs
- Why Dataflow Programming Languages are Ideal for Programming Parallel Hardware?
- Learn more about NI LabVIEW
Reader Comments | Submit a comment »
Diagrams are unreadable
Enlarge does not work; it simply opens the
diagram into it's own window but keeps the
same size. It's impossible to read the
diagram, let alone the text. And the pdf
version is even worse.
- Chatonda Mtika, Algis Corporation. cmtika@algiscorp.com - Nov 6, 2007
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
