GithubHelp home page GithubHelp logo

parallel-programming's Introduction

OpenMP Fundamentals

Basic Usage

  • Include OpenMP library: #include <omp.h>
  • Begin compiler directive using: #pragma omp <construct> <clause()>
  • Compile using g++ -fopenmp -o main main.cpp or any other compatible compiler equivalent.
  • Most omp constructs apply to the immediate next structured block.
  • It is ok to have an exit() in a structured block.

Concepts

  1. OpenMP is a multi-threading, shared address model. This means that threads communicate by *sharing variables.
  2. Unintended sharing of data causes race conditions: when the program's outcome changes as the threads are scheduled differently. (the threads "race" against each other to modify the same variable)
  3. To control race conditions: use synchronization to protect data conflicts.
  4. BUT synchronization is expensive, so it is better to change how data (certain variables) is accessed to minimize the need for synchronization.
    • using data sharing attribute clauses such as - default(none) private(x) firstprivate(x) lastprivate(x) shared(x) reduction()
  5. For inevitable synchronization, use synchronization clauses - critical() atomic() ordered() barrier() nowait()
  6. To specify limits on threading, use scheduling clauses - schedule(type, chunk) where type can be static, dynamic, or guided
  7. Datacopying
  8. flush and master
  9. Multithreading explained:
    • A method of parallelizing where a primary thread (thread ID: 0) is forked into subthreads, then the system divides the task among them. These threads run concurrently, where the runtime environment allocated threads to different processor cores.
    • At completion of the parallelized code, the threads join back together into the primary thread, after which it resumes the program on that single thread.
    • Threads are allocated to processors during runtime depending on usage, machine load, and other factors.

image

Sources

parallel-programming's People

Contributors

jeesooxkim avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.