weighted power voronoi - power_diagramer.exe file - voronoi

As I understand in order to have power weighted voronoi diagram I need first to create/make file named:power_diagramer.exe as follow:
all:
#-frounding-math is GCC specific, but required for any CGAL code compiled with GCC
g++ -O3 power_diagram_lib.cpp -o power_diagramer.exe -Wall -lCGAL -lgmp -lgmpxx -lmpfr -frounding-math
my question is what are this line of code?
is it C++?
How can I run it and get the file?
also what is this file is it generated using CGAL library?
R,
Yaniv

Related

Error in dyn.load(dll_copy_file) --A error when building R package via linux system

I am currently building a local R package with Rcpp and FFTW3.
When I run devtools::document() the error shows up, below is the full error message:
Error in dyn.load(dll_copy_file) :
unable to load shared object '/tmp/RtmpcsGXOO/pkgload7f8a5462dce4/pmd.so':
/tmp/RtmpcsGXOO/pkgload7f8a5462dce4/pmd.so: undefined symbol: fftw_execute
pmd is my package name. I am wondering it might relate to my Makevar file.
My Makevars.in looks like this:
PKG_CPPFLAGS=#CPPFLAGS# #FFTW_CFLAGS#
PKG_LIBS=#LIBS# #FFTW_LIBS#
all: $(SHLIB)
PKG_CPPFLAGS = -I../inst/include -I/usr/local/include
PKG_LIBS= -L/usr/local/lib -lfftw3
Actually, I have no idea how to write a Makevars file, the way I wrote this Makevars is copying Makevars from other existing packages.
Originally, I used C to perform what I want, and I used dyn.load after typing following codes in terminal so that I could .C() those C functions in R:
C_INCLUDE_PATH=~/usr/include
export C_INCLUDE_PATH
export LD_RUN_PATH=$HOME/usr/lib
R CMD SHLIB functions.c -I$HOME/usr/include -L$HOME/usr/lib -lfftw3 -lgsl -lgslcblas -lm -o functions.so
.

Invoking R CMD SHLIB through system() doesn't find GSL library

I have a C program that uses GNU Scientific Library (GSL) for root finding and I want to make this into a shared library (.so or .dll) for use in R.
Say my GSL_MRE.c file looks like this:
#include <gsl/gsl_math.h>
#include <gsl/gsl_roots.h>
#include <gsl/gsl_errno.h>
#include <R.h>
int gsl_rootsolve ()
{
const gsl_root_fdfsolver_type *T;
gsl_root_fdfsolver *s;
T = gsl_root_fdfsolver_newton;
s = gsl_root_fdfsolver_alloc (T);
printf ("using %s method\n", gsl_root_fdfsolver_name (s));
gsl_root_fdfsolver_free (s);
return 0;
}
If I run the following in Terminal on MacOS 10.13.6:
$ R CMD SHLIB GSL_MRE.c -lgsl -lgslcblas -lm -L/opt/local/lib
($ is the terminal prompt) it creates GSL_MRE.so that I can load by executing in R:
R> dyn.load(paste("GSL_MRE", .Platform$dynlib.ext, sep = ""))
(R> is R prompt)
But when I try to create the .so file from R with system():
R> system("R CMD SHLIB GSL_MRE.c -lgsl -lgslcblas -lm -L/opt/local/lib")
It can't find the header files. I get:
GSL_MRE.c:1:10: fatal error: 'gsl/gsl_math.h' file not found
#include <gsl/gsl_math.h>
^~~~~~~~~~~~~~~~
1 error generated.
make: *** [GSL_MRE.o] Error 1
I've been trying to set all sorts of FLAGS in ~/.R/Makevars, but nothing works. My Makevars currently only contains the following line:
CC=gcc -Wall -Wextra
Why does system() from R not work? And how do I make the .so from R programmatically?
There are a few packages that wrap around the GSL, I recommend you study them. At a minimum you could use gsl-config (which you should test for) to derive include and linker statements. On my Uvuntu system:
edd#rob:~$ gsl-config --cflags
-I/usr/include
edd#rob:~$ gsl-config --libs
-L/usr/lib/x86_64-linux-gnu -lgsl -lgslcblas -lm
edd#rob:~$
More fundamentally, you got trapped between linking (where you correctly pointo to the GSL libraries) and compiling (where you have told the compiler where your GSL headers reside). You apprently need to tell it on your system.
Also, some packages provide facilities. My RcppGSL package offers some simple vector and matrix wrappers, but also deals with GSL detection so that for example my RcppZiggurat (which uses GSL RNGs) can use:
edd#rob:~$ cat git/rcppziggurat/src/Makevars
PKG_CPPFLAGS = -I. -I../inst/include
## Use the R_HOME indirection to support installations of multiple R version
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "RcppGSL:::LdFlags()"`
edd#rob:~$
It's not a trivial problem as you need to sort our compiling and linking, but it has been done before so you can lean on that.

undefined references when using Rcpp

I am trying to build an R package that is a wrapper around a C library (and which uses gsl) in Windows. I can transition to Linux, if necessary
For better or worse, I put the make commands for the C library in Makevars.in.
I used Rstudio's Rcpp skeleton feature to create the package. I have installed Rtools 3.3 and using R 3.3.1
and I included Rcpp and RcppGSL in LinkingTo field of DESCRIPTION. I am still getting undefined reference errors for the make command
$(CXX) $(CXXFLAGS) $(OBJECTS) ../inst/libgraphm.a $(PKG_LIBS)
A few of the error are as follows
c:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o RGraphM.dll tmp.def graphmatch_rcpp.o RcppExports.o -L../inst -lgraphm -LC:/tools/gsl/lib/x64 -lgsl -lgslcblas -Ld:/Compiler/gcc-4.9.3/local330/lib/x64 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-33~1.1/bin/x64 -lR
#cd graphm && /usr/bin/make
c:/Rtools/mingw_64/bin/g++ -O2 -Wall -mtune=core2 graphmatch_rcpp.o RcppExports.o ../inst/libgraphm.a -L../inst -lgraphm -LC:/tools/gsl/lib/x64 -lgsl -lgslcblas
graphmatch_rcpp.o: In function `PreserveStorage':
C:/Users/sadali/Documents/R/win-library/3.3/Rcpp/include/Rcpp/storage/PreserveStorage.h:10: undefined reference to `__imp_R_NilValue'
graphmatch_rcpp.o: In function `Vector':
C:/Users/sadali/Documents/R/win-library/3.3/Rcpp/include/Rcpp/vector/Vector.h:58: undefined reference to `Rf_allocVector'
graphmatch_rcpp.o: In function `Rcpp_ReplaceObject':
The answer to this similar (in my eyes) question seems to be inapplicable
Undefined reference errors when including Rcpp.h
as I am using LinkingTo and trying to create an R package
Edit: as the first answer suggested, I have tried building RcppZiggurat with the following Makevars.win :
PKG_CPPFLAGS = -I. -I../inst/include -IC:/tools/gsl/include
## Use the R_HOME indirection to support installations of multiple R version
PKG_LIBS = $(LDFLAGS) -L../inst -L$(LIB_GSL)/lib/x64 $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppGSL:::LdFlags()")
I am getting these errors.
ziggurat.o:ziggurat.cpp:(.text+0x86): undefined reference to `gsl_rng_free'
ziggurat.o:ziggurat.cpp:(.text+0xa6): undefined reference to `gsl_rng_free'
ziggurat.o:ziggurat.cpp:(.text+0xc6): undefined reference to `gsl_rng_free'
ziggurat.o:ziggurat.cpp:(.text+0x1254): undefined reference to `gsl_rng_set'
I was able to get the windows build running successfully using this template for Makevars.win
https://github.com/adalisan/RGraphM/blob/master/src/Makevars.win.gen
and this script creates the Makevars.win
https://github.com/adalisan/RGraphM/blob/master/configure.win
Once the pre-built gsl windows libraries have been put in the directory defined by env. var LIB_GSL, both the compilation and linking steps worked.
One small issue is that the zip file for the pre-built libraries downloaded here include there are two subdirectories for two sub-architectures (i386 and x64)
You should make sure that you link against the right version and that -L"$(LIB_GSL)\lib\$(ARCH)" argument in the linker calls evaluates to the right directory for the sub-arch.
Thanks to the creators of Rcpp and RcppGSL for making the packaging of gsl-based code easier.
You have a misunderstanding of how this works:
The LinkingTo: field of DESCRIPTION does not linking, despite its name. It only helps for header files. Which is why your package compiled but did not link.
You need linker instructions. As has been said before, the mvabund and RcppZiggurat packages both link to the GSL using a tool from RcppGSL.
RcppZiggurat in particular may be a good example to follow as it is small. There is also an entire example package included in RcppGSL -- which we use as reference as well as in unit testing.

Compiling R 3.1.1 using Intel MKL: --enable-R-shlib triggers undefined reference to symbol error

Problem
I need to compile R 3.1.1 with shared library (--enable-R-shlib) with ICC/MKL (Composer XE 2013 SP 1.3.174) in order to use a specific IDE (rstudio) and I am running into trouble.
Context
Some information about my platform:
OS: Ubuntu 14.04.1 LTS
Kernel: 3.13.0-30
Compiler: Intel ICC (Composer XE 2013 SP 1.3.174)
MKL: Intel MKL (Composer XE 2013 SP 1.3.174)
I previously had a working installation of R 3.1.1 (without shared library) compiled with ICC/MKL (Composer XE 2013 SP 1.3.174) as follows:
$source /opt/intel/composerxe/bin/compilervars.sh intel64
$export CC="icc"
$export CXX="icpc"
$export AR="xiar"
$export LD="xild"
$export CFLAGS="-O3 -ipo -openmp -xHost -multiple-processes"
$export CXXFLAGS="-O3 -ipo -openmp -xHost -multiple-processes"
$export MKL="-lmkl_gf_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread"
$./configure --with-lapack --with-blas="$MKL" --build="x86_64-linux-gnu" --host="x86_64-linux-gnu" > log_cfg
$make > log_make_out 2> log_make_err
#make install
When I run the commands above the compilation is successful and log_make_err is empty at the end of the process.
As I said in the beginning, I now need to compile R with shared library (--enable-R-shlib). Therefore, I tried to use the exact same commands as before (same computer) and changed the configure line to:
$./configure --with-lapack --with-blas="$MKL" --build="x86_64-linux-gnu" --host="x86_64-linux-gnu" --enable-R-shlib
This gives the following output:
R is now configured for x86_64-pc-linux-gnu
Source directory: .
Installation directory: /usr/local
C compiler: icc -std=gnu99 -O3 -ipo -openmp -xHost -multiple-processes
Fortran 77 compiler: gfortran -g -O2
C++ compiler: icpc -O3 -ipo -openmp -xHost -multiple-processes
C++ 11 compiler: icpc -std=c++11 -O3 -ipo -openmp -xHost -multiple-processes
Fortran 90/95 compiler: x86_64-linux-gnu-gfortran -g -O2
Obj-C compiler: x86_64-linux-gnu-gcc
Interfaces supported: X11, tcltk
External libraries: readline, BLAS(generic), LAPACK(in blas), lzma
Additional capabilities: PNG, JPEG, TIFF, NLS, cairo
Options enabled: shared R library, R profiling
Recommended packages: yes
In this case, the compilation is not successful and log_make_err contains the following:
ld: /tmp/ipo_iccUpPSPh.o: undefined reference to symbol '__kmpc_end##VERSION'
/opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/intel64/libiomp5.so: error adding symbols: DSO missing from command line
make[3]: *** [R.bin] Error 1
make[2]: *** [R] Error 2
make[1]: *** [R] Error 1
make: *** [R] Error 1
When I run diff on the output of the configure script for each case, nothing strange shows up:
753c753
< Options enabled: R profiling
---
> Options enabled: shared R library, R profiling
I tried to include the full output of the make command but it exceeds the maximum number of characters allowed and using pastebin is not a good practice at SO.
Let me know if you feel like there is information missing that could help you lead me in the right direction.
Thanks!
I've been compiling R against MKL, and its a challenge. I haven't been doing it on ubuntu, but from your configuration four things leap out at me:
Using icc to compile against mkl, you usually have to source a shell script in one of the mkl directories to set a bunch of environment variables to the correct dynamic library search paths. I don't see that you're doing this?
You can make your life a lot easier by linking against libmkl_rt.
My configure line (which is for gcc) uses
--with-blas="mkl_rt" --with-lapack BLAS_LIBS="-lmkl_rt -liomp5 -lpthread"
You're trying to enable openmp with compiler directives without sending --enable-openmp to configure.
You're mixing icc with gfortran, and not setting a link directive or library list for gfortran. MKL may not link against gfortran unless its recompiled -- some of Intel's documentation says recompilation is necessary; I can't get a straight answer from them. gfortran with your directives doesn't seem to know that you want it to be multi-threaded, and it may not know how to find libraries.
Adding the following to the script solved it for me:
export MAIN_LDFLAGS='-openmp'
Everything else stayed the same.
Hopefully this will be useful to someone else.

Construction of flags in R CMD SHLIB

I am having a lot of trouble understanding the steps that construct the compilation flags when using R CMD SHLIB. I use the following:
in ~/.R/Makevars define `CPPFLAGS=-O3'
in src/Makevars.win define PKG_CPPFLAGS = -O3
include Rcpp and RcppGSL as dependencies in the DESCRIPTION file
where the second step is clearly redundant, but I do it just in case PKG_CXXFLAGS was initialized to something different.
But when I run R CMD SHLIB I find my -O3 flags but also -UNDEBUG -Wall -pedantic -g -O0. Where can those additional flags be coming from? Can Rcpp and RcppGSL affect these flags in a way I can't control through my Makevars.in?
For per-user, or personal settings, I just use ~/.R/Makevars which will affect all R CMD SHLIB or R CMD COMPILE calls, including those from Rcpp.
You can also define them in per-project Makefiles, or src/Makevars, and besides the per-user files, you can of course edit the system-wide variant (which is where the other values that confused you came from). See the file $R_HOME/etc/Makeconf for the latter.
Lastly, DESCRIPTION has nothing to do here.

Resources