Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C++ Data Types
  • C++ Input/Output
  • C++ Arrays
  • C++ Pointers
  • C++ OOPs
  • C++ STL
  • C++ Interview Questions
  • C++ Programs
  • C++ Cheatsheet
  • C++ MCQ
  • C++ Projects
  • C++ Exception Handling
  • C++ Memory Management
Open In App
Next Article:
How to install Zabbix on Linux
Next article icon

OpenMP | Introduction with Installation Guide

Last Updated : 01 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

After a long thirst for parallelizing highly regular loops in matrix-oriented numerical programming, OpenMP was introduced by

OpenMP Architecture Review Board (ARB) on 1997

. In the subsequent releases, the enthusiastic OpenMP team added many features to it including the task parallelizing, support for accelerators, user-defined reductions and lot more. The latest

OpenMP 5.0

release was made in 2018 November.

Open Multi-processing (OpenMP)

is a technique of parallelizing a section(s) of C/C++/Fortran code. OpenMP is also seen as an extension to C/C++/Fortran languages by adding the parallelizing features to them. In general, OpenMP uses a

portable

,

scalable

model that gives programmers a simple and flexible interface for developing parallel applications for platforms that ranges from the normal desktop computer to the high-end supercomputers.

THREAD Vs PROCESS

A process is created by the OS to execute a program with given resources(memory, registers); generally, different processes do not share their memory with another. A thread is a subset of a process, and it shares the resources of its parent process but has its own stack to keep track of function calls. Multiple threads of a process will have access to the same memory.

Parallel Memory Architectures

Before getting deep into OpenMP, let’s revive the basic parallel memory architectures. These are divided into three categories;

  • Shared memory: Shared Memory Architecture OpenMP comes under the shared memory concept. In this, different CPU’s (processors) will have access to the same memory location. Since all CPU’s connect to the same memory, memory access should be handled carefully.
  • Distributed memory: Distributed Memory Architecture Here, each CPU(processor) will have its own memory location to access and use. In order to make them communicate, all independent systems will be connected together using a network. MPI is based on distributed architecture.
  • Hybrid: Hybrid is a combination of both shared and distributed architectures. A simple scenario to showcase the power of OpenMP would be comparing the execution time of a normal C/C++ program and the OpenMP program.

Steps for Installation of OpenMP

  • STEP 1: Check the GCC version of the compiler
    gcc --version

    GCC provides support for OpenMP starting from its version 4.2.0. So if the system has GCC compiler with the version higher than 4.2.0, then it must have OpenMP features configured with it. If the system doesn’t have the GCC compiler, we can use the following command

    sudo apt install gcc

    For more detailed support for installation, we can refer here

  • STEP 2: Configuring OpenMP We can check whether the OpenMP features are configured into our compiler or not, using the command
    echo |cpp -fopenmp -dM |grep -i open

    If OpenMP is not featured in the compiler, we can configure it use using the command

    sudo apt install libomp-dev
  • STEP 3: Setting the number of threads In OpenMP, Before running the code, we can initialise the number of threads to be executed using the following command. Here, we set the number of threads to be getting executed to be 8 threads.
    export OMP_NUM_THREADS=8

Running First Code in OpenMP

C




// OpenMP header
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
 
int main(int argc, char* argv[])
{
    int nthreads, tid;
 
    // Begin of parallel region
    #pragma omp parallel private(nthreads, tid)
    {
        // Getting thread number
        tid = omp_get_thread_num();
        printf("Welcome to GFG from thread = %d\n",
               tid);
 
        if (tid == 0) {
 
            // Only master thread does this
            nthreads = omp_get_num_threads();
            printf("Number of threads = %d\n",
                   nthreads);
        }
    }
}
 
 

Output:

This program will print a message which will be getting executed by various threads.

Compile: 
gcc -o gfg -fopenmp geeksforgeeks.c

Execute:
./gfg



Next Article
How to install Zabbix on Linux

A

Akbar B
Improve
Article Tags :
  • Articles
  • C Language
  • C++
  • Technical Scripter
  • Technical Scripter 2018
Practice Tags :
  • CPP

Similar Reads

  • How To Install Microsoft Edge On Linux?
    Want to set up Microsoft Edge on a Linux system? Linux users may now access Microsoft Edge, which was previously only available on Windows. Microsoft Edge for Linux is simple to download and use as your daily browser, regardless of the distribution you're using—Ubuntu, Debian, or another. Regardless
    4 min read
  • How to Install Drupal in Localhost with XAMPP on Windows?
    Drupal can be understood as a content management framework that helps in building interactive web applications and websites. It is an open-source platform. The development credit for this platform goes to Dries Buytaert. It was initially launched in 2000. It was developed using the PHP programming l
    6 min read
  • Getting Started with CentOS
    CentOS, short for Community ENTerprise Operating System, is a powerful and widely used Linux distribution known for its stability, security, and open-source nature. Derived from the source code of Red Hat Enterprise Linux (RHEL), CentOS has become a popular choice for server environments and enterpr
    7 min read
  • How to install Zabbix on Linux
    A system administrator's duties include network management. Zabbix is a free and open-source monitoring tool for administering and monitoring networks. This software is open-source and free, and it has a tonne of functionality. Zabbix is used to monitor resources in the cloud as well as networks, se
    2 min read
  • How to Install OpenTTD in Ubuntu?
    OpenTTD is an open-source transportation simulation game for Linux, based on the popular game Transport Tycoon Deluxe. It allows players to build and manage transportation networks, including roads, railways, airports, and ports, to transport goods and passengers. The game features a wide range of v
    6 min read
  • How to Install Microsoft Office 2007 on Linux?
    Microsoft Office is the most important tool on the computer. Whatever the operating system is, Microsoft Office is the essential component of the device. This is the package of the popular software. Microsoft has developed this software to easily handle some difficult problems. Microsoft Office mean
    5 min read
  • How to install Kloxo-MR in Linux
    Kloxo-MR is a free web hosting panel available for Linux distributions. The name of the Lxadmin earlier knew it. But in 2017, The Lxadmin name was changed to the name Kloxo-MR. As there was some issue with the name. And also, there was a massive response from the user to change the application's nam
    7 min read
  • How to get started with Garuda Linux?
    Garuda Linux is a recent Linux distro that is primarily based on Arch Linux (a former Linux distribution). This distro was mainly created by keeping performance-centric tasks in mind, such as - Gaming, Video Editing, and Compiling huge amounts of code. Other than this, it also offers easy-to-use fea
    9 min read
  • How to Install Oracle Database 11g on Windows?
    Oracle Database (known as Oracle RDBMS) is a Database Management System produced and marketed by Oracle Corporation. The Most Fundamental and common usage of Oracle Database is to store a Pre-Defined type of Data. It supports the Structured Query language (SQL) to Manage and Manipulate the Data that
    4 min read
  • How to install PuTTY on Ubuntu
    Although PuTTY is a popular SSH client for Windows, it also supports other network protocols including Telnet and rlogin. PuTTY is also used by the system administrators as a Telnet and SSH client. Telnet is a protocol for establishing communication between two or more networked devices, but it was
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences