Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Jul 23, 2008


Feedback


Yes No

Related Links - Developer Zone

Related Links - Products and Services

Multicore Programming

0 ratings | 0.00 out of 5
Print | PDF

Multicore Programming

Multicore processors present new software challenges that you must overcome to fully take advantage of the processing capabilities in test, control, and embedded design applications. Explore the following resources to learn how you can use graphical programming to multithread your applications, implement parallel programming strategies, and harness the power of dual-core and multicore processors. If you have written parallel programs in G and have a multicore computer, congratulations! You have been successfully developing interactive parallel programs that execute in multicore PC processors.

Figure 1. Interactive Multicore G Program

 

The following sections discuss some multicore programming techniques to improve the performance of G programs.

Data Parallelism

Matrix multiplication is a compute-intensive operation that can leverage data parallelism. Figure 2 shows a G program with eight sequential frames to demonstrate the performance improvement via data parallelism.

Figure 2. Data Parallelism

 

Sequence Frame

Operation Description

First Frame

Generates two square matrices initialized with random numbers

Second Frame

Records start time for single-core matrix multiply

Third Frame

Performs single-core matrix multiply

Fourth Frame

Records stop time of single-core matrix multiply

Fifth Frame

Splits the matrix into top and bottom matrices

Sixth Frame

Records start time for multicore matrix multiply

Seventh Frame

Performs multicore matrix multiply

Eighth Frame

Records stop time of multicore matrix multiply

 

The Create Matrix function generates a square matrix containing random numbers between 0 and 1 whose size is indicated by Size. The Create Matrix function is shown in the adjacent “Creating a Square Matrix” diagram.

Figure 3. Creating a Square Matrix

 

The Split Matrix function determines the number of rows in the matrix and shifts right the resulting number of rows by one (integer divide by 2). This value is used to split the input matrix into the top half and bottom half matrices. The Split Matrix function is shown in Figure 4.

Figure 4. Split Matrix into Top and Bottom

 

The rest of the calculations determine the execution time in milliseconds of the single-core and multicore matrix multiply operations and the performance improvement of using data parallelism in a multicore computer.

 

This program was executed in a dual-core 1.83 GHz laptop. The results are shown in Figure 5. By leveraging data parallelism, the same operation has nearly a 2X performance improvement. You can obtain similar performance benefits with higher multicore processors.

Figure 5. Data Parallelism Performance Improvement

 

Task Pipelining

A variety of applications require you to program tasks sequentially and continually iterate on these tasks. Most notable are telecommunications applications that require simultaneous transmit and receive. The following simple telecommunications example illustrates how you can pipeline these sequential tasks to leverage multicore environments. 

 

Consider this simple modulation-demodulation example where a noisy signal is modulated, transmitted, and demodulated. A typical diagram is shown in Figure 6.

Figure 6. Sequential Tasks

 

Adding a shift register to the loop allows you to pipeline tasks and execute them in parallel in separate cores should they be available. Task pipelining is shown in Figure 7.

Figure 7. Pipelined Tasks

The program shown in Figure 8 times the sequential task and the pipelined tasks to establish its performance improvement when executed in multicore computers. 

Figure 8. Task Pipelining Program Example

 

Figure 9 shows the results of running the above G program in a dual-core 1.8 GHz laptop. Pipelining shows a nearly 2X performance improvement.

Figure 9. Pipelining Performance Improvement

 

Pipelining Using Feedback Nodes

Feedback Nodes provide a storage mechanism between loop iterations. They are programmatically identical to the Shift Registers. Feedback Nodes consist of an Initializer Terminal and the Feedback Node itself.

Figure 10. Feedback Node

 

To add a Feedback Node, right-click on the G programming window and select Feedback Node from the Functions>>Programming>>Structures pop-up menu. You can change the direction of the Feedback Node by right-clicking on the node and selecting Change Direction.

Figure 11. Feedback Node Direction

 

 

The diagram shown in Figure 12 is programmatically identical to the diagram in Figure 7.

Figure 12. Pipelining with Feedback Node

 

Similarly, the diagram in Figure 13 is programmatically identical to that in Figure 8.


[+] Enlarge Image

Figure 13. Pipelining Tasks with Feedback Nodes

 

Related Links

Scientific Computing with Graphical System Design

Scientific Computing with NI LabVIEW

Visualization and Imaging

Introduction to G Programming

Introduction to Curve Fitting

Statistical Analysis

Scripting Languages and NI LabVIEW

 

0 ratings | 0.00 out of 5
Print | PDF

Reader Comments | Submit a comment »

 

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/).