Created
August 31, 2019 07:20
-
-
Save munckymagik/7512b5d731f76538f8b19e3c7dd03dfc to your computer and use it in GitHub Desktop.
Trying out OpenMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic CMake project | |
cmake_minimum_required(VERSION 2.8.11) | |
# Name the project after the exercise | |
project(omptryout CXX) | |
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include") | |
set(OpenMP_CXX_LIB_NAMES "omp") | |
set(OpenMP_omp_LIBRARY "/usr/local/opt/libomp/lib/libomp.dylib") | |
find_package(OpenMP REQUIRED) | |
set(CMAKE_CXX_FLAGS ${OpenMP_CXX_FLAGS}) | |
add_executable(omptryout omptryout.cpp) | |
target_link_libraries(omptryout ${OpenMP_CXX_LIBRARIES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <omp.h> | |
#include <cstdio> | |
int main() { | |
puts("Starting..."); | |
omp_set_num_threads(4); | |
#pragma omp parallel | |
{ | |
int ID = omp_get_thread_num(); | |
printf(" hello(%d) ", ID); | |
printf(" world(%d) \n", ID); | |
printf("Num threads; %d\n", omp_get_num_threads()); | |
printf("Max threads; %d\n", omp_get_max_threads()); | |
} | |
puts("Done..."); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment