Using CLion with openmp

Answered

Hi, i'm new to CLion and i have school assignment with openmp.

What should i do in order to use CLion with openmp (Mac OS).

Thank you very much!

2
8 comments

CLion uses CMake as a build system, so you need to configure your CMakeLists.txt to work with OpenMP. Please take a look here: http://stackoverflow.com/a/40534056.

0
Avatar
Permanently deleted user

Thank you I'll try that!

0
Avatar
Permanently deleted user

can you please explain that? does it work with mac???

1

@RR, yes, you can work with OpenMP in CLion on macOS. You need to configure your CMakeLists.txt in the appropriate way. Please see http://stackoverflow.com/a/40534056 as my colleague suggested in the comment above.

-1

This doesn't work on mac. I've even downloaded gcc and switched my compiler to gcc (shown below). I've been wrestling with this for half a day and I can't get clion to recognize openmp.

0

@Sethd63, the compiler you installed is not gcc, it's clang. You can check it using --version in Terminal:

You need to install gcc using Homebrew, for example.

0

 

# On Mac, 

I got it working along with debugger by changing the CMakeLists.txt. Make sure to change line 2 and line # 12 according to your folder name and file name. Clion is smart to detect it. But yeah, please make sure. I spent whole day to find the solution. : D. 

# Also I used the gcc-13 as a compiler which is downloaded from https://formulae.brew.sh/formula/gcc instead of the default clang compiler in Mac.


cmake_minimum_required(VERSION 3.26)
project(Project1 C)

# Specify the path to GCC-13 (replace with your actual path)
set(CMAKE_C_COMPILER /opt/homebrew/bin/gcc-13)

set(CMAKE_C_STANDARD 11)

# Find OpenMP package
find_package(OpenMP REQUIRED)

add_executable(Project1 sequential.c)

# Enable OpenMP support
if (OpenMP_C_FOUND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    target_link_libraries(Project1 PRIVATE ${OpenMP_C_LIBRARIES})
endif ()

1

Shresthapritam7, thank you for sharing! 

This is not directly relevant, but still: please note that gcc-13 is a C compiler. In the “C++ Compiler” field, g++-13 should be specified.

0

Please sign in to leave a comment.