Saturday, August 27, 2011

MySQL with ODBC driver

Configuring MySQL and ODBC driver

# more /etc/odbcinst.ini
# Example driver definitinions
#
#
# Included in the unixODBC package
[PostgreSQL]
Description    = ODBC for PostgreSQL
Driver        = /usr/lib64/libodbcpsql.so
Setup        = /usr/lib64/libodbcpsqlS.so
FileUsage    = 1
# Driver from the MyODBC package
# Setup from the unixODBC package
[MySQL]
Description    = ODBC for MySQL
Driver        = /usr/lib64/libmyodbc3.so
Setup        = /usr/lib64/libodbcmyS.so
FileUsage    = 1

/etc/odbc.ini

# more /etc/odbc.ini
[ODBC]
Description = Moab MySQL Database
Driver = MySQL
USER = root
PASSWORD = <write sql root password here>
Server = localhost
Database = Moab
Port = 3306
Socket = /var/lib/mysql/mysql.sock
Option =
Stmt =
The above standard odbc driver file syntax should be used to configure how your application talks to MySQL. Which means the file will have the same content as /etc/odbc.ini. For example application moab uses the file dsninfo.dsn in /opt/moab directory.
# more /opt/moab/dsninfo.dsn
[ODBC]
Driver = MySQL
USER = root
PASSWORD = <write sql password here>
Server = localhost
Database = Moab
Port = 3306
Socket = /var/lib/mysql/mysql.sock
Option =
Stmt =

Testing

Test the ODBC to MySQL connection by running the isql command, which reads the /etc/odbc.ini file:
# isql -v ODBC
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
Segmentation fault

Solution

To get rid of the error "segmentation fault" we need to recompile and install the unixODBC with an extra configure options.

Installing unixODBC

Web link: http://www.unixodbc.org/
# wget ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.0.tar.gz
# tar xzvf unixODBC-2.3.0.tar.gz
# cd unixODBC-2.3.0
# ./configure --enable-stats=no --enable-gui=no --sysconfdir=/etc --prefix=/usr
# make
# make install
--enable-stats=no is an attempt to correct the segmentation fault.
--enable-gui=no provides no GUIs, is used when ./configure can't find the X includes.

Installing ODBC Driver: MyODBC

Web link: http://www.mysql.com/products/connector/
Web link: http://www.mysql.com/downloads/connector/odbc/
# rpm -ivh --nodeps MyODBC-3.51.07-1.i586.rpm
--nodeps avoids aborting because rpm can't find libmyodbc that does exist in /usr/lib.
When isql won't work because it can't find the library, go make a link in /usr/lib to libmyodbc3-3.51.07.so and name it libmyodbc.so.

Testing

Test the ODBC to MySQL connection by running the isql command, which reads the /etc/odbc.ini file:
# isql -v ODBC
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
sreeSQL> show tables
+-----------------------------------------------------------------+
| Tables_in_Moab                                                  |
+-----------------------------------------------------------------+
| EventType                                                       |
| Events                                                          |
| GeneralStats                                                    |
| GenericMetrics                                                  |
| Jobs                                                            |
| Moab                                                            |
| NodeStats                                                       |
| NodeStatsGenericResources                                       |
| Nodes                                                           |
| ObjectType                                                      |
| Requests                                                        |
| mcheckpoint                                                     |
+-----------------------------------------------------------------+
SQLRowCount returns -4294967284
12 rows fetched
SQL> quit
[root@cuda unixODBC-2.3.0]#

Thursday, August 25, 2011

Applescript for Apple Mail

Almost 6 months back I encountered a problem with desktop mail client on Mac. I had to use Applescript to solve the problem. I always wanted to copy whatever email I get onto my mac. I setup rules to copy certain emails based on specific criteria on my mac. The problem was whenever I read an email it was still unread on my mac. I tried every other method to make their status read. Nothing worked and so finally I opted for Applescript. You can see that the number of unread mail count on my mac is 716 while inbox has zero.

I wrote this applescript to solve this problem. Here it is:
tell application "Mail"
	set theMailboxes to every mailbox
	repeat with theMailbox in theMailboxes
		set theMessages to every message of theMailbox
		repeat with theMessage in theMessages
			if read status of theMessage is false then
				set read status of theMessage to true
			end if
		end repeat
	end repeat
end tell


It doesn't change the status of new emails in your inbox. It only changes the status of emails on your mac. Once you run the script in applescript editor you can see the count dropping down to zero very quickly.

The good thing with the script is you can make this run at specific times in a day by using ical. Just use alarm options in iCal to setup to run this script at certain of the day. I run this script at 8am early in the morning and at noon and at 4 pm, etc so that I don't see the annoying email count on my mac.

Wednesday, August 24, 2011

Locking screen on Mac from Terminal

I do all my work from a terminal on my mac. I try to use as much keyboard as possible for everything. Whenever I need to lock my screen which I say many times in a day I either use hot corners or key chain options. Then I thought why not from terminal it self. In case you are also interested to know how to do this, here is how I did it.

Open up a terminal and do these commands. The last command "schlock" will lock the screen whenever you execute it from the terminal. Of course, you can give what ever name you like. Make sure that it doesn't have space between the words, for example "screen lock". You can always give something like "screen_lock", etc.

$ echo "alias scrlock='/System/Library/CoreServices/\"Menu Extras\"/\
User.menu/Contents/Resources/CGSession -suspend'" >> ~/.bashrc
$ source ~/.bashrc
$ scrlock

Tuesday, August 23, 2011

Installing XmGrace (Grace) on Mac OS X

We need to install motif libraries first. You can download binary from here:
http://www.ist.co.uk/downloads/motif_download.html

Grace Download: http://plasma-gate.weizmann.ac.il/Grace/

$ cd Desktop
$ wget ftp://ftp.fu-berlin.de/unix/graphics/grace/src/grace5/grace-latest.tar.gz
$ tar xzvf grace-latest.tar.gz
$ cd grace-5.1.22
$ ./configure --x-includes=/usr/X11/include --x-libraries=/usr/X11/lib \
--with-motif-library=-lXm  --with-extra-incpath=/usr/OpenMotif/include:/Users/sm4082/fftw-2.1.5/include \
--with-extra-ldpath=/usr/OpenMotif/lib:/Users/sm4082/fftw-2.1.5/lib
$ make
$ sudo make install
$ echo "export PATH=$PATH:/usr/local/grace/bin" >> ~/.bashrc
$ source ~/.bashrc
$ xmgrace

Now you should have xmgrace at your prompt. Cool. Right?

Monday, August 22, 2011

Torque qsub wrapper/submit filter shell script

I have recently written this shell script to act as a filter to pbs job scripts submitted on our clusters. For more information look online for Torque administrator manual.
#!/bin/bash

##########################################################################################################
# This acts as a wrapper/filter to qsub. Written by Sreedhar Manchu.
# Added on Aug 8th, 2011
# http://www.clusterresources.com/torquedocs21/a.jqsubwrapper.shtml
##########################################################################################################

# Memory Variables.
# If you want to provide more memory for jobs than the currently allocated memory on
# nodes on certain chassis you just need to change these variables.

mem16gb_limit=14		 # Right now 14GB memory is allocated for jobs on 16GB nodes
mem32gb_limit=30		 # Right now 30GB memory is allocated for jobs on 32GB nodes
mem_bigmem_min=18        # Minimum memory required for bigmem queue in GB
memory_per_core=1536	 # Memory allocated per core is 1536MB (1.5GB). If you are changing this number make sure 
                         # that the processors per node times this number is at least 1GB less than physcal memory
						 # present on the node. In this case, it is 16GB. 8*1536MB=12GB < 15GB. This number 
                         # should be in MB.

wtime_bigmem_max=172800  # Bigmem queue maximum walltime in seconds (48 hours)
                         # Should be a multiple of 3600.
wtime_p12_max=43200      # p12 queue maximum walltime in seconds (12 hours)
                         # Should be a multiple of 3600.
wtime_p48_max=172800     # p48 queue maximum walltime in seconds (48 hours)
                         # Should be a multiple of 3600.
wtime_serlong_min=172860 # serlong queue minimum walltime in seconds (48 hours 1 minute)
					     # The remainder after deviding it with 3600 should be a multiple of 60.
wtime_serlong_max=345600 # serlong queue maximum walltime in seconds (96 hours)
                         # Should be a multiple of 3600.
wtime_ser2_min=60		 # ser2 queue minimum walltime in seconds (1 minute).
                         # Should be a multiple of 60. For example, it can be 120 (=2*60)
wtime_ser2_max=172800    # ser2 queue maximum walltime in seconds (48 hours)
                         # Should be a multiple of 3600.

# Don't change the code in the block bordered by dashes

#---------------------------------------------------------------------------------------------------------

if [ $# -eq 1 ]   # Enters loop when job runs through only script. Hence argument is 1.
then              # This part of the code makes sure that script follows the pbs scripting rules.
	counter=0
	line_count=0
	while read -r i
	do
   		if [ $line_count -eq 0 ]
   		then
      		if echo $i | egrep "^#\! */" 2>&1 > /dev/null  # Looks for shebang/hashbang (#!) in the first line
      		then
         		echo $i
      		else
         		echo -e "\nFirst line should have shebang/hashbang (#!). Please fix the script\n" > /dev/tty
				echo -e "For example, it can be #!/bin/sh or #!/bin/bash , etc.\n" > /dev/tty
         		echo -e "For more information please refer to https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
         		exit -1
      		fi
      		line_count=1
      		pbs_operatives="not_done"
      		pbs_line_count=0
      		pbs_first_line="yes"
      		continue
   		elif [[ $pbs_operatives == "not_done" ]]
   		then
      		if [ $pbs_first_line = "yes" -a `echo $i | egrep "^$" 2>&1 > /dev/null` $? -ne 0 -a `echo $i | egrep "^ *#" | grep -v "^ *#PBS *" 2>&1 > /dev/null` $? -ne 0 -a `echo $i | egrep "^ *#PBS *" 2>&1 > /dev/null` $? -ne 0 ]
      		then
         		echo -e "\nPBS operatives such as \"#PBS -l nodes=1:ppn=2,walltime=05:00:00\" are either missing or not declared immediately after shebang/hashbang line \"#\!/bin/bash\". Please fix the script.\n" > /dev/tty
         		echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
         		exit -1
      		else
         		pbs_first_line="no"
         		if [ `echo $i | egrep "^$" 2>&1 > /dev/null` $? -eq 0 -o `echo $i | egrep "^ *#" | grep -v "^ *#PBS *" 2>&1 > /dev/null` $? -eq 0 ]
         		then
            		echo $i
            		line_count=$(($line_count+1))
            		if [ `head -$(($line_count+1)) $1 | tail -1 | egrep "^$" 2>&1 > /dev/null` $? -ne 0 -a `head -$(($line_count+1)) $1 | tail -1 | egrep "^ *#" | grep -v "^ *#PBS *" 2>&1 > /dev/null` $? -ne 0 -a `head -$(($line_count+1)) $1 | tail -1 | egrep "^ *#PBS *" 2>&1 > /dev/null` $? -ne 0 ]  
            		then
               			if [ $pbs_line_count -eq 0 ]
               			then
                  			echo -e "\nPBS operatives such as \"#PBS -l nodes=1:ppn=2,walltime=05:00:00\" are either missing or not declared immediately after shebang/hashbang line \"#\!/bin/bash\". Please fix the script.\n" > /dev/tty
                  			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
                  			exit -1
               			else
                  			pbs_operatives="done"
               			fi
            		fi
            		continue    # This part of the code finds the required parts from #pbs lines
         		elif echo $i | egrep "^ *#PBS  *" 2>&1> /dev/null    # Looks for #PBS lines
         		then
      	   			if echo $i | egrep "^ *#PBS  *-q  *" 2>&1> /dev/null   # Looks for #PBS -q line
            		then
               			queue=$i    # Stores the queue requested
               			echo $i
            		elif echo $i | egrep "^ *#PBS  *-l  *" 2>&1> /dev/null   # Looks for #PBS -l lines
            		then
               			if echo $i | egrep " *nodes=0*[1-9][0-9]?" 2>&1> /dev/null  # Looks for nodes= in #PBS -l line
               			then
                  			node_count=`echo $i | egrep -o 'nodes=0*[1-9][0-9]?' | cut -d"=" -f2`   # stores number of nodes requested
                  			#echo "node count is $node_count"
               			fi
               			if echo $i | egrep "ppn=0*[1-9][0-9]?" 2>&1> /dev/null   # Looks for ppn= in #PBS -l line
               			then
                  			ppn_count=`echo $i | egrep -o 'ppn=0*[1-9][0-9]?' | cut -d"=" -f2`   # stores number of ppn requested
                  			#echo "ppn count is $ppn_count"
               			fi
               			if echo $i | egrep " *mem=0*[1-9][0-9]*[a-zA-Z][a-zA-Z]" 2>&1> /dev/null   # looks for mem= in #PBS -l line
               			then
							if echo $i | egrep -w " *mem=0*[1-9][0-9]*[a-zA-Z][a-zA-Z]" 2>&1> /dev/null
							then
                  				mtag=`echo $i | egrep -o ' *mem=0*[1-9][0-9]*[a-zA-Z][a-zA-Z]' | cut -d= -f2 | egrep -o '[a-zA-Z][a-zA-Z]'`   # stores memory tag like KB, MB or GB
                  				memory=`echo $i | egrep -o 'mem=0*[1-9][0-9]*' | cut -d"=" -f2`
                  				if echo $mtag | egrep '[gG][bB]' 2>&1> /dev/null
                  				#if [[ $mtag =~ "[gG][bB]" ]]
                  				then
                     				memory=`expr $memory '*' 1024 '*' 1024`   # stores memory requested and converts it into kilo bytes
                     				#memory=$(($memory*1024*1024))
                  				elif echo $mtag | egrep '[mM][bB]' 2>&1> /dev/null
                  				#if [[ $mtag =~ "[mM][bB]" ]]
                  				then
                     				memory=`expr $memory '*' 1024`
                     				#memory=$(($memory*1024))
                  				elif echo $mtag | egrep '[kK][bB]' 2>&1> /dev/null
                  				#if [[ $mtag =~ "[kK][bB]" ]]
                  				then
                     				memory=$memory
								else
									echo -e "\nMemory should be either in Kilo Bytes(kb, KB) or Mega Bytes (mb, MB) or Giga Bytes (gb, GB). Please fix the script.\n" > /dev/tty
									echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
									exit -1
								fi
							else
								echo -e "\nMemory tag should not be more than two letters. It can be just one of kb,KB,mb,MB,gb and GB. Please fix the script.\n" > /dev/tty
								echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
								exit -1
                  			fi
               			fi
               			if echo $i | egrep -o '( |,)walltime=[0-9]*:?[0-9]*:?[0-9]*:?[0-9]*($|,)' 2>&1> /dev/null   # looks for walltime= in #PBS -l line
               			then
                  			wallstring=`echo $i | egrep -o '( |,)walltime=[0-9]*:?[0-9]*:?[0-9]*:?[0-9]*($|,)' | cut -f2 -d"="`
                  			if [ `echo "$wallstring" | egrep -o '^[0-9]*:?[0-9]*:?[0-9]*:?[0-9]*,$'` ]
                  			then
                     			wallstring=`echo "$wallstring" | cut -f1 -d","`
                  			fi
                  			if [ -z "$wallstring" ]
                  			then
                     			echo -e "\nPlease declare the walltime in the script such as in \"#PBS -l walltime=05:00:00\" or \"#PBS -l nodes=1:ppn=8,walltime=05:00:00\"\n" > /dev/tty
                     			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
                     			exit -1;
                  			elif [ `echo "$wallstring" | egrep -o '^:{1,3}$'` ]
                  			then
                     			echo -e "\nPlease declare the walltime in the script such as in \"#PBS -l walltime=05:00:00\" or \"#PBS -l nodes=1:ppn=8,walltime=05:00:00\"\n" > /dev/tty
                     			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
                     			exit -1;
                  			else
                     			number=`echo "$wallstring" | tr -dc ":" | wc -c`
                     			for  (( j=$(($number+1)); j>0; j-- ))
                     			do
                        			if [ -n "`echo "$wallstring" | cut -f"$j" -d":"`" -a $j -eq $(($number+1)) ]
                        			then
                                		walltime=`echo "$wallstring" | cut -f"$j" -d":"`    # stores walltime requested
                        			elif [ -n "`echo "$wallstring" | cut -f$j -d":"`" -a $j -eq $number ]
                        			then
                                		walltime=$(($walltime+`echo "$wallstring" | cut -f$j -d":"`*60))   # converts into seconds
                        			elif [ -n "`echo "$wallstring" | cut -f$j -d":"`" -a $j -eq $(($number-1)) ]
                        			then
                                		walltime=$(($walltime+`echo "$wallstring" | cut -f$j -d":"`*60*60))   # converts into seconds
                        			elif [ -n "`echo "$wallstring" | cut -f$j -d":"`" -a $j -eq $(($number-2)) ]
                        			then
                                		walltime=$(($walltime+`echo "$wallstring" | cut -f$j -d":"`*24*60*60))  # converts into seconds
                        			fi
                     			done
                  			fi
                  			#echo "walltime is $walltime"
               			fi
               			echo $i
            		else
               			echo $i
            		fi
            		line_count=$(($line_count+1))
            		pbs_line_count=$(($pbs_line_count+1))
            		if [ `head -$(($line_count+1)) $1 | tail -1 | egrep "^$" 2>&1 > /dev/null` $? -ne 0 -a `head -$(($line_count+1)) $1 | tail -1 | egrep "^ *#" | grep -v "^ *#PBS *" 2>&1 > /dev/null` $? -ne 0 -a `head -$(($line_count+1)) $1 | tail -1 | egrep "^ *#PBS *" 2>&1 > /dev/null` $? -ne 0 ]  
            		then
               			pbs_operatives="done"
            		fi
            		continue
         		fi 
 			fi     
		fi
   
   		if [ -z $node_count ]
   		then
      		echo -e "\nNode count is not declared such as in \"#PBS -l nodes=1:ppn=8,walltime=05:00:00\". Please fix the script.\n" > /dev/tty
      		echo -e "For more information please refter to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
      		exit -1
   		fi
   		if [ -z $ppn_count ]
   		then
      		echo -e "\nProcessor Per Node count is not declared such as in \"#PBS -l nodes=1:ppn=8,walltime=05:00:00\". Please fix the script.\n" > /dev/tty
      		echo -e "For more information please refter to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
      		exit -1
   		else
      		if [ $ppn_count -gt 8 ]
      		then
         		echo -e "\nMaximum number of processors per node available is 8. Please fix the script.\n" > /dev/tty
         		echo -e "For more information please refter to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
         		exit -1
      		fi
   		fi
   		if [ -z $walltime ]
   		then
      		echo -e "\nPlease declare the walltime in the script such as in \"#PBS -l walltime=05:00:00\" or \"#PBS -l nodes=1:ppn=8,walltime=05:00:00\"\n" > /dev/tty
      		echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
      		exit -1;
   		fi

#---------------------------------------------------------------------------------------------------------

# This part of the code works based on the queues declared.

   		if [ -n "$queue" -a $counter -eq 0 ]
   		then
      		if echo $queue | egrep "^ *#PBS  *-q  *bigmem$" 2>&1> /dev/null   # Enters if the queue is bigmem
      		then
         		if [ -z "$memory" ]  # If memory is not requested it echoes the statement below.
         		then
            		echo -e "\nBigmem queue needs memory declaration in the pbs script. For example, if your job needs 25GB memory, job script should contain a line:" > /dev/tty
            		echo -e "\n#PBS -l mem=25GB\n" > /dev/tty
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
            		exit -1
         		else
               		if [ $memory -lt $(($mem_bigmem_min*1024*1024)) ]
               		then
		  				echo -e "\nMinimum memory for bigmem queue is ${mem_bigmem_min}GB. Please fix the script.\n" > /dev/tty
   		  				echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
                  		exit -1
               		elif [ $memory -gt $(($mem32gb_limit*1024*1024)) ]
               		then
                  		echo -e "\nMaximum memory for bigmem queue is ${mem32gb_limit}GB. Please fix the script.\n" > /dev/tty
                  		echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
                  		exit -1
               		fi
         		fi
         		if [ $walltime -gt $wtime_bigmem_max ]   # makes sure walltime is less than 48 hours
         		then
            		echo -e "\nThe maximum walltime for bigmem jobs is $(($wtime_bigmem_max/3600)) hours. Please fix the walltime before you resubmit the script.\n" > /dev/tty
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
         		fi
      		elif echo $queue | egrep "^ *#PBS  *-q  *p12$" 2>&1> /dev/null   # looks for p12 queue in #PBS -q line
      		then
         		if [ ! -z $node_count -a $node_count -eq 1 ]   # p12 jobs require minimum 2 nodes
         		then
               		echo -e "\nMinimum number of nodes needed for queue p12 is 2. Please fix your job script.\n" > /dev/tty
               		echo  -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
               		exit -1
         		elif [ -n "$memory" -a -n $node_count ]
         		then
            		if [ $memory -gt $(($mem16gb_limit*1024*1024)) ]
            		then
               			echo -e "\nTo run parallel jobs that require memory greater than ${mem16gb_limit}GB please use queue bigmem.\n" > /dev/tty
               			echo  -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
               			exit -1
            		fi
         		elif [ -z "$memory" ]
         		then
            		echo "#PBS -l mem=${mem16gb_limit}GB"
            		echo -e "\nAllocated memory for your job is ${mem16gb_limit}GB. If you need more than this please use bigmem queue.\n"> /dev/tty
               		echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
         		fi
         		if [ $walltime -gt $wtime_p12_max ]  # makes sure walltime is less than 12 hours for p12 jobs
         		then
            		echo -e "\nThe maximum walltime for p12 jobs is $(($wtime_p12_max/3600)) hours. Please fix the walltime before you resubmit the script.\n" > /dev/tty
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
         		fi
      		elif echo $queue | egrep "^ *#PBS  *-q  *p48$" 2>&1> /dev/null   # p48 queue
      		then
         		if [ ! -z $node_count -a $node_count -eq 1 ]
         		then
            		echo -e "\nMinimum number of nodes needed for queue p48 is 2. Please fix your job script.\n" > /dev/tty
            		echo  -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
            		exit -1
         		elif [ -n "$memory" -a -n $node_count ]
         		then
            		if [ $memory -gt $(($mem16gb_limit*1024*1024)) ]
            		then
               			echo -e "\nTo run parallel jobs that require memory greater than ${mem16gb_limit}GB please use queue bigmem.\n" > /dev/tty
               			echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
               			exit -1
            		fi
         		elif [ -z "$memory" ]
         		then
            		echo "#PBS -l mem=${mem16gb_limit}GB"
            		echo -e "\nAllocated memory for your job is ${mem16gb_limit}GB. If you need more than this please use bigmem queue.\n"> /dev/tty
               		echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
         		fi
         		if [ $walltime -gt $wtime_p48_max ]
         		then
            		echo -e "\nThe maximum walltime for p48 jobs is $(($wtime_p48_max/3600)) hours. Please fix the walltime before you resubmit the script.\n" > /dev/tty
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
         		fi
      		elif echo $queue | egrep "^ *#PBS  *-q  *serlong$" 2>&1> /dev/null   # serlong queue
      		then
         		if [ ! -z $node_count -a $node_count -gt 1 ]
         		then
            		echo -e "\nThe maximum node count for serlong queue is 1. Please fix the script.\n" > /dev/tty
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
         		elif [ $walltime -lt $wtime_serlong_min ]
         		then
            		echo -e "\nThe minimum walltime for serlong queue is $(($wtime_serlong_min/3600)) hours $((($wtime_serlong_min-3600*($wtime_serlong_min/3600))/60)) minute. Please fix the script.\n" > /dev/tty  
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
         		elif [ $walltime -gt $wtime_serlong_max ]
         		then
            		echo -e "\nThe maximum walltime for serlong queue is $(($wtime_serlong_max/3600)) hours. Please fix the script.\n" > /dev/tty
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
         		fi
         		if [ -n "$memory" ]
         		then
            		if [ $memory -gt $(($mem16gb_limit*1024*1024)) ]
            		then
               			echo -e "\nMaximum memory available for serlong queue is ${mem16gb_limit}GB. To request more than this please use queue bigmem.\n" > /dev/tty
               			echo -e "For more information please refter to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
               			exit -1
            		fi
            		if [ $ppn_count -lt 8 ]
            		then
               			if [ $(($ppn_count*$mem16gb_limit*1024*1024/8)) -lt $memory ]
               			then
                  			echo -e "\nAllocated memory for each core is $(($mem16gb_limit*1024/8))MB (=${mem16gb_limit}GB/8). Please change the ppn count in the script according to the calculation, ppn*$(($mem16gb_limit*1024/8))MB >= declared memory for the job.\n" > /dev/tty
                  			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
                  			exit -1
               			fi
            		else
               			if [ $memory -gt $(($mem16gb_limit*1024*1024)) ]
               			then
                  			echo -e "\nMaximum memory available is ${mem16gb_limit}GB. Please fix the script.\n" > /dev/tty
                  			echo -e "For more information refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
                  			exit -1
               			fi
            		fi
         		else
            		if [ $ppn_count -lt 8 ]
            		then
               			echo "#PBS -l mem=$(($ppn_count*$memory_per_core))MB"
               			echo -e "\nAllocated memory for your job is $(($ppn_count*$memory_per_core))MB. Memory is calculated using the formula ppn times memory per core, ${memory_per_core}MB." > /dev/tty
               			echo -e "If you think you need more memory than this please either change ppn count or declare memory with #PBS -l mem=xxGB\n" > /dev/tty
               			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
            		else
               			echo "#PBS -l mem=${mem16gb_limit}GB"
               			echo -e "\nAllocated memory for your job is ${mem16gb_limit}GB. If you need more than this please use bigmem queue.\n" > /dev/tty
               			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
            		fi
         		fi
      		elif echo $queue | egrep "^ *#PBS  *-q  *ser2$" 2>&1> /dev/null   # ser2 queue
      		then
         		if [ ! -z $node_count -a $node_count -gt 1 ]
         		then
            		echo -e "\nThe maximum node count for ser2 queue is 1. Please fix the script.\n" > /dev/tty
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
         		elif [ $walltime -lt $wtime_ser2_min ]
         		then
            		echo -e "\nThe minimum walltime for ser2 queue is $(($wtime_ser2_min/60)) minute. Please fix the script.\n" > /dev/tty
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
         		elif [ $walltime -gt $wtime_ser2_max ]
         		then
            		echo -e "\nThe maximum walltime for ser2 queue is $(($wtime_ser2_max/3600)) hours. Please fix the script.\n" > /dev/tty
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
         		fi
         		if [ -n "$memory" ]
         		then
            		if [ $memory -gt $(($mem16gb_limit*1024*1024)) ]
            		then
               			echo -e "\nMaximum memory available for ser2 queue is ${mem16gb_limit}GB. To request more than this please use queue bigmem.\n" > /dev/tty
               			echo -e "For more information please refter to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
               			exit -1            
            		fi
            		if [ $ppn_count -lt 8 ]
            		then
               			if [ $(($ppn_count*$mem16gb_limit*1024*1024/8)) -lt $memory ]
               			then
                  			echo -e "\nAllocated memory for each core is $(($mem16gb_limit*1024/8))MB (=${mem16gb_limit}GB/8). Please change the ppn count in the script according to the calculation, ppn*$(($mem16gb_limit*1024/8))MB >= declared memory for the job.\n" > /dev/tty
                  			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
                  			exit -1
               			fi
            		else
               			if [ $memory -gt $(($mem16gb_limit*1024*1024)) ]
               			then
                  			echo -e "\nMaximum memory available is ${mem16gb_limit}GB. Please fix the script.\n" > /dev/tty
                  			echo -e "For more information refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
                  			exit -1
               			fi
            		fi
         		else
            		if [ $ppn_count -lt 8 ]
            		then
               			echo "#PBS -l mem=$(($ppn_count*$memory_per_core))MB"
               			echo -e "\nAllocated memory for your job is $(($ppn_count*$memory_per_core))MB. Memory is calculated using the formula ppn times memory per core,${memory_per_core} MB." > /dev/tty
               			echo -e "If you think you need more memory than this please either change ppn count or declare memory with #PBS -l mem=xxGB\n" > /dev/tty
               			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
            		else
               			echo "#PBS -l mem=${mem16gb_limit}GB"
               			echo -e "\nAllocated memory for your job is ${mem16gb_limit}GB. If you need more than this please use bigmem queue.\n"> /dev/tty
               			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
            		fi
         		fi
      		fi
      		counter=1

# This part of the code works when there are no queues declared.

   		elif [ -z "$queue" -a $counter -eq 0 ]
   		then
      		if [ -n $node_count -a $node_count -eq 1 ]
      		then
         		if [ $walltime -lt $wtime_ser2_min ]
         		then
            		echo -e "\nThe minimum walltime for serial jobs is $(($wtime_ser2_min/60)) minute. Please fix the script.\n" > /dev/tty
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
         		elif [ $walltime -gt $wtime_serlong_max ]
         		then
	    			echo -e "\nThe maximum walltime for serial jobs is $(($wtime_serlong_max/3600)) hours. Please fix the script.\n" > /dev/tty
	    			echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
	 			fi
         		if [ -z "$memory" ]
         		then
            		if [ -n $ppn_count -a $ppn_count -lt 8 ]
            		then
               			echo "#PBS -l mem=$(($ppn_count*$memory_per_core))MB"
               			echo -e "\nAllocated memory for your job is $(($ppn_count*$memory_per_core))MB. Memory is calculated using the formula ppn times memory per core, ${memory_per_core}MB." > /dev/tty
               			echo -e "If you think you need more memory than this please either change ppn count or declare memory with #PBS -l mem=xxGB\n" > /dev/tty
               			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
            		elif [ -n $ppn_count -a $ppn_count -eq 8 ]
            		then
               			echo "#PBS -l mem=${mem16gb_limit}GB"
               			echo -e "\nAllocated memory for your job is ${mem16gb_limit}GB. If you need more than this please use bigmem queue.\n"> /dev/tty
               			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
            		fi
         		else
            		if [ $memory -gt $(($mem16gb_limit*1024*1024)) ]
            		then
               			echo -e "\nMaximum memory available is ${mem16gb_limit}GB. To request more than this please use queue bigmem.\n" > /dev/tty
               			echo -e "For more information please refter to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
               			exit -1            
            		fi
            		if [ $ppn_count -lt 8 ]
            		then
               			if [ $(($ppn_count*$mem16gb_limit*1024*1024/8)) -lt $memory ]
               			then
                  			echo -e "\nAllocated memory for each core is $(($mem16gb_limit*1024/8))MB (=${mem16gb_limit}GB/8). Please change the ppn count in the script according to the calculation, ppn*$(($mem16gb_limit*1024/8))MB >= declared memory for the job.\n" > /dev/tty
                  			echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
                  			exit -1
               			fi
            		fi
         		fi
      		elif [ -n $node_count -a $node_count -ge 2 ]
      		then
	 			if [ $walltime -gt  $wtime_p48_max ]
	 			then
	    			echo -e "\nMaximum walltime for parallel jobs is $(($wtime_p48_max/3600)) hours. Please fix the script.\n" > /dev/tty
            		echo -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Queues\n" > /dev/tty
            		exit -1
	 			fi
         		if [ -n "$memory" ]
         		then
            		if [ $memory -gt $(($mem16gb_limit*1024*1024)) ]
            		then
               			echo -e "\nTo run parallel jobs that require memory greater than ${mem16gb_limit}GB please use queue bigmem.\n" > /dev/tty
               			echo  -e "For more information please refer to HPC wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
               			exit -1
            		fi
         		else
            		echo "#PBS -l mem=${mem16gb_limit}GB"
	    			echo -e "\nAllocated memory for your job is ${mem16gb_limit}GB. If you need more than this please use bigmem queue.\n"> /dev/tty
               		echo -e "For more information please refer to HPC Wiki at https://wikis.nyu.edu/display/NYUHPC/Running+jobs\n" > /dev/tty
         		fi
      		fi
      		counter=1
   		fi
   		echo $i
	done
# This below part works when job is submitted through command line but
# not through script. Where as the above part entirely deals with the pbs scripts.
else
	while read -r i
	do
		echo $i
	done
fi

Making personal keyboard shortcuts to Applications on Mac

As every Mac user does I often open System Preferences. I don't like to use either track pad or mouse. So I made my own shortcut. First, open up System Preferences, then Keyboard, Keyboard shortcuts. Select Application Shortcuts in the left pane. Then click on + to add the short cut. Select the application in the dialogue box that has popped up and give it a name. Finally, next to Keyboard shortcut just press the entire keyboard sequence you want to have it as a shortcut. For example, I pressed <lat> + <command> + <single quote> at the same time. As soon as you are done pressing the keys you'd see the sequence in the box. Click add and you are done. See the pic below to see what I'm talking about. I guess pics make things easier.

By the way, the reason behind choosing chose alt + command + ' for the system preferences is that every application preferences on Mac can be accessed with keyboard shortcut of command + '. Hence I've just added alt to it. Makes sense I guess.


Sunday, August 21, 2011

selection of form fields uisng tab on Mac

By default, form field selection on Mac using tab doesn't work. To do this go to System Preferences ---> keyboard ---> and then select "All Controls" for "Full keyboard access: In windows and dialogues, press Tab to move keyboard focus between:".

By default Text boxes and lists only is selected as shown in the picture below. Just select "All controls" and then you'd be able to use Tab and Space bar combination to focus and select equivalent to moving mouse onto the option and left clicking.


In the picture below you can see that cancel option is focused and you can hit the space bar to select this option to cancel deleting the song from iTunes.


Getting rid of annoying document images under places on finder window on mac

For longest time, on my mac, I had these annoying document names under places on every finder window. I tried to delete them by changing the sidebar preferences. Nothing happened. The other day I was trying to find solution online and someone posted this simple and beautiful trick.

While holding the command key try to drag the icons you want to get rid of on to desktop. That's it. You don't see them anymore. Sometimes, small tricks like this are life savers :)

Thursday, August 18, 2011

Installing DJVIEW4 on Mac OS X for viewing .djvu files

First make sure that you've installed xcode. xcode 3 is free. Means, xcode 4 is not. You can download it from Apple.

Then, download dvulibre from here http://djvu.sourceforge.net/.

$ cd Desktop
$ open http://ftp.gnu.org/gnu/wget/wget-1.13.tar.gz
$ tar xzvf wget-1.13.tar.gz
$ cd wget-1.13
$ ./configure --without-ssl
$ make
$ sudo make install
$ cd ..
$ wget http://www.ijg.org/files/jpegsrc.v8c.tar.gz
$ tar xzvf jpegsrc.v8c.tar.gz
$ cd jpeg-8c/
$ ./configure
$ make
$ sudo make install
$ cd ..
$ wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.25.tar.gz
$ tar xzvf pkg-config-0.25.tar.gz 
$ cd pkg-config-0.25
$ ./configure 
$ make
$ sudo make install
$ cd ..
$ wget http://downloads.sourceforge.net/djvu/djvulibre-3.5.24.tar.gz
$ tar xzvf djvulibre-3.5.24.tar.gz
$ cd djvulibre-3.5.24
$ ./configure
$ make
$ sudo make install
$ cd ..
Then download QT4 (google search term is "downloading qt4") and install it. It's a standard package for mac and so there is no need to do it from terminal.

DJVIEW 4 can be downloaded from http://djvu.sourceforge.net/djview4.html.

$ wget http://downloads.sourceforge.net/djvu/djview-4.8.tar.gz
$ tar xzvf djview-4.8.tar.gz
$ cd djview-4.8
$ ./configure QMAKE=$HOME/QtSDK/Desktop/Qt/473/gcc/bin/qmake
$ make
$ sudo make install
$ cd ..
$ djview filename.djvu
You should see a window opening with your ebook on it. I needed to install this to read one of the ebooks I found online.

Note: Always, don't go for latest versions. Most of the time they are unstable and don't work well. Just go for the version just before the latest. For example, I had problems with pkg-config latest version 0.26. But 0.25 worked beautifully without any problems. For some reason djviewlibre didn't work with tiff library. I didn't have time to fix that either. So I used ./configure --without-tiff and it worked for me. I didn't install pdflib too. But the minimum works for me well.

Enabling X11 Forwarding on Mac OS X

By default, X11 forwarding is not enabled on Mac Leopard. To enable it you need to have a line like "X11Forwarding yes" in the file /private/etc/sshd_config. Just do this command from the terminal.
$ sudo echo "X11Forwarding yes" >> /private/etc/sshd_config
Enter the password when prompted.

Make sure that you check Remote Login under Sharing in System Preferences.

$ ssh -X username@remotehost
$ xeyes &
$ xclock &

For the xeyes you should see the eyes on your screen. For the xclock it's clock. On our clusters we are not allowed to be idle for more than certain time and so I use xclock to keep it active all the time.


Apple shortcut to highlight apple icon on top left corner

Have you ever tried to select the apple icon on the top left corner using keyboard? I often use it and so started looking into finding a shortcut. I think almost 3 to 4 years back I search online for a while to find the shortcut without any success. Then I kept on pressing different keys together and finally found the shortcut. I'm sure there might be another simple shortcut but what I found was lifesaver for me. Here it is ...

<fn> + <control> +<F2>

That is pressing function, control and F2 keys together highlights the apple symbol and from there using arrow keys take you to other options like software update, restart and shutdown.

Wednesday, August 10, 2011

Performance Analysis Tools: MPE2, mpiP and libunwind Installation on Linux

I have built all these tools on our clusters using Intel compilers. Location of all the executables like icc, ifort, icpc, mpicc, etc have already been added to the path. The locations of intel, mpi libraries are appended to LD_LIBRARY_PATH. If you haven't done it yet then you can do that using export PATH=$PATH: and export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. Better add these two lines to your ~/.bashrc.

First, I had to build libunwind so that mpiP can be built using this. It can be downloaded at http://www.nongnu.org/libunwind/.

Building libunwind

$ ./configure CC=icc CFLAGS="-g -O3 -fPIC -align -Zp8 -axP -unroll -xP -ip" CXX=icc \
CCAS=icc CCASFLAGS="-g -O3 -fPIC -align -Zp8 -axP -unroll -xP -ip" \
LDFLAGS="-L$PWD/src/.libs" --prefix=/home/manchu/libunwind/ \
--exec-prefix=/home/manchu/libunwind/ --enable-cxx-exceptions --enable-debug
$ make
$ sudo bash
$ make install
Profiling tool mpiP can be downloaded at http://mpip.sourceforge.net/.

Building mpiP

$ ./configure --prefix=/home/manchu/mpiP/ --exec-prefix=/home/manchu/mpiP/ \
CC=mpicc CFLAGS="-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip" F77=mpif77 \
FFLAGS="-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip" --with-cxx=mpic++ \
CXXFLAGS="-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip" --enable-demangling=GNU \
--enable-fortranweak --enable-getarg --with-libunwind=/home/manchu/libunwind/lib/ \
--enable-collective-report-default
$ make
$ sudo bash
$ make install
You can download the profiling cum tracing tool MPE2 here. If you're installing MPICH2 then don't bother about this as it comes with this package.

Building MPE2

$ ./configure --prefix=/home/manchu/mpe2/ --exec-prefix=/home/manchu/mpe2/ \
CC=icc CFLAGS="-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip" MPI_CC=mpicc \
MPI_CFLAGS="-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip" F77=ifort \
FFLAGS="-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip" MPI_F77=mpif77 \
MPI_FFLAGS="-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip" --enable-collchk \
--enable-wrappers --enable-checkMPIwtime --enable-g
$ make
$ sudo bash
$ make install
If you see any problems with finding libraries then I recommend you add LDFLAGS as well as CPPFLAGS, etc. Do ./configure -help to see more options.

Tuesday, August 9, 2011

LAMMPS, FFTW, JPEGLIB and MPICH2 Installation on MAC OS X

This post shows how to install LAMMPS on MAC. To have parallel build one needs to install some MPI wrapper like OpenMPI or MPICH2. For some type of simulations with LAMMPS you need FFTW too. I wanted to have Jpeg libraries too with LAMMPS. Of course, you need the most important piece, C, C++ and Fortran compilers. If you just need LAMMPS, I mean with out optional packages, then you don't need Fortran compiler. I recommend Intel compilers. Yesterday, I built LAMMPS with all these and thought it might be helpful for someone if I posted it here.

Oho, by the way make sure you download XCODE and install it before you install Intel compilers. Otherwise, you won't be able to create c executables. You can download it from Apple website. It is also there on the CDs that come with your mac. Xcode is not installed by default.

Here is how it goes ...

Jpeg Libraries

You can download the source at http://www.ijg.org/
$ cd Desktop
$ tar xzvf jpegsrc.v8c.tar.gz
$ cd jpeg-8c/
$ mkdir ~/libjpeg
$ ./configure --prefix=/Users/sm4082/libjpeg/ CC=icc \
CFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' \
LDFLAGS='-L/Developer/opt/intel/Compiler/11.1/084/lib/' \
CPPFLAGS='-I/Developer/opt/intel/Compiler/11.1/084/include'
$ make
$ make install
$ make test

MPICH2 Installation

MPICH2 can be downloaded from http://www.mcs.anl.gov/research/projects/mpich2/.
$ cd ~/Desktop
$ tar xzvf mpich2-1.4.tar.gz
$ cd mpich2-1.4
$ mkdir ~/mpich2
$ ./configure --prefix=/Users/sm4082/mpich2 CC=icc \
CFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' \
F77=ifort FFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' FC=ifort \
FCFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' CXX=icpc \
CXXFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' --enable-f77 \
--enable-fc --enable-cxx --enable-totalview --enable-mpe \
--enable-fast=O2 --with-device=ch3:nemesis \
--with-pm=hydra:mpd:gforker --enable-error-checking=all \
--enable-error-messages=all --enable-smpcoll --enable-nmpi-as-mpi \
--enable-timing=all --enable-timer-type=gettimeofday \
--enable-romio --enable-threads=default --enable-debuginfo --enable-g=dbg,log --disable-rpath 2>&1 | tee c.txt
$ make 2>&1 | tee m.txt
$ make install 2>&1 | tee mi.txt

FFTW Installation

LAMMPS doesn't work with FFTW version 3.X version. We need to install version 2.X.X. FFTW can be downloaded from http://www.fftw.org/
$ cd ~/Desktop
$ tar xzvf fftw-2.1.5.tar.gz
$ cd fftw-2.1.5
$ mkdir ~/fftw-2.1.5
$ ./configure CC='icc' CFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' \
LDFLAGS='-L/Developer/opt/intel/Compiler/11.1/084/lib' \
CPPFLAGS='-I/Developer/opt/intel/Compiler/11.1/084/include' --enable-shared  \
--enable-mpi MPICC=/Users/sm4082/mpich2/bin/mpicc \
LDFLAGS='-L/Users/sm4082/mpich2/lib' \
CPPFLAGS='-I/Users/sm4082/mpich2/include' --with-openmp \
--enable-debug --disable-fortran --prefix=/Users/sm4082/fftw-2.1.5/
$ make
$ make install
$ make check

Finally, LAMMPS Installation

LAMMPS can be downloaded from http://lammps.sandia.gov/
To install packages like MEAM, REAX you need Fortran compiler. I have used Intel Fortran compiler.
$ cd ~/Desktop
$ tar xzvf lammps.tar.gz
$ cd lammps-5Aug11/lib/meam/
$ make -f Makefile.ifort
$ cd ../poems/
$ make -f Makefile.icc
$ cd ../reax/
$ make -f Makefile.ifort
$ cd ../../src/
Next, edit the makefile Makefile.linux in MAKE folder in src directory.
$ more MAKE/Makefile.linux
# linux = RedHat Linux box, Intel icc, Intel ifort, MPICH2, FFTW

SHELL = /bin/sh

# ---------------------------------------------------------------------
# compiler/linker settings
# specify flags and libraries needed for your compiler

CC =            /Users/sm4082/mpich2/bin/mpic++
CCFLAGS =       -O3 -fPIC -align -Zp8 -axP -unroll -xP -ip
DEPFLAGS =      -M
LINK =          /Users/sm4082/mpich2/bin/mpic++
LINKFLAGS =     -O
LIB =           -lstdc++
ARCHIVE =       ar
ARFLAGS =       -rc
SIZE =          size

# ---------------------------------------------------------------------
# LAMMPS-specific settings
# specify settings for LAMMPS features you will use

# LAMMPS ifdef options, see doc/Section_start.html

LMP_INC =       -DLAMMPS_GZIP -DLAMMPS_JPEG

# MPI library, can be src/STUBS dummy lib
# INC = path for mpi.h, MPI compiler settings
# PATH = path for MPI library
# LIB = name of MPI library

MPI_INC =       -DMPICH_SKIP_MPICXX -I/Users/sm4082/mpich2/include
MPI_PATH = -L/Users/sm4082/mpich2/lib
MPI_LIB =       -lmpich -lpthread

# FFT library, can be -DFFT_NONE if not using PPPM from KSPACE package
# INC = -DFFT_FFTW, -DFFT_INTEL, -DFFT_NONE, etc, FFT compiler settings
# PATH = path for FFT library
# LIB = name of FFT library

FFT_INC =       -DFFT_FFTW -I/Users/sm4082/fftw-2.1.5/include
FFT_PATH = -L/Users/sm4082/fftw-2.1.5/lib
FFT_LIB =       -lfftw

# JPEG library, only needed if -DLAMMPS_JPEG listed with LMP_INC
# INC = path for jpeglib.h
# PATH = path for JPEG library
# LIB = name of JPEG library

JPG_INC =      -I/Users/sm4082/libjpeg/include 
JPG_PATH =      -L/Users/sm4082/libjpeg/lib
JPG_LIB =       -ljpeg

# additional system libraries needed by LAMMPS package libraries
# these settings are IGNORED if the corresponding LAMMPS package
#   (e.g. gpu, meam) is NOT included in the LAMMPS build
# SYSINC = settings to compile with
# SYSLIB = libraries to link with
# SYSPATH = paths to libraries

gpu_SYSINC =
meam_SYSINC =
reax_SYSINC =
user-atc_SYSINC =
user-awpmd_SYSINC =

gpu_SYSLIB =       -lcudart -lcuda
meam_SYSLIB =      -lifcore -lsvml -lompstub -limf
poems_SYSLIB =     -lifcore -lsvml -lompstub -limf
reax_SYSLIB =      -lifcore -lsvml -lompstub -limf
user-atc_SYSLIB =  -lblas -llapack
user-awpmd_SYSLIB =  -lblas -llapack

gpu_SYSPATH =      -L/usr/local/cuda/lib64
meam_SYSPATH =     -L/Developer/opt/intel/Compiler/11.1/084/lib
poems_SYSPATH =     -L/Developer/opt/intel/Compiler/11.1/084/lib
reax_SYSPATH =     -L/Developer/opt/intel/Compiler/11.1/084/lib
user-atc_SYSPATH =
user-awpmd_SYSPATH =

# ---------------------------------------------------------------------
# build rules and dependencies
# no need to edit this section

include Makefile.package

EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC)
EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH)
EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB)

# Link target

$(EXE): $(OBJ)
        $(LINK) $(LINKFLAGS) $(EXTRA_PATH) $(OBJ) $(EXTRA_LIB) $(LIB) -o $(EXE)
        $(SIZE) $(EXE)

# Library target

lib:    $(OBJ)
        $(ARCHIVE) $(ARFLAGS) $(EXE) $(OBJ)

# Compilation rules

%.o:%.cpp
        $(CC) $(CCFLAGS) $(EXTRA_INC) -c $<

%.d:%.cpp
        $(CC) $(CCFLAGS) $(EXTRA_INC) $(DEPFLAGS) $< > $@

# Individual dependencies

DEPENDS = $(OBJ:.o=.d)
include $(DEPENDS)
Edit the Makefile.linux following the above makefile. You need Fortran libraries for compiling packages Meam and Reax. The library needed is libifcore. So, I have created a link to this in intel C/C++ lib folder. The advantage of doing this is that you just need to add just intel C/C++ lib to DYLD_LIBRARY_PATH, but not Fortran libraries location. If you want you can include Fortran libraries location for meam_SYSPATH and reax_SYSPATH variables in makefile. But like I said, you need to add both C/C++ and Fortran library locations to DYLD_LIBRARY_PATH.
$ sudo -s
$ ln -s /Developer/opt/intel/composerxe-2011.0.085/compiler/lib/libifcore.a /Developer/opt/intel/Compiler/11.1/084/lib/libifcore.a
$ ln -s /Developer/opt/intel/composerxe-2011.0.085/compiler/lib/libifcore.dylib /Developer/opt/intel/Compiler/11.1/084/lib/libifcore.dylib
$ exit
$ make yes-granular
$ make yes-meam
$ make yes-poems
$ make yes-reax
$ make linux
You should see the lammps executable lmp_linux at the end of the installation.

Running examples with LAMMPS executable

First, we need to make sure the path of Intel libraries, /Developer/opt/intel/Compiler/11.1/084/lib, is added to DYLD_LIBRARY_PATH. You can either do it temporarily for a session or permanently by adding to your ~.bashrc.
Temporary
$ export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Developer/opt/intel/Compiler/11.1/084/lib
Permanent
$ cd
$ echo "export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Developer/opt/intel/Compiler/11.1/084/lib" >> .bashrc
$ source .bashrc
If you still see library problems while trying to run examples, I suggest add the location of MPICH2, Jpeg and FFTW libraries also to DYLD_LIBRARY_PATH varaible.

LAMMPS Examples

$ cd lammps-5Aug11/examples/meam/
$ ../../src/lmp_linux < in.meam
$ cd ../peptide
$ ../../src/lmp_linux < in.peptide 
$ cd ../micelle/
$ ../../src/lmp_linux < in.micelle 
$ cd ../flow/
$ ../../src/lmp_linux < in.flow.couette 
$ ../../src/lmp_linux < in.flow.pois
For all these runs you should see lammps running successfully outputting details on the screen just like the ones shown in the log files in those respective example directories. Most of the time, the errors come from the library problems like library not found. Which means library location is not added to DYLD_LIBRARY_PATH variable. You can run the same examples with mpi wrapper in parallel.
$ ~/mpich2/bin/mpiexec -n 4 ../../src/lmp_linux < in.flow.couette
or
$ ~/mpich2/bin/mpirun -np 4 ../../src/lmp_linux < in.flow.couette
You should see something like "Loop time of 0.523332 on 4 procs for 10000 steps with 420 atoms" instead of "Loop time of 0.468267 on 1 procs for 10000 steps with 420 atoms".

Sometimes, you need to go to Security pane in the System Preferences and add lmp_linux to allowed incoming connections. Otherwise, it won't let you run any parallel runs. By the way, you need to go to advanced tab on the security pane to do this.

If everything goes well you're done. You got LAMMPS executable to run whole lot of simulations in the days ahead of you. Good luck. If you get problems don't hesitate to drop me a comment and I'll try my best to help you out.

PBS Script Generator: Interdependent dropdown/select menus in Javascript

PBS SCRIPT GENERATOR
SH/BASH TCSH/CSH
Begin End Abort

About Me

LA, CA, United States
Here I write about the battles that have been going on in my mind. It's pretty much a scribble.

Sreedhar Manchu

Sreedhar Manchu
Higher Education: Not a simple life anymore