Skip to content

Commit

Permalink
Add omp simd pragmas to some loops
Browse files Browse the repository at this point in the history
  • Loading branch information
imciner2 committed May 9, 2024
1 parent b37fdff commit c7d4912
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
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);
}

0 comments on commit c7d4912

Please sign in to comment.