Showing posts with label OPENMP. Show all posts
Showing posts with label OPENMP. Show all posts

Wednesday, 29 July 2020

OpenMP Lock with Example | How To Use Lock in OpenMP | Thread Synchronization in OpenMP

                    In this post, we will see OpenMP Lock with Example | How To Use Lock in OpenMP | Thread Synchronization in OpenMP

Watch this video to know about OpenMP Lock:




Watch on YouTube: https://www.youtube.com/watch?v=ZXT63uh-YmI

Monday, 27 July 2020

OpenMP Critical Section with Example | How To Synchronize Threads in OpenMP

                   In this post, we will see OpenMP Critical Section with Example | How To Synchronize Threads in OpenMP | openmp critical,openmp critical section with example,openmp critical example,how to synchronize threads,openmp synchronize threads

Blog link for OpenMP Critical Section Example:
https://www.comrevo.com/2016/01/openmp-critical-section-example.html

Watch following video:




Watch on YouTube: https://www.youtube.com/watch?v=5yla68mLVoM

OpenMP Sections | OpenMP Section Example | OpenMP Parallel Sections

                   In this post, we will see OpenMP Sections | OpenMP Section Example | OpenMP Parallel Sections | openmp programs in c,openmp programming,openmp sections,openmp sections example,openmp parallel sections

Blog link for OpenMP Parallel Sections Example:
https://www.comrevo.com/2016/01/openmp-parallel-sections-example.html

Watch this video to know about OpenMP Parallel Sections with Example:




Watch on YouTube: https://www.youtube.com/watch?v=KMEXW2lZ_-0

OpenMP Basics | What is OpenMP | A Simple Example To Create Threads in OpenMP | OpenMP Programming-

                   In this post, we will see OpenMP Basics | What is OpenMP | A Simple Example To Create Threads in OpenMP | OpenMP Programming | openmp parallel programming,openmp tutorial,openmp programs in c,openmp programming,openmp execution model,openmp directives,openmp for loop,openmp basics

Blog link for How To Create Threads using OpenMP API:
https://www.comrevo.com/2016/01/how-to-create-threads-using-openmp-api.html

Watch this video to know basics of OpenMP programming:




Watch on YouTube: https://www.youtube.com/watch?v=B7-Qnu2vZDc

Monday, 20 February 2017

How To Use Lock in OpenMP

                 In this post, we will see OpenMP Lock with Example | How To Use Lock in OpenMP | Thread Synchronization in OpenMP.

                  In last post, we have seen how to use "#pragma omp critical ". In this post, we will see how to use OpenMP Lock.                             
                 Critical section is the region in program where various threads want to access global variables. In OpenMP, we can avoid such race condition among different threads by using Lock.

Watch following video:


                 Lets see a simple C language program (program.c) which uses OpenMP API. Here we will create 300 threads and each thread will try to increment the value of x.


Friday, 19 February 2016

OpenMP Program for Merge Sort

                         In this post, we will see how to implement merge sort concurrently using OpenMP API.
                        OpenMP API is available with gcc/g++ compiler.

Watch following video to know Basics of OpenMP:


Watch following video to know OpenMP Sections which are used to allocate different work to different threads:


                        Go through the following program. Output is given at the end of the program.

Thursday, 18 February 2016

OpenMP Program for Matrix Addition

              In this post, we will see sample program for two matrices addition. For concurrent addition operations, I have used OpenMP API. 
              OpenMP API is available with gcc/g++ compilers. Each thread id can be obtained by calling standard function omp_get_thread_num().  
               Go through the following program. Output is given at the end of the program. 

Tuesday, 26 January 2016

How To Create Threads using OpenMP API

               In this post, we will see What is OpenMP?, Which header file should we include in C/C++ language?, A simple example to create threads,
How to create required number of threads?, How to create multiple threads using "for" loop?, How to allocate different work to different thread?, How to synchronize threads?

Monday, 18 January 2016

OpenMP Critical Section Example

                      In this post, we will see OpenMP Critical Section with Example | How To Synchronize Threads in OpenMP | openmp critical,openmp critical section with example,openmp critical example,how to synchronize threads,openmp synchronize threads.

                     Critical section is the region in program where various threads want to access global variables. In OpenMP, we can avoid such race condition among different threads by using preprocessor directive "#pragma omp critical ". 

Watch following video:



                Lets see a simple C language program (program.c) which uses OpenMP API. Here we will create 300 threads and each thread will try to increment the value of x.

Friday, 15 January 2016

OpenMP Parallel Sections Example

                In this video, we will see OpenMP Sections | OpenMP Section Example | OpenMP Parallel Sections.
                In OpenMP, we can allocate different work to different threads by using sections. We have to use " #pragma omp parallel sections " for the same purpose.
                I have provided simple example, which creates three threads. Each thread does the distinct job. First thread is printing 'X', second thread 'Y' and third thread 'Z'. I am also printing thread ids, so that you can easily understand, threads are different and doing independent job.
                Predefined function omp_get_thread_num() is used to print the thread id. 

Watch following video:



                Go through the following program:

Saturday, 9 January 2016

Concurrent Quicksort Program in C++ using OPENMP

              In this post, we will see how to implement Quick sort algorithm concurrently(parallelly) in C++ language. (For implementation in C language, check http://www.comrevo.com/2015/08/concurrent-quicksort-program-in-c-using-openmp.html) To make it concurrent/parallel, we will use OPENMP API. OPENMP is available alongwith gcc/g++ compiler.

Friday, 1 January 2016

OpenMP Program for Array Addition

                    In this post, we will see sample OpenMP program for array addition (sum). It is the best example to understand how threads are created in OpenMP.
                    Here we will take two one-dimensional arrays, each of size of 5. We will create 5 threads. Each thread will be responsible for one addition operation.
                    In OpenMP, pre-defined preprecessor directive #pragma omp parallel is used to create threads. We can mention the number of threads to be created as a parameter to num_threads(). If you are not mentioning num_threads(), then the number of threads to be created is equal to number of cores in processor. Thread id can be obtained by using predefined function omp_get_thread_num().  

Watch OpenMP Basics with Example in following video:


                    Go through the following program:

Tuesday, 11 August 2015

Concurrent Quicksort Program in C using OPENMP

              In this post, we will see how to implement Quick sort algorithm concurrently(parallelly) in C language. (For implementation in C++, check http://www.comrevo.com/2016/01/concurrent-quicksort-program-in-cpp-using-openmp.html). To make it concurrent/parallel, we will use OPENMP API. OPENMP is available alongwith gcc compiler.

Tuesday, 9 June 2015

OPENMP program to find prime numbers from range 1 to n by parallel processing (multi-threading)

Explanation:
                 In this program, I have used optimized way to find the prime numbers from the range 1 to n. 
                 Logic behind the program is as follows:
       I start with the assumption that all numbers from 1 to n are prime numbers. Then I remove 1 from the list as everyone knows 1 is neither prime nor composite number. Then I take next prime number(say i) and remove all its next multiples from the list. Again I take next prime number and remove its next multiples from the list. I continue this process until, for a next prime number i,  i*i is less than 'n' to avoid repetition. 
                 I have used multi-threading to remove multiples of prime numbers from the list (in this case, an array). 
                 For execution, I have used gcc compiler on operating system Linux. gcc and g++ compiler consists of OPENMP library.  

Watch OpenMP Basics with Example in following video:


Thursday, 14 May 2015

OpenMP program for n-ary search algorithm

Introduction:
            n-ary search algorithm is for searching a number from the given sorted array by dividing the array into n equal parts recursively until we get the required position of required number. Binary search is also a n-ary search with value of n=2.
             In this program, I have used multi-threading to find the n parts of array. Break-up points which separates these parts, I called them 'separators' and their indices are saved in the array 'sep'.

Watch following video to know basics of OpenMP Programming:


             Go through the following program and check the output which I have provided at the end of this post. For this program, I have used gcc compiler on Linux. gcc and g++ compilers, they are consisted of OpenMP library.