Skip to content

Commit

Permalink
Added OpenMP directives to cpp backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
GPMueller committed Jul 30, 2017
1 parent 68d03f5 commit 739e8a0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
30 changes: 29 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ MESSAGE( STATUS ">> ------------------------------------------------------------
MESSAGE( STATUS ">> --------------------- Backends ------------------------------------- <<" )

######### CMake Version #####################
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
### We need at least C++11
set (CMAKE_CXX_STANDARD 11)
### Distinction between Clang and AppleClang
cmake_policy(SET CMP0025 NEW)
#############################################


Expand Down Expand Up @@ -33,11 +37,17 @@ set(BACKENDS_META_VERSION "${META_VERSION}" PARENT_SCOPE)
set(BACKENDS_META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})" PARENT_SCOPE)
#############################################


######### Project Name ######################
project(${META_PROJECT_NAME} VERSION ${BACKENDS_META_VERSION})
#############################################


# #############################################
# SET( BACKENDS_USE_CUDA OFF CACHE BOOL "Use CUDA to speed up certain parts of the code." )
SET( BACKENDS_USE_OPENMP OFF CACHE BOOL "Use OpenMP to speed up certain parts of the code." )
# #############################################


# ######### CUDA decisions ####################
# if ( BACKENDS_USE_CUDA )
Expand All @@ -51,6 +61,24 @@ project(${META_PROJECT_NAME} VERSION ${BACKENDS_META_VERSION})
# #############################################


#############################################
if ( BACKENDS_USE_OPENMP )
include( FindOpenMP )
if( OPENMP_FOUND )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}" )
message( STATUS ">> OpenMP found." )
message( STATUS ">> OpenMP C Flags: ${OpenMP_C_FLAGS}" )
message( STATUS ">> OpenMP CXX Flags: ${OpenMP_CXX_FLAGS}" )
message( STATUS ">> OpenMP EXE Linker Flags: ${OpenMP_EXE_LINKER_FLAGS}" )
else( OPENMP_FOUND )
message( STATUS ">> WARNING: OpenMP could not be found." )
endif( OPENMP_FOUND )
endif( )
#############################################


######### Where to search for library headers
include_directories( ${PROJECT_SOURCE_DIR} )
#############################################
Expand Down
6 changes: 5 additions & 1 deletion backends/cpp/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace backends
template<typename T>
void fill(vector<T>& vec, const T& val)
{
std::fill(vec.begin(), vec.end(), val);
#pragma omp parallel for
for (unsigned int i = 0; i<vec.size(); ++i)
{
vec[i] = val;
}
}
}
1 change: 1 addition & 0 deletions backends/cpp/reduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace backends
T sum(vector<T>& vec)
{
T ret = 0;
#pragma omp parallel for reduction(+:ret)
for (unsigned int i = 0; i<vec.size(); ++i)
{
ret += vec[i];
Expand Down

0 comments on commit 739e8a0

Please sign in to comment.