Wednesday, April 11, 2012

With Fortran, how to overwrite the present line on the console screen?

program print_on_the_same_line

integer :: I, N

N=5

open(6,CARRIAGECONTROL ='FORTRAN')

do I=1,N
call sleep(1)
write(6,'(1H+" ",I,a,I)') I,' out of',N
enddo

close(6)

stop
end program

****************************************************
The above Fortran codes are adopted from the link:
http://stackoverflow.com/questions/1390125/how-do-i-format-a-print-or-write-statement-to-overwrite-the-current-line-on-the

Sunday, March 11, 2012

Using an old router as a wireless Access Point

For convenience, we call, in this note, the present router as master router, and the old router as AP.

Firstly, assume the master router has been configured with the following settings:
LAN IP: 192.168.0.1
Subnet Mask: 255.255.255.0
DHCP Server: Yes
UPnP: On
Wireless SSID and security mode: set up according to router manual

Before connecting the master router and AP, configure the AP with settings:
LAN IP: within subnet of master router such as 192.168.0.2
Subnet Mask: 255.255.255.0
DHCP Server: No
UPnP: Off
Wireless SSID and security mode: the same as that of the master router

Finally, connect the master router and the AP via LAN port to LAN port directly and leave the WAN port of the AP disconnected.
Rebooting one or both devices maybe necessary to take effect the configurations.

Tuesday, January 17, 2012

Install Rmpi with MPICH2 environment

While installing Rmpi package on my Ubuntu system, I encountered the following problem:
******* some outputs ommitted here******
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/usr/local/lib/R/site-library/Rmpi/libs/Rmpi.so':
/usr/lib/libmpich.so.3: undefined symbol: MPL_trid
Error: loading failed
In addition: Warning message:
.Last.lib failed in detach() for 'Rmpi', details:
call: dyn.unload(file.path(libpath, "libs", paste("Rmpi", .Platform$dynlib.ext,
error: shared object '/usr/local/lib/R/site-library/Rmpi/libs/Rmpi.so' was not loaded
******** some outputs ommitted here ******

After searching quite a lot by google, I found that this problem could be solved by setting mpicc compiler/linker instead of gcc (by default, R uses gcc on Linux system) to compile package sources while installing Rmpi. (A relevant discussion can be found here http://r.789695.n4.nabble.com/Re-R-CMD-INSTALL-configure-args-and-CC-customization-td3802485.html)

Here is the solution:
(1) Edit /etc/R/Makeconf (administrator priviledge required) or ~/.R/Makevars (if installing Rmpi as user specific package) by modifying/setting the following two entries:
CC=mpicc
SHLIB_LD=mpicc

(2) Run the following code (in R) to install Rmpi:
install.packages('Rmpi',configure.args="--with-Rmpi-type=MPICH2 --with-Rmpi-include=/usr/lib/mpich2/include --with-Rmpi-libpath=/usr/lib/mpich2/lib/ --with-mpi=/usr/include/mpich2/")
or install from shell:
R CMD INSTALL Rmpi_***.tar.gz --configure-args="--with-Rmpi-type=MPICH2 --with-Rmpi-include=/usr/lib/mpich2/include --with-Rmpi-libpath=/usr/lib/mpich2/lib/ --with-mpi=/usr/include/mpich2/"
Note: please make appropriate changes in the above code if MPICH2 installation path is different.

Update on 3 October 2013
Here is a simpler solution. Instead of modifying Makeconf, we can specify compiler options with configure.vars argument  (or --configure-vars in command line):
install.packages('Rmpi',configure.args="--with-Rmpi-type=MPICH2 --with-Rmpi-include=/usr/lib/mpich2/include --with-Rmpi-libpath=/usr/lib/mpich2/lib/ --with-mpi=/usr/include/mpich2/",configure.vars="CC=mpicc")