[OpenMP] OpenMP configuration on Visual Studio and Mac

Source: Internet
Author: User

Today got a half-day to fix the Mac on the OpenMP, on the one hand, the lower IQ, on the other hand unexpectedly found that there is no detailed online process, deliberately put my configuration process to paste up

Multicore programming can be thought of as a degree of abstraction of multithreaded programming, providing some simple APIs that allow users to avoid having to spend too much time understanding the underlying knowledge of multithreading, thus improving programming efficiency. These two days of focused multi-core programming tools include OpenMP and TBB. According to the current discussion on the Internet, TBB has to cover OpenMP, such as OpenCV used to be OpenMP, but from the 2.3 version began to abandon OpenMP, to TBB. But as I try, TBB is a bit more complicated, and in contrast, OpenMP is very easy to get started with. Because of the limited energy and time, there is no way to spend too much time learning TBB, here to share the two-day learning of the OpenMP a little bit of knowledge, and we discuss together.

OpenMP-supported programming languages include C, C + + and Fortran, and the compilers that support OpenMP include the Sun Studio,intel compiler,microsoft Visual STUDIO,GCC.

Configuration of OpenMP on Microsoft Visual Studio

A total of 2 steps:

    • Create a new project. This is not much to say.
    • After building the project, click on the menu bar->project->properties, pop-up menu, click Configuration properties->c/c++->language->openmp Support, select Yes from the drop-down menu. The configuration ends at this point.

Using Clang-omp with Xcode

    • Website for this extension: http://clang-omp.github.io/
    • Install Clang-omp using homebrew:
    • Install Clang-omp
    • Create a new Xcode project.
    • Under Click ' The name of theproject ' Build Settings
      • Editor--Add Build Setting--Add user-defined Setting (Press ' delete ' on the keyboard to delete the user-defined setting if you don't want it)

        • Set the setting name as CC
        • Set its value As/usr/local/bin/clang-omp

      • Add-fopenmp to other C Flags
      • Add/usr/local/include to Header Search Paths
      • Set Enable Modules (C and Objective-c) to No.
    • Under Build phases
      • Add/usr/local/lib/libiomp5.dylib to Link Binary with Libraries
    • Done. You can now #include <libiomp/omp.h> and start using #pragma omp ... in your source code.

The code to test for the success of the compiler and environment configuration is as follows:

 #include <omp.h> #include  <stdio.h> int   Main () {  #pragma  omp parallel  printf (  hello from thread%d, nthreads% d\n   , Omp_get_thread_num (), omp_get_ Num_threads ());}  /*   Output:hello from thread 0, nthreads 4Hello from thread 3, nthreads 4Hello from thread 2, n Threads 4Hello from thread 1, nthreads 4Program ended with exit code:0  */ 

You should see more than one "Hello" line with different thread numbers. Note that the lines is mixed together. If you see only one, try setting the environment variable omp_num_threads to some number (say 4) and try again.

[OpenMP] OpenMP configuration on Visual Studio and Mac

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.