Tuesday, November 26, 2013

Debug Fortran Program with gdb

1.    Compile the program with “-g” option. Eg,
gfortran -g foo.f90 -o foo
2.    Start program with gdb
gdb foo
3.    Get help about the debug commands
help
help command
4.    Set breakpoints
break line_number                                   (break at a given line number)
break function_name                              (break at the entry of a specified function)
If multiple source files are involved, specify the file name like
break file_name:line_number
break file_name:function_name
5.    Set command line arguments (optional)
set args option1 option2
6.    Start running under gdb (and stop at the first breakpoint if set)
run
run option1 option2                                (give command line arguments)
7.    List all breakpoints
info breakpoints
8.    Delete breakpoint(s)
delete number                                              (delete the breakpoint numbered number)
delete                                                           (delete all breakpoints)
clear  line_number                                       (delete breakpoint at a particular line number)
clear function_number                                 (delete breakpoint at a particular function)
9.    List program source code
list                                                (print out some lines of codes around the current stop point)
list line_number                            (print out some lines of codes around line_number)
list line_number_start,line_number_end
list file_name:line_number
10.    Inspect variables
print variable_name
To print values of an allocatable array
print *((real_8 *)my_array + 1)  (print the second element of a real*8 array)
print *((real_8 *)my_array + 1)@5 (print five elements from number 2)
print my_array[0]@25                                  (print the first 25 elements in an array)
11.    Continue running until the next breakpoint
continue
12.    Execute current line and then stop execution again (function call will be completely executed before stop execution if current line calls a function)
next
13.    Execute current line and stop (will stop at the first line of a function called if current line calls a function)
step
14.    Step out of a loop (if at the last line of a loop) and then stop at the first line after the loop
until
15.    Exit gdb
quit

Sunday, October 27, 2013

How to recover sudo if /etc/sudoers file is invalid?

If /etc/sudoers file is damaged/changed so that sudo command cannot be invoked, the best method of saving the world is to call utility 'pkexec':

   pkexec command_to_run

For example, to edit the /etc/sudoers file is simply

   pkexec visudo

Tuesday, October 1, 2013

Some useful PBS/Maui commands

    Command  Description
    showq  Show a detailed list of submitted jobs
    showbf  Show the free resources (time and processors available) at the moment
    checkjob job.ID  Show a detailed description of the job job.ID
    showstart job.ID  Give an estimate of the expected started time of the job job.ID
    pbsnodes    List nodes and their state
    qdel $(qselect -u abc123) Delete all jobs belonging to user abc123

Monday, September 30, 2013

How to run R scripts in batch mode with arguments

Run R script as:

R CMD BATCH --no-save --no-restore '--args 1 c(2,3,4) matrix(c(5,6,7,8),nrow=2)' script.R

The script.R has content:

# This just reads the two arguments passed from the command line
# and assigns them to a vector of characters.
args <- commandArgs (TRUE)
# Here you should add some error exception handling code
# in case the number of passed arguments doesn't match what
# you expect (check what Forester did in his example)

# Parse the arguments (in characters) and evaluate them
vec1 <- eval( parse( text= args[1] ) )
vec2 <- eval( parse( text= args[2] ) )
mat1 <- eval( parse( text= args[3] ) )

# Check
print(vec1) # prints a vector of length 1
print(vec2) # prints a vector of length 3
print(mat1) # prints a 2 x 2 matrix


Reference:
http://shihho.wordpress.com/2012/11/30/r-how-to-run-r-scripts-in-batch-mode-with-arguments/

Saturday, September 21, 2013

Tuning NFS Performance

On a Ubuntu system, by default the NFS daemon will only spawn up to 8 processes. The default number may not be sufficient to handle multiple nfs connections by the clients for a heavily loaded system. To check whether the default is sufficient, we can look at RPC statistics using nfsstat command on the NFS client:

# nfsstat -rc
Client rpc stats:
calls      retrans    authrefrsh
236317426   2          236317430


In the example above, the retrans (retransmissions) value is larger than 0, indicating that the number of available NFS kernel threads on the server is insufficient to handle the requests from this client.

To increase the number of NFS threads on the server, we need to change the configuration of item RPCNFSDCOUNT in files /etc/default/nfs-kernel-server and /etc/init.d/nfs-kernel-server. Increase this number to 32 on a moderately busy server, or up to 128 on a more heavily used system. Restart NFS service and then run command nfsstat -rc on the client to check whether the number of NFS threads is sufficient. If the retrans value is 0, it is enough; otherwise, increase the number of threads further.

On the clients, we can change the mount command options rsize and wsize to optimize transfer speeds. These two options specify the size of the chunks of data that the client and server pass back and forth to each other. By default, most clients will mount remote NFS file systems with an 8-KB read/write block size. Significant performance gains can be made to NFS performance with some simple tweaks to the rsize/wsize options. It is suggested (see reference 1) to mount with the following options on the client for improved NFS performance:
    rsize=32768,wsize=32768,intr,noatime
If the NFS filesystem is mounted via /etc/fstab, change the mount configuration there like the following:
   server:/path/to/shared /shared nfs rsize=32768,wsize=32768,intr,noatime

Reference:
1. http://www.techrepublic.com/blog/linux-and-open-source/tuning-nfs-for-better-performance/

Friday, May 10, 2013

Some SGE query commands

To list all the queue names:
   qconf -sql
 
To show detailed configurations about a queue:
   qconf -sq quene_name
 
To show the current status of the queues and the jobs associated with the queues
   qstat -g c 

Wednesday, April 24, 2013

Ubuntu List User Processes

List all processes owned by a user:
ps -fp $(pgrep -d, -u USERID)

To kill all process owned by a user:
sudo pkill -9 -u USERID

Tuesday, March 12, 2013

Making loops in shell script


(1)
for i in $(seq 1 10)
do 
 echo $i
 //do some stuff
done

(2)
for i in `seq 1 10`
do
 //do some stuff
done

(3)
for i in 1 2 3 4 5 6 7 8 9 10
do
 //do some stuff 
done
 
(4) 
for i in {1..10} {15..20}
do //do some stuff
done

(5)
s=0
while [ "$s" -lt 10 ]; do s=`echo $s+1|bc`; echo $s; done

(6)
for (( i=1; c<=10; i++ ))
do
 // do some stuff
done
 
(7) Loops through files in a directory
files=( $( ls /path/to/directory ) )  #list files in an array
n=${#files[*]}   #array size
for (( i=0; i < n; i++ ))
do 
 echo File number $((i+1)) is ${files[$i]}
done