### Read pbdMPI vignettes first at
### http://cran.r-project.org/web/packages/pbdMPI/vignettes/pbdMPI-guide.pdf
###
### Also, pbdDEMO vignettes at
### http://cran.r-project.org/web/packages/pbdDEMO/vignettes/pbdDEMO-guide.pdf
###
### This file is only a quick installation for Solaris, Linux, and Mac OS X.
### See `INSTALL.win.src' for a source installation for Windows system.
### See `INSTALL.win.bin' for a binary installation for Windows system.

--- 'OpenMPI' Installation:
   Obtain 'OpenMPI' from 'http://www.open-mpi.org/'

     > tar zxvf openmpi-1.5.4.tar.gz
     > cd openmpi-1.5.4
     > ./configure
     > ./make
     > ./make install

   These install files to '/usr/local/bin', '/usr/local/lib', and
   '/usr/local/include' etc.  i.e. ${MPI_ROOT} is '/usr/local'.


--- Set environment variables:
   For 'csh' or 'tcsh', I would set

     > setenv PATH /usr/local/bin:$PATH
     > setenv LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH

   For 'sh', 'bash', or 'ksh', I would set

     > export PATH=/usr/local/bin:$PATH
     > export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

   - 'PATH' is to make sure I can run 'mpiexec', 'mpirun', or 'orterun'.
   - 'LD_LIBRARY_PATH' is to make sure I can reach 'libmpi.so'.

   *** The other way is to modify '/etc/ld.so.conf' and to use the command
       'ldconfig' to update the system searhing path for 'libmpi.so'.


--- Test 'OpenMPI':
   In order to test if 'OpenMPI' works correctly, I simply run

     > mpiexec -np 2 hostname

   and this should show host name twice if environment variables are correct.


--- 'pbdMPI' Installation:
0. Download and extract 'pbdMPI'

     > tar zxvf pbdMPI_0.2-3.tar.gz

1. Default Installation:
   This should work with most platforms with 'OpenMPI' installed. The
   configuration detects the flags and libraries from
   'mpicc --showme:*' which is more portable.

     > R CMD INSTALL pbdMPI

2. Non-default Installation:

     > R CMD INSTALL pbdMPI \
     +   --configure-args="--with-mpi-type=OPENMPI \
     +                     --with-mpi=/usr/local"

3. Unusual Installation:
   Suppose 'PATH' and 'LD_LIBRARY_ATH' are set, but I don't use default paths
   to header files and libraries, then I can install 'pbdMPI' by

     > R CMD INSTALL pbdMPI \
     +   --configure-args="--with-mpi-type=OPENMPI \
     +                     --with-mpi-include=/usr/local/ompi/include  \
     +                     --with-mpi-libpath=/usr/local/ompi/lib" \

   Note that I still need 'PATH' and 'LD_LIBRARY_PATH' to be set correctly in
   this case.


--- Test 'pbdMPI':
   Suppose 'PATH' and 'LD_LIBRARY_ATH' are set correctly, I can run test
   examples by

     > cd pbdMPI/inst/examples/test_spmd/
     > ./00_test_all.sh


### `INSTALL.win.src'

--- 'Rtools' Installation:
   Download 'Rtools216.exe' from 'http://cran.r-project.org/bin/windows/Rtools/'
   and click it to install to

     'C:\Rtools'


--- 'MS-MPI' Installation:
   Download 'HPC Pack 2012 R2 MS-MPI Redistributable Package' from
   'http://http://www.microsoft.com/en-us/download/'.
   File 'MSMPISetup.exe' is for both 32 and 64 bits system.
   Click on it and install them to the default directory
   'C:\Program Files\Microsoft MPI'.


--- Set environment variables:
   Suppose 'R', 'Rtools', and 'MS-MPI' are all installed by default. I have
   a batch file 'set_mpisrc.bat' as the following to set the environment
   variables. In short, 'MPI_ROOT' should be set to 'MS-MPI' root directory,
   and added '%MPI_ROOT%/bin' to 'PATH'.

@ECHO OFF
SET R_HOME=C:\Program Files\R\R-3.0.1\
SET RTOOLS=C:\Rtools\bin\
SET MINGW=C:\Rtools\gcc-4.6.3\bin\
SET MPI_ROOT=C:\Program Files\Microsoft MPI\
SET PATH=%R_HOME%;%R_HOME%BIN\;%RTOOLS%;%MINGW%;%MPI_ROOT%BIN\;%PATH_ORG%


--- Test 'MS-MPI':
   In order to test if 'MS-MPI' works correctly, I run

     C:/> set_mpisrc
     C:/> mpiexec -np 2 hostname.exe

   and this should list two host names twice if environment variables are
   correct. User's id and password may be required to launch MS-MPI.


--- 'pbdMPI' Installation:
   Default Installation:

     C:/> set_mpisrc
     C:/> tar zxvf pbdMPI_0.2-3.tar.gz
     C:/> R CMD INSTALL --build --no-test-load pbdMPI
     C:/> R CMD INSTALL pbdMPI_0.2-3.zip


--- Test 'pbdMPI':
   Suppose all environments are set correctly, I can run test examples by

     C:/> set_mpisrc
     C:/> cd pbdMPI\examples\test_spmd\
     C:/> sh 00_test_all.win


### `INSTALL.win.bin'

--- 'MS-MPI' Installation:
   Download 'HPC Pack 2012 R2 MS-MPI Redistributable Package' from
   'http://http://www.microsoft.com/en-us/download/'.
   File 'MSMPISetup.exe' is for both 32 and 64 bits system.
   Click on it and install them to the default directory
   'C:\Program Files\Microsoft MPI'.


--- Set environment variables:
   Suppose 'R', 'Rtools', and 'MS-MPI' are all installed by default. I have
   a batch file 'set_mpi.bat' as the following to set the environment
   variables. In short, 'MPI_ROOT' should be set to 'MS-MPI' root directory,
   and added '%MPI_ROOT%/bin' to 'PATH'.

@ECHO OFF
SET R_HOME=C:\Program Files\R\R-3.0.1\
SET MPI_ROOT=C:\Program Files\Microsoft MPI\
SET PATH=%R_HOME%;%R_HOME%BIN\;%RTOOLS%;%MINGW%;%MPI_ROOT%BIN\;%PATH_ORG%


--- Test 'MS-MPI':
   In order to test if 'MS-MPI' works correctly, I run

     C:/> set_mpi
     C:/> mpiexec -np 2 hostname.exe

   and this should list two host names twice if environment variables are
   correct. User's id and password may be required to launch MS-MPI.


--- 'pbdMPI' Installation:
   Default Installation:

     C:/> set_mpi
     C:/> R CMD INSTALL pbdMPI_0.2-3.zip


--- Test 'pbdMPI':
   Suppose all environments are set correctly, I can run test examples by

     C:/> set_mpi
     C:/> mpiexec -np 2 Rscript.exe -e "library(pbdMPI);init();finalize()"

