Skip to content

Instantly share code, notes, and snippets.

@munckymagik
Created August 31, 2019 07:20
Show Gist options
  • Save munckymagik/7512b5d731f76538f8b19e3c7dd03dfc to your computer and use it in GitHub Desktop.
Save munckymagik/7512b5d731f76538f8b19e3c7dd03dfc to your computer and use it in GitHub Desktop.
Trying out OpenMP
# 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})
#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