Setting up “configure” for openMP in R

前端 未结 2 516
盖世英雄少女心
盖世英雄少女心 2021-02-04 14:34

I have an R package which is easily sped up by using OpenMP. If your compiler supports it then you get the win, if it doesn\'t then the pragmas are ignored and you get one core.

相关标签:
2条回答
  • 2021-02-04 14:37

    Methinks you have the library option wrong, please try

    ## -- compiling for OpenMP 
    PKG_CXXFLAGS=-fopenmp
    ##
    ## -- linking for OpenMP
    PKG_LIBS= -fopenmp -lgomp 
    

    In other words, -lgomp gets you the OpenMP library linked. And I presume you know that this library is not part of the popular Rtools kit for Windows. On a modern Linux you should be fine.

    In an unrelease testpackage I have here I also add the following to PKG_LIBS, but that is mostly due to my use of Rcpp:

    $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") \
                                  $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
    

    Lastly, I think the autoconf business is not really needed unless you feel you need to test for OpenMP via configure.

    Edit: SpacedMan is correct. Per the beginning of the libgomp-4.4 manual:

    1 Enabling OpenMP

    To activate the OpenMP extensions for C/C++ and Fortran, the compile-time flag `-fopenmp' must be specified. This enables the OpenMP directive [...] The flag also arranges for automatic linking of the OpenMP runtime library.

    So I stand corrected. Seems that it doesn't hurt to manually add what would get added anyway, just for clarity...

    0 讨论(0)
  • 2021-02-04 14:44

    Just addressing your question regarding the usage of autoconf--no, you do not want to run autoconf with any arguments, nor should you redirect its output. You are correct that running autoconf to build the configure script is something that the package maintainer does, and the resulting configure script is distributed. Normally, to generate the configure script from configure.ac (older packages use the name configure.in, but that name has been discouraged for several years), the developer simply runs autoconf with no arguments. Before running autoconf, it is necessary to run aclocal, autoheader, libtoolize, etc... There is also a tool (autoreconf) which simplifies the process and invokes all the required programs in the correct order. It is now more typical to run autoreconf instead of autoconf.

    0 讨论(0)
提交回复
热议问题