title: How to set openMP for Multithreading in ubuntu 12.04 for an openCV project?
body: <p>I want to do multi threading in one of my <code>for loop</code> using <code>#pragma omp parallel</code>. So, i am writing the following code:</p>
  
  <pre><code>#pragma omp parallel for 
  for(int i=0; i&lt;square-&gt;total; i++)
  {
  ......
  }
  </code></pre>
  
  <p>My project have a CMakeList.txt and Makefile. <strong><em>I don't understand, how do i tell the compiler and linker to use openMP?</em></strong></p>
  
  <p><strong>Updates:</strong></p>
  
  <p>I have edited my <code>CMakeList.txt</code> with following code</p>
  
  <pre><code>find_package(OpenMP)
  if (OPENMP_FOUND)
      set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
      set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  endif()
  </code></pre>
  
  <p>and then i did <code>cmake ..</code> and got the following result at terminal:</p>
  
  <p>-- The C compiler identification is GNU</p>
  
  <p>-- The CXX compiler identification is GNU</p>
  
  <p>-- Check for working C compiler: /usr/bin/gcc</p>
  
  <p>-- Check for working C compiler: /usr/bin/gcc -- works</p>
  
  <p>-- Detecting C compiler ABI info</p>
  
  <p>-- Detecting C compiler ABI info - done</p>
  
  <p>-- Check for working CXX compiler: /usr/bin/c++</p>
  
  <p>-- Check for working CXX compiler: /usr/bin/c++ -- works</p>
  
  <p>-- Detecting CXX compiler ABI info</p>
  
  <p>-- Detecting CXX compiler ABI info - done</p>
  
  <p>-- Try OpenMP C flag = [-fopenmp]</p>
  
  <p>-- Performing Test OpenMP_FLAG_DETECTED</p>
  
  <p>-- Performing Test OpenMP_FLAG_DETECTED - Success</p>
  
  <p>-- Try OpenMP CXX flag = [-fopenmp]</p>
  
  <p>-- Performing Test OpenMP_FLAG_DETECTED</p>
  
  <p>-- Performing Test OpenMP_FLAG_DETECTED - Success</p>
  
  <p>-- Found OpenMP: -fopenmp </p>
  
  <p>-- Configuring done</p>
  
  <p>-- Generating done</p>