Skip to content

OpenMP support on macOS #1926

Closed
Closed

Description

@seisman

I think GMT also needs glib2 for gthread support, right? If yes, we should also add glib2 as an optional dependency.

A related question: is pthread used in GMT? HAVE_PTHREAD is almost never used in the codes.

Activity

  1. PaulWessel commented on Oct 29, 2019

    @PaulWessel
    Contributor

    This is all @joa-quim I think. I really want us to standardize on OpenMP as having too many different system for achieving the same thing makes maintenance much harder and add more dependencies for just a few modules. I have added OpenMP to several modules and library functions and if I find time (hah!) I would like to rewrite grdfilter to use OpenMP, etc., etc.

  2. PaulWessel commented on Oct 29, 2019

    @PaulWessel
    Contributor

    But to answer your question, yes, I guess glib2 (at least for now - see above) should be treated the same way we treat other optional libs like Lapack, etc.

  3. seisman commented on Oct 29, 2019

    @seisman
    MemberAuthor

    OK. I will submit a PR for glib2 later.

    As for OpenMP, we still need to figure out how to enable OpenMP on macOS using Apple's default compiler.

  4. PaulWessel commented on Oct 29, 2019

    @PaulWessel
    Contributor

    Apple has yet to implement OpenMP in their clang. once can install another version or use gcc to build it. Just install gcc and make a file (here cache.cmake):

    SET ( CMAKE_C_COMPILER "/opt/local/bin/gcc-mp-9" CACHE STRING "GNU MP C compiler" )
    SET ( CMAKE_CXX_COMPILER "/opt/local/bin/g++-mp-9" CACHE STRING "GNU MP C++ compiler" )
    SET (CMAKE_C_FLAGS -flax-vector-conversions)
    SET (CMAKE_C_FLAGS_DEBUG -flax-vector-conversions)
    SET (CMAKE_C_FLAGS_RELEASE -flax-vector-conversions)
    SET (OpenMP_C_FLAGS -flax-vector-conversions)

    and then

    cmake -DCMAKE_INSTALL_PREFIX=gmt6 -DCMAKE_BUILD_TYPE=Release -G Ninja -C ~/cache.cmake ..

  5. joa-quim commented on Oct 29, 2019

    @joa-quim
    Member

    pthread is not used anywhere in GMT, but we build a test using it (pthreads_example)

  6. seisman commented on Oct 29, 2019

    @seisman
    MemberAuthor

    Apple has yet to implement OpenMP in their clang.

    I think that's not true. I can use OpenMP with AppleClang, following this post (https://iscinumpy.gitlab.io/post/omp-on-high-sierra/), so it's doable. The only problem is cmake can't find AppleClang's OpenMP support correctly.

    pthread is not used anywhere in GMT, but we build a test using it (pthreads_example)

    Since it's never used, do you think we should remove it?

  7. joa-quim commented on Oct 29, 2019

    @joa-quim
    Member

    Yes, I think we should. Afaik, it was Florian that for some reason added that pthread test.

    Regarding OpenMP the VS support is lousy but found this, which makes think things are changing. The #pragma omp for simd seems really interesting.

  8. joa-quim commented on Oct 29, 2019

    @joa-quim
    Member

    But reading this https://developercommunity.visualstudio.com/idea/351554/please-support-newer-version-of-openmp.html chills out the enthusiasm. The VS guys talk about OMP is just hard to believe they are talking seriously.

  9. changed the title [-]Add glib2 as GMT dependency[/-] [+]GThread, pthread and OpenMP support[/+] on Oct 29, 2019
  10. claudiodsf commented on Nov 1, 2019

    @claudiodsf
    Contributor

    I think that's not true. I can use OpenMP with AppleClang, following this post (https://iscinumpy.gitlab.io/post/omp-on-high-sierra/), so it's doable. The only problem is cmake can't find AppleClang's OpenMP support correctly.

    I could actually let CMake found OpenMP, using Homebrew's libomp.

    Details are in the attached brew formula

    $ brew install -vv ./gmt.rb
    

    However compilation aborts at 42% with this error:

    /tmp/gmt-20191102-74335-1w0o76o/gmt-6.0.0/src/grdlandmask.c:649:2: error: condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'row'
            gmt_M_grd_loop (GMT, Grid, row, col, ij) {      /* Turn levels into mask values */
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /tmp/gmt-20191102-74335-1w0o76o/gmt-6.0.0/src/gmt_grd.h:165:40: note: expanded from macro 'gmt_M_grd_loop'
    #define gmt_M_grd_loop(C,G,row,col,ij) gmt_M_row_loop(C,G,row) gmt_M_col_loop(C,G,row,col,ij)
                                           ^~~~~~~~~~~~~~~~~~~~~~~
    /tmp/gmt-20191102-74335-1w0o76o/gmt-6.0.0/src/gmt_grd.h:163:47: note: expanded from macro 'gmt_M_row_loop'
    #define gmt_M_row_loop(C,G,row) for (row = 0; (int)row < (int)G->header->n_rows; row++)
                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.
    
  11. PaulWessel commented on Nov 1, 2019

    @PaulWessel
    Contributor

    So this works fine with gcc -fopen and clearly we are using rational comparison <. It must not like to expand the macro or the cast to signed int? (WIndows demands signed ints....)

  12. added
    feature request
    help wanted
    on Nov 7, 2019
  13. changed the title [-]GThread, pthread and OpenMP support[/-] [+]OpenMP support on macOS[/+] on Dec 18, 2019
  14. seisman commented on Jan 6, 2020

    @seisman
    MemberAuthor

    I recently updated cmake to 3.16.2, and cmake now can find AppleClang OpenMP correctly. However, as reported by @claudiodsf, the compilation gives an error.

  15. PaulWessel commented on May 2, 2020

    @PaulWessel
    Contributor

    I am trying to ease back into OpenMP. Before I try Xcode, I wanted to just do gcc. This worked previously with gcc for me, but now I get tons of these

    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vBasicOps.h:379:70: error: incompatible type for argument 2 of '_mm_mullo_epi16'

    despite having

    set (CMAKE_C_FLAGS -flax-vector-conversions)
    set (CMAKE_C_FLAGS_DEBUG -flax-vector-conversions)
    set (CMAKE_C_FLAGS_RELEASE -flax-vector-conversions)
    

    in my cache file. After config I see

    -- Using CFLAGS = '-std=gnu99 -Wextra -Wall -Wdeclaration-after-statement -fopenmp -O3 -DNDEBUG'

    so so much for the flax settings. Thought?

  16. seisman commented on May 2, 2020

    @seisman
    MemberAuthor

    It seems you have to set all variables as cached entries.

    SET ( CMAKE_C_COMPILER "/opt/local/bin/gcc-mp-9" CACHE STRING "GNU MP C compiler" )
    SET ( CMAKE_CXX_COMPILER "/opt/local/bin/g++-mp-9" CACHE STRING "GNU MP C++ compiler" )
    SET (CMAKE_C_FLAGS -flax-vector-conversions CACHE STRING "C FLAGS")
    SET (CMAKE_C_FLAGS_DEBUG -flax-vector-conversions CACHE STRING "C FLAGS DEBUG")
    SET (CMAKE_C_FLAGS_RELEASE -flax-vector-conversions CACHE STRING "C FLAGS RELEASE")
    SET (OpenMP_C_FLAGS -flax-vector-conversions CACHE STRING "C FLAGS OPENMP")
    
  17. joa-quim commented on Apr 12, 2024

    @joa-quim
    Member

    Is this still an open issue?

  18. seisman commented on Apr 15, 2024

    @seisman
    MemberAuthor

    Yes, we still have trouble enabling OpenMP on macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requesthelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions