From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI User Group Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Introduction to Open Multi-Processing (OpenMP) for LabWindows/CVI

LabWindows/CVI 2013 Preview: Support for OpenMP

Overview

OpenMP, Open Multi-Processing, is a set of compiler directives and related clauses, an application programming interface (API), and environment variables that allow you to easily create applications that execute on multiple threads. Jointly defined by a group of major computer hardware and software vendors, OpenMP is a portable, scalable model that gives shared-memory parallel programmers a simple and flexible interface for developing parallel applications for platforms ranging from the desktop to the supercomputer.[1]

The OpenMP model allows you to complete the following tasks:

  • Define parallel regions of code and create teams of threads that execute the parallel regions.

  • Specify how to share work among the threads in the team.

  • Declare data that is shared among the threads and data that is private to each thread.

  • Synchronize threads, protect shared data from concurrent access, and define regions that execute by a single thread exclusively.

The compiler directives and associated clauses address the high level work of defining parallel regions, dividing code and loop iterations among threads, and synchronizing work among the threads of a team. The API provides a finer level of control within a parallel region; you can determine and set the number of available threads, set and initialize locks, and more. The environment variables control the execution of the parallel regions at run time.

Goals of OpenMP [2]

  • Standardization:

    • Provide a standard among a variety of shared memory architectures/platforms

    • Jointly defined and endorsed by a group of major computer hardware and software vendors

  • Lean and Mean:

    • Establish a simple and limited set of directives for programming shared memory machines.

    • Significant parallelism can be implemented by using just 3 or 4 directives.

    • This goal is becoming less meaningful with each new release, apparently.

  • Ease of Use:

    • Provide capability to incrementally parallelize a serial program, unlike message-passing libraries which typically require an all or nothing approach

    • Provide the capability to implement both coarse-grain and fine-grain parallelism

  • Portability:

    • The API is specified for C/C++ and Fortran

    • Public forum for API and membership

    • Most major platforms have been implemented including Unix/Linux platforms and Windows

Thread Creation Example

The pragma omp parallel is used to fork additional threads to carry out the work enclosed in the construct in parallel. The original thread will be denoted as master thread with thread ID 0.

Example (C program): Display "Hello, world" using multiple threads. [3]

#include <stdio.h> 
int main(void)
{
     #pragma omp parallel
     printf("Hello, world.\n");
     return 0;
}

LabWindows/CVI 2013 OpenMP Support

Note  The OpenMP Runtime Library is available only in the LabWindows/CVI Full Development System.

While you can use the LabWindows/CVI Multithreaded Library to create multithreaded applications, the benefits of using the OpenMP model include:

  • Implementing OpenMP incrementally within existing code, with minimal re-writing of the code.

  • Preserving the sequential order of the original source code.

  • Minimizing possible programming errors common to multithreaded programming with the structured approach of OpenMP.

  • Porting code to other compilers and operating systems easily.


    Note  Compilers that do not support the OpenMP structure ignore the OpenMP compiler directives. Use the _OpenMP macro to ensure that OpenMP function calls do not result in errors in other compilers that do not support OpenMP.

To utilize OpenMP directives and clauses, variables, and function calls, you must enable OpenMP by selecting Enable OpenMP Support in the Build Options dialog box. If you do not enable OpenMP, LabWindows/CVI ignores all OpenMP directives and clauses, variables, and function calls.

LabWindows/CVI is compliant with the OpenMP 2.5 Specification [4].

References

[1] http://openmp.org/wp/

[2] Lawrence Livermore National Laboratory https://computing.llnl.gov/tutorials/openMP/

[3] Wikipedia article http://en.wikipedia.org/wiki/OpenMP

[4] OpenMP 2.5 Specification http://www.openmp.org/mp-documents/spec25.pdf

National Instruments
Comments
ALC_Mark
Member
Member
on

Will LabWindows/CVI 2013 include example programs using OpenMP?

LuisG
NI Employee (retired)
on

Yes, it will.

mountainting
Member
Member
on

Very Good, Multi-Thread is needed highly in our application

Contributors