<div dir="ltr"><div>Hi all,</div><div>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 : <br></div><div>#include <stdio.h><br>#include "hemi/parallel_for.h"<br>#include <RInside.h><br><br>using namespace hemi;<br><br>int main(void)<br>{<br>    parallel_for(0, 100, [] HEMI_LAMBDA (int i) { <br>        printf("%d\n", i); <br>    });<br><br>    deviceSynchronize();<br><br>    return 0;<br>}</div><div>the main problem is that I can't give Rcpp and RInside all the headers they need, this is the makefile: <br></div><div># operating system<br>HOST_OS := $(shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]")<br><br># architecture <br>ARCH := $(shell getconf LONG_BIT)<br><br>NVCC := nvcc<br><br>## comment this out if you need a different version of R, <br>## and set set R_HOME accordingly as an environment variable<br>R_HOME :=         $(shell R RHOME)<br><br>sources :=         $(wildcard *.cpp)<br>programs :=         $(sources:.cpp=)<br><br><br>## include headers and libraries for R <br>RCPPFLAGS :=         $(shell $(R_HOME)/bin/R CMD config --cppflags)<br>RLDFLAGS :=         $(shell $(R_HOME)/bin/R CMD config --ldflags)<br>RBLAS :=         $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)<br>RLAPACK :=         $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)<br><br>## if you need to set an rpath to R itself, also uncomment<br>#RRPATH :=        -Wl,-rpath,$(R_HOME)/lib<br><br>## include headers and libraries for Rcpp interface classes<br>## note that RCPPLIBS will be empty with Rcpp (>= 0.11.0) and can be omitted<br>RCPPINCL :=         $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)<br>RCPPLIBS :=         $(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)<br><br><br>## include headers and libraries for RInside embedding classes<br>RINSIDEINCL :=         $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)<br>RINSIDELIBS :=         $(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)<br><br>## compiler etc settings used in default make rules<br>ifeq ($(HOST_OS),darwin)<br>    CXX := clang++ $(shell $(R_HOME)/bin/R CMD config CXX)<br>else<br>    CXX := $(shell $(R_HOME)/bin/R CMD config CXX)<br>endif<br><br>STD := --std=c++11<br><br>CPPFLAGS :=         -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)<br><br>CXX_FLAGS  := $(STD) -I../ -I../../ $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) -g  -Xcompiler -fstack-protector-strong -Xcompiler -Wformat -Xcompiler -Wdate-time -Xcompiler -D_FORTIFY_SOURCE=2<br>##$(shell $(R_HOME)/bin/R CMD config CXXFLAGS)<br>LDFLAGS    =         -s<br>LDLIBS :=         $(RLDFLAGS) $(RBLAS) $(RLAPACK) $(RINSIDELIBS) $(RCPPLIBS)<br>CC :=             $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config CXX)<br>HOST_ONLY_FLAGS := -DHEMI_CUDA_DISABLE<br><br># uncomment for debug<br>DEBUG_FLAGS := -g -DDEBUG<br>DEBUG_FLAGS_NVCC := -G -D_FORCE_INLINES<br><br># comment for debug<br>CXX_FLAGS += -O3<br><br>CXX_FLAGS += $(DEBUG_FLAGS)<br><br>NVCC_FLAGS := $(CXX_FLAGS) $(DEBUG_FLAGS_NVCC) --expt-extended-lambda<br><br>## --expt-extended-lambda<br><br>LDLIBS :=         $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)<br><br>all: parallel_for_device parallel_for_host_nvcc parallel_for_host<br><br>parallel_for_device: parallel_for.cpp<br>    $(NVCC) $? $(NVCC_FLAGS) -x cu -o $@<br><br>parallel_for_host_nvcc: parallel_for.cpp<br>    $(NVCC) $? $(CXX_FLAGS) -x c++ -o $@<br><br>parallel_for_host: parallel_for.cpp<br>    $(CXX) $? $(CXX_FLAGS) $(HOST_ONLY_FLAGS) -o $@<br><br>clean:<br>    rm -rf parallel_for_device parallel_for_host_nvcc parallel_for_host</div><div><br></div><div>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:</div><div><br></div><div>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<br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/r_cast.h(121): warning: statement is unreachable<br><br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/r_cast.h(74): warning: statement is unreachable<br><br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/vector/vector_from_string.h(42): warning: statement is unreachable<br><br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/r_cast.h(54): warning: statement is unreachable<br><br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/r_cast.h(74): warning: statement is unreachable<br><br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/r_cast.h(121): warning: statement is unreachable<br><br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/Environment.h(93): warning: statement is unreachable<br><br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/vector/vector_from_string.h(42): warning: statement is unreachable<br><br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/vector/Vector.h(324): warning: statement is unreachable<br><br>/tmp/tmpxft_00000456_00000000-10_parallel_for.o: nella funzione "Rcpp::Rstreambuf<false>::xsputn(char const*, long)":<br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:56: riferimento non definito a "REprintf"<br>/tmp/tmpxft_00000456_00000000-10_parallel_for.o: nella funzione "Rcpp::Rstreambuf<false>::sync()":<br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:80: riferimento non definito a "R_FlushConsole"<br>/tmp/tmpxft_00000456_00000000-10_parallel_for.o: nella funzione "Rcpp::Rstreambuf<true>::sync()":<br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:76: riferimento non definito a "R_FlushConsole"<br>/tmp/tmpxft_00000456_00000000-10_parallel_for.o: nella funzione "Rcpp::Rstreambuf<true>::xsputn(char const*, long)":<br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:52: riferimento non definito a "Rprintf"<br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:52: riferimento non definito a "Rprintf"<br>/tmp/tmpxft_00000456_00000000-10_parallel_for.o: nella funzione "Rcpp::Rstreambuf<false>::xsputn(char const*, long)":<br>/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:56: riferimento non definito a "REprintf"<br>collect2: error: ld returned 1 exit status<br>Makefile:72: set di istruzioni per l'obiettivo "parallel_for_device" non riuscito<br>make: *** [parallel_for_device] Errore 1<br></div><div><br></div><div>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.<br></div></div>