Skip to content

Commit

Permalink
Option to build OpenMP with XCode (cmake -DOPENMP_XCODE=ON ..) expect…
Browse files Browse the repository at this point in the history
…s dynamic library libomp.dylib (https://mac.r-project.org/openmp/)
  • Loading branch information
neurolabusc committed Dec 4, 2020
1 parent 75760db commit 32afed0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion SuperBuild/SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

option(USE_STATIC_RUNTIME "Use static runtime" ON)
option(OPENMP_XCODE "Build the static library" OFF)

include(ExternalProject)

set(DEPENDENCIES)

set(DEP_INSTALL_DIR ${CMAKE_BINARY_DIR})

set(ZLIB_IMPLEMENTATION "Cloudflare" CACHE STRING "Choose zlib implementation.")
set_property(CACHE ZLIB_IMPLEMENTATION PROPERTY STRINGS "Cloudflare;System;Custom")
if(${ZLIB_IMPLEMENTATION} STREQUAL "Cloudflare")
Expand Down Expand Up @@ -55,6 +55,7 @@ ExternalProject_Add(src
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
-DCMAKE_VERBOSE_MAKEFILE:BOOL=${CMAKE_VERBOSE_MAKEFILE}
-DOPENMP_XCODE:BOOL=${OPENMP_XCODE}
-DUSE_STATIC_RUNTIME:BOOL=${USE_STATIC_RUNTIME}
-DZLIB_IMPLEMENTATION:STRING=${ZLIB_IMPLEMENTATION}
-DZLIB_ROOT:PATH=${ZLIB_ROOT}
Expand Down
9 changes: 7 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ if(NOT CMAKE_BUILD_TYPE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel")
endif()


#e.g. cmake -DOPENMP_XCODE=ON ..
option(OPENMP_XCODE "Build the static library" OFF)
if(${CMAKE_C_COMPILER_ID} STREQUAL "AppleClang")
# using AppleClang
add_definitions(-fno-caret-diagnostics)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip")
if (OPENMP_XCODE)
set(CMAKE_C_FLAGS "-I/usr/local/include -Xclang -fopenmp ${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib -lomp")
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip")
elseif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
# using GCC
set(CMAKE_C_STANDARD 11)
Expand Down
4 changes: 1 addition & 3 deletions src/core32.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,6 @@ static int nifti_smooth_gauss(nifti_image * nim, flt SigmammX, flt SigmammY, flt
for (int i = 2; i < 8; i++ )
nRow *= MAX(nim->dim[i],1);
#if defined(_OPENMP)
//printf(">>>%d\n", omp_get_num_threads());
if (omp_get_max_threads() > 1)
blurP(img, nim->nx, nRow, nim->dx, SigmammX);
else
Expand Down Expand Up @@ -636,10 +635,9 @@ static int nifti_smooth_gauss(nifti_image * nim, flt SigmammX, flt SigmammY, flt
//BLUR Z:
if ((SigmammZ <= 0.0) || (nim->nz < 2)) return 0; //all done!
nRow = nim->nx * nim->ny; //transpose XYZ to ZXY and blur Z columns with XY Rows
//#pragma omp parallel
//#pragma omp for
#pragma omp parallel for
for (int v = 0; v < nVol; v++ ) { //transpose each volume separately
//printf("volume %d uses thread %d\n", v, omp_get_thread_num());
flt * img3D = (flt *)_mm_malloc(nvox3D*sizeof(flt), 64); //alloc for each volume to allow openmp
size_t vo = v * nvox3D; //volume offset
for (int z = 0; z < nz; z++ ) {
Expand Down

0 comments on commit 32afed0

Please sign in to comment.