[Rcpp-devel] Rcpp unreachable when RInside+Hemi tryed to be compiled together

ExtremePasta extremepasta at gmail.com
Fri May 18 09:22:16 CEST 2018


Hi all,
I'm trying to make a simple .cpp compile with RInside and Hemi in it, in
particular to parallelize R function directly in .cpp without using or
creating R packages, to be precise this is the .cpp :
#include <stdio.h>
#include "hemi/parallel_for.h"
#include <RInside.h>

using namespace hemi;

int main(void)
{
    parallel_for(0, 100, [] HEMI_LAMBDA (int i) {
        printf("%d\n", i);
    });

    deviceSynchronize();

    return 0;
}
the main problem is that I can't give Rcpp and RInside all the headers they
need, this is the makefile:
# operating system
HOST_OS := $(shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]")

# architecture
ARCH := $(shell getconf LONG_BIT)

NVCC := nvcc

## comment this out if you need a different version of R,
## and set set R_HOME accordingly as an environment variable
R_HOME :=         $(shell R RHOME)

sources :=         $(wildcard *.cpp)
programs :=         $(sources:.cpp=)


## include headers and libraries for R
RCPPFLAGS :=         $(shell $(R_HOME)/bin/R CMD config --cppflags)
RLDFLAGS :=         $(shell $(R_HOME)/bin/R CMD config --ldflags)
RBLAS :=         $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
RLAPACK :=         $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)

## if you need to set an rpath to R itself, also uncomment
#RRPATH :=        -Wl,-rpath,$(R_HOME)/lib

## include headers and libraries for Rcpp interface classes
## note that RCPPLIBS will be empty with Rcpp (>= 0.11.0) and can be omitted
RCPPINCL :=         $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R
--vanilla --slave)
RCPPLIBS :=         $(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R
--vanilla --slave)


## include headers and libraries for RInside embedding classes
RINSIDEINCL :=         $(shell echo 'RInside:::CxxFlags()' |
$(R_HOME)/bin/R --vanilla --slave)
RINSIDELIBS :=         $(shell echo 'RInside:::LdFlags()'  |
$(R_HOME)/bin/R --vanilla --slave)

## compiler etc settings used in default make rules
ifeq ($(HOST_OS),darwin)
    CXX := clang++ $(shell $(R_HOME)/bin/R CMD config CXX)
else
    CXX := $(shell $(R_HOME)/bin/R CMD config CXX)
endif

STD := --std=c++11

CPPFLAGS :=         -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)

CXX_FLAGS  := $(STD) -I../ -I../../ $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL)
-g  -Xcompiler -fstack-protector-strong -Xcompiler -Wformat -Xcompiler
-Wdate-time -Xcompiler -D_FORTIFY_SOURCE=2
##$(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
LDFLAGS    =         -s
LDLIBS :=         $(RLDFLAGS) $(RBLAS) $(RLAPACK) $(RINSIDELIBS) $(RCPPLIBS)
CC :=             $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config CXX)
HOST_ONLY_FLAGS := -DHEMI_CUDA_DISABLE

# uncomment for debug
DEBUG_FLAGS := -g -DDEBUG
DEBUG_FLAGS_NVCC := -G -D_FORCE_INLINES

# comment for debug
CXX_FLAGS += -O3

CXX_FLAGS += $(DEBUG_FLAGS)

NVCC_FLAGS := $(CXX_FLAGS) $(DEBUG_FLAGS_NVCC) --expt-extended-lambda

## --expt-extended-lambda

LDLIBS :=         $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS)
$(RINSIDELIBS)

all: parallel_for_device parallel_for_host_nvcc parallel_for_host

parallel_for_device: parallel_for.cpp
    $(NVCC) $? $(NVCC_FLAGS) -x cu -o $@

parallel_for_host_nvcc: parallel_for.cpp
    $(NVCC) $? $(CXX_FLAGS) -x c++ -o $@

parallel_for_host: parallel_for.cpp
    $(CXX) $? $(CXX_FLAGS) $(HOST_ONLY_FLAGS) -o $@

clean:
    rm -rf parallel_for_device parallel_for_host_nvcc parallel_for_host

using -Xcompiler and removing some flag from $(shell $(R_HOME)/bin/R CMD
config CXXFLAGS) I tryed to make nvcc recognize all the gcc command but I
don't know if this allow nvcc run it perfectly. When running "make" this is
the error I get:

nvcc parallel_for.cpp --std=c++11 -I../ -I../../ -I/usr/share/R/include
-I/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include
-I/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/RInside/include -g
-Xcompiler -fstack-protector-strong -Xcompiler -Wformat -Xcompiler
-Wdate-time -Xcompiler -D_FORTIFY_SOURCE=2 -O3 -g -DDEBUG -G
-D_FORCE_INLINES --expt-extended-lambda -x cu -o parallel_for_device
/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/r_cast.h(121):
warning: statement is unreachable

/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/r_cast.h(74):
warning: statement is unreachable

/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/vector/vector_from_string.h(42):
warning: statement is unreachable

/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/r_cast.h(54):
warning: statement is unreachable

/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/r_cast.h(74):
warning: statement is unreachable

/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/r_cast.h(121):
warning: statement is unreachable

/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/Environment.h(93):
warning: statement is unreachable

/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/vector/vector_from_string.h(42):
warning: statement is unreachable

/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/vector/Vector.h(324):
warning: statement is unreachable

/tmp/tmpxft_00000456_00000000-10_parallel_for.o: nella funzione
"Rcpp::Rstreambuf<false>::xsputn(char const*, long)":
/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:56:
riferimento non definito a "REprintf"
/tmp/tmpxft_00000456_00000000-10_parallel_for.o: nella funzione
"Rcpp::Rstreambuf<false>::sync()":
/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:80:
riferimento non definito a "R_FlushConsole"
/tmp/tmpxft_00000456_00000000-10_parallel_for.o: nella funzione
"Rcpp::Rstreambuf<true>::sync()":
/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:76:
riferimento non definito a "R_FlushConsole"
/tmp/tmpxft_00000456_00000000-10_parallel_for.o: nella funzione
"Rcpp::Rstreambuf<true>::xsputn(char const*, long)":
/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:52:
riferimento non definito a "Rprintf"
/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:52:
riferimento non definito a "Rprintf"
/tmp/tmpxft_00000456_00000000-10_parallel_for.o: nella funzione
"Rcpp::Rstreambuf<false>::xsputn(char const*, long)":
/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:56:
riferimento non definito a "REprintf"
collect2: error: ld returned 1 exit status
Makefile:72: set di istruzioni per l'obiettivo "parallel_for_device" non
riuscito
make: *** [parallel_for_device] Errore 1

I know the makefile isn't make in the proper way, what would you suggest? I
really cant make Rcpp reachable, is there a guide to understand better how
to link all the headers for RInside properly? How would you modify the
makefile? Can this error be fixed or is just impossible? Sorry for my bad
english, I hope I asked this in the proper way, sorry but I'm trying to fix
this error for weeks and don't know what to try more... Thank you for the
help and sorry for the answer, maybe you will find it stupid but I really
can't understand or find a way to debug it.. Have a nice day.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20180518/ea58cee0/attachment.html>


More information about the Rcpp-devel mailing list