Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenMP SIMD pragmas to some loops #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/openmp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: OpenMP SIMD

on: [push, pull_request]

env:
# The CMake build type
BUILD_TYPE: Release

jobs:
build:
strategy:
fail-fast: false
matrix:
float: [ON, OFF]

name: OpenMP SIMD Build - ${{ matrix.float == 'ON' && 'single' || 'double' }}
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v2
with:
submodules: 'recursive'

- name: Setup Environment
run: cmake -E make_directory ${{ runner.workspace }}/build

- name: Configure
shell: bash
working-directory: ${{ runner.workspace }}/build
run: cmake --warn-uninitialized -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DQDLDL_UNITTESTS=ON -DQDLDL_FLOAT=${{ matrix.float }} -DCOVERAGE=OFF -DQDLDL_ENABLE_OPENMP_SIMD=ON $GITHUB_WORKSPACE

- name: Build
shell: bash
working-directory: ${{ runner.workspace }}/build
run: cmake --build . --config $BUILD_TYPE

- name: Run tests
shell: bash
working-directory: ${{ runner.workspace }}/build
run: ctest -C $BUILD_TYPE
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(QDLDL_VERSION "${QDLDL_VERSION_MAJOR}.${QDLDL_VERSION_MINOR}.${QDLDL_VERSION
project(qdldl VERSION ${QDLDL_VERSION})

include( CMakeDependentOption )
include(CheckCCompilerFlag)

option( QDLDL_BUILD_STATIC_LIB "Build the static library" ON )
option( QDLDL_BUILD_SHARED_LIB "Build the shared library" ON )
Expand Down Expand Up @@ -53,6 +54,11 @@ if( NOT (CMAKE_SIZEOF_VOID_P EQUAL 8) )
endif()
message(STATUS "Long integers (64bit) are ${QDLDL_LONG}")

option( QDLDL_ENABLE_OPENMP_SIMD "Enable OpenMP SIMD annotations" OFF )
if( ${QDLDL_ENABLE_OPENMP_SIMD} )
message( STATUS "Enabling OpenMP SIMD annotations" )
endif()


# Set Compiler flags
# ----------------------------------------------
Expand All @@ -74,6 +80,30 @@ if (NOT MSVC)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")
endif (NOT MSVC)

# Add flags for OpenMP SIMD optimizations
if( ${QDLDL_ENABLE_OPENMP_SIMD} )
# Flags for Clang/GCC, if supported
check_c_compiler_flag( "-fopenmp-simd" HAVE_FOPENMP_SIMD )
if( ${HAVE_FOPENMP_SIMD} )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp-simd")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fopenmp-simd")
endif()

# Flags for Intel linux compiler, if supported
check_c_compiler_flag( "-qopenmp-simd" HAVE_DASH_QOPENMP_SIMD )
if( ${HAVE_DASH_QOPENMP_SIMD} )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qopenmp-simd")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -qopenmp-simd")
endif()

# Flags for Intel Windows compiler, if supported
check_c_compiler_flag( "/Qopenmp-simd" HAVE_SLASH_QOPENMP_SIMD )
if( ${HAVE_SLASH_QOPENMP_SIMD} )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qopenmp-simd")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Qopenmp-simd")
endif()
endif()

# Generate header file with the global options
# ---------------------------------------------

Expand Down
10 changes: 9 additions & 1 deletion src/qdldl.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ void QDLDL_Lsolve(const QDLDL_int n,
QDLDL_int i,j;
for(i = 0; i < n; i++){
QDLDL_float val = x[i];

#pragma omp simd
for(j = Lp[i]; j < Lp[i+1]; j++){
x[Li[j]] -= Lx[j]*val;
}
Expand All @@ -258,6 +260,8 @@ void QDLDL_Ltsolve(const QDLDL_int n,
QDLDL_int i,j;
for(i = n-1; i>=0; i--){
QDLDL_float val = x[i];

#pragma omp simd reduction(-:val)
for(j = Lp[i]; j < Lp[i+1]; j++){
val -= Lx[j]*x[Li[j]];
}
Expand All @@ -276,6 +280,10 @@ void QDLDL_solve(const QDLDL_int n,
QDLDL_int i;

QDLDL_Lsolve(n,Lp,Li,Lx,x);
for(i = 0; i < n; i++) x[i] *= Dinv[i];

#pragma omp simd
for(i = 0; i < n; i++)
x[i] *= Dinv[i];

QDLDL_Ltsolve(n,Lp,Li,Lx,x);
}
Loading