Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass an R package on CRAN with issues on MACOS due + OpenMP

I have an R package with Fortran and OpenMP than can't pass CRAN. I receive the following message:

Your package no longer installs on macOS with OpenMP issues.

My Makevars file is:

USE_FC_TO_LINK =
PKG_FFLAGS = $(SHLIB_OPENMP_FFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_FFLAGS)

C_OBJS = init.o
FT_OBJS = e_bottomup.o e_topdown.o check_nt.o

all:
    @$(MAKE) $(SHLIB)
    @rm -f  *.o

$(SHLIB): $(FT_OBJS) $(C_OBJS)

init.o:  e_bottomup.o e_topdown.o check_nt.o

How to solve this issue? Thanks.

Edit 1:

I tried adding the flag cpp:

USE_FC_TO_LINK =
PKG_FFLAGS = $(SHLIB_OPENMP_FFLAGS) *-cpp*
PKG_LIBS = $(SHLIB_OPENMP_FFLAGS)

to add the condition #ifdef _OPENMP on Fortran code before !omp...

But with R CMD Check I got the message:

Non-portable flags in variable 'PKG_FFLAGS': -cpp
like image 977
Sergio Avatar asked Oct 03 '20 14:10

Sergio


2 Answers

The Makevars file is fine. The OMP directives must be commented !$, including the USE OMP.

For instance, I created an R package with Fortran and OMP to test (and play with it).

I included an R function to return the max number of threads in each machine:

get_threads

The Fortran code is :

SUBROUTINE checkntf (nt) 
!$ USE OMP_LIB

IMPLICIT NONE
INTEGER nt

!$ nt = OMP_GET_MAX_THREADS()

RETURN
END

The already install on Windows, Ubuntu and macOS as shown here

enter image description here

like image 200
Sergio Avatar answered Nov 16 '22 09:11

Sergio


You can look how the data.table package deal with that using #ifdef _OPENMP: https://github.com/Rdatatable/data.table/blob/master/src/myomp.h It should be pretty similar in Fortran I guess

#ifdef _OPENMP
  #include <omp.h>
#else
  // for machines with compilers void of openmp support
  #define omp_get_num_threads()  1
  #define omp_get_thread_num()   0
  #define omp_get_max_threads()  1
  #define omp_get_thread_limit() 1
  #define omp_get_num_procs()    1
  #define omp_set_nested(a)   // empty statement to remove the call
  #define omp_get_wtime()        0
#endif
like image 38
JRR Avatar answered Nov 16 '22 11:11

JRR