Saturday, September 20, 2014

Getting ready to use Rserve

This is a quick test to connect to Rserve

I am working on CentOS release 6.5 (Final)

1. Let's set JAVA_HOME to do that find the value of JVM installed
update-alternatives --display java

It shows me that Current 'best' version is /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java accordingly I will set JAVA_HOME to /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/. To do this I add the following line to /etc/profile.d/java.sh. I will be copying the Rserve jar files to the JAVA_HOME/lib/ext/ folder so configuration defining CLASSPATH is also added (see next step for details on this)
export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib/ext/Rserve.jar:$JAVA_HOME/lib/ext/REngine.jar
** Make sure there is no gap between the "=" sign above. Once done you will have to either logout or login again or source using
source /etc/profile.d/java.sh

2. Download the most recent tar file from "Most Recent Snapshots" at http://rforge.net/Rserve/files/, untar them and copy the jar files from the archive into $JAVA_HOME/lib/ext/
wget wget http://rforge.net/Rserve/snapshot/Rserve_1.8-0.tar.gz
tar -xvzf Rserve_1.8-0.tar.gz
cp Rserve/inst/java/*.jar /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/lib/ext/.

3. Now let's write a simple Hello.java
import org.rosuda.REngine.*;
import org.rosuda.REngine.Rserve.*;
class Hello {
    public static void main(String[] args) throws RserveException, REXPMismatchException {
        RConnection c = new RConnection();
        REXP x = c.eval("R.version.string");
        System.out.println(x.asString());
        System.out.println("Hello World!"); // Display the string.
    }
}

4. Now compile and Run
javac Hello.java 
java Hello

Installing Rserve

Following are the steps that were taken to install Rserve for an application. I am working on CentOS release 6.5 (Final)

The two are available at: http://rforge.net/Rserve/ and http://rforge.net/FastRWeb/

All the steps below were performed as root unless specified otherwise.

Rserve

1. Check the version of R and if it is not installed install R.  You may have to install new repository EPEL i.e. Extra Packages for Enterprise Linux.  Here is a page describing that http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/

yum install R

Now I have R version 3.1.1 (2014-07-10) working

2. Start R and type
install.packages("Rserve")


Once install process is done you can check the instal files using
ls -al /usr/lib64/R/library/Rserve/

3.  Created a file /etc/Rserv.conf with following content to run the R process as apache
uid apache
gid apache
workdir /tmp/Rserv
fileio enable
port 6311
maxinbuf 262144

4. Start Rserve and check if running then stop it
R CMD Rserve --gui-none --no-save
ps -eaf | grep Rserve
killall Rserve

5. Add a startup script by creating a file /etc/init.d/Rserve and adding the content. Thanks to (http://paranumeral.blogspot.com/2013/03/a-basic-etcinitdrserve-start-rserve-at.html) on which I have used most of the content.
#!/bin/sh
# chkconfig: 2345 20 80
#
# description: rserve startup script
#
RSERVE=/usr/lib64/R/bin/Rserve
. /etc/rc.d/init.d/functions
test -f /etc/Rserv.conf
export R_HOME=/usr/lib64/R
RETVAL=0
case "$1" in
   start)
      echo -n "Starting Rserve: "
      [ -f $RSERVE ] || exit 1
      $RSERVE --gui-none --no-save
      RETVAL=$?
      echo
      [ $RETVAL -eq 0 ] && touch /var/lock/subsys/rserve
      ;;
  stop)
      echo -n "Shutting down RServe: "
      killproc $RSERVE
      RETVAL=$?
      echo
      [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/rserve
      ;;
  restart|reload)
      $0 stop
      $0 start
      RETVAL=$?
      ;;
  status)
      status $RSERVE
      RETVAL=$?
      ;;
  *)
      echo "Usage: $0 {start|stop|restart|status}"
      exit 1
esac
exit $RETVAL

6. Change permissions of auto start script, test start and stopping:
chmod 755 /etc/init.d/Rserve 
service Rserve start
service Rserve stop

7. Finally configure to start with reboot of machine
chkconfig --level 2345 Rserve on


Friday, September 12, 2014

Thursday, September 11, 2014

Install Process

Followed the README as is. Since I am working on CentOS release 6.5  I had to install a newer version of cmake from its source code and configured it in path

cmake install

wget http://www.cmake.org/files/v3.0/cmake-3.0.1.tar.gz
tar -xvzf cmake-3.0.1.tar.gz
cd cmake-3.0.1
./configure --prefix=~/CMAKEBIN
gmake
make install
vi ~/.bashrc

# Add the following:
# export PATH=~/CMAKEBIN/bin:$PATH
source ~/.bashrc

Installing okular

su -
yum install kdegraphics.x86_64

deal.II install

Followed the README file and video tutorial Obtaining and installing deal.II

cd deal.II
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=~/deal.IIInstall ..
make install

Once installed I have the following folders in the install directory


Test Example

cd ~/deal.IIInstall/examples/step-1
cmake -DDEAL_II_DIR=../ .
make



make run
okular grid-2.eps