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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With