问题描述
我有一个R package的Fortran和OpenMP不能通过CRAN。我收到以下消息:
您的软件包不再安装在具有OpenMP问题的macOS上。
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
如何解决此问题?谢谢。
编辑1:
我尝试添加标志cpp:
USE_FC_TO_LINK =
PKG_FFLAGS = $(SHLIB_OPENMP_FFLAGS) *-cpP*
PKG_LIBS = $(SHLIB_OPENMP_FFLAGS)
在!omp之前在Fortran代码上添加条件#ifdef _OPENMP ...
但是使用R CMD Check,我收到消息:
Non-portable flags in variable 'PKG_FFLAGS': -cpp
解决方法
Makevars文件很好。必须将OMP指令注释为$,包括USE OMP。
例如,我用Fortran和OMP创建了一个R包进行测试(并使用它)。
我包含了一个R函数,用于返回每台计算机上的最大线程数:
Fortran代码为:
def player_chooses_card():
# graphic and logic updates for player's choice
# computer turn
if Computer cannot play:
trigger graphic for end of game
else:
Do some "AI" stuff... the computer plays
# function is done; back to idle state waiting for an event
已安装在Windows,Ubuntu和macOS上,如图here
,您可以使用data.table
查看#ifdef _OPENMP
软件包的处理方式:https://github.com/Rdatatable/data.table/blob/master/src/myomp.h我想在Fortran中应该非常相似
#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