ARSC HPC Users' Newsletter 411, March 19, 2010

RSS Feeds Available

System downtime notices and news items are now available via RSS feeds so you can stay updated with your favorite RSS reader. Pingo, Midnight, Seawolf, and the Linux Workstations are included. Each host has its own two feeds, one for downtime notices and one for news items. You may also subscribe to the downtime notices or news items for all hosts as a single feed.

Please visit the following URL to choose your feed criteria under the "menu to filter items by type" and then click the RSS icon to subscribe:

Many thanks go to ARSC intern Tom Sielicki for developing the initial version of this system.

5 Steps to Off Site Command Line File Transferring

[ By Oralee Nudson ]

The following 5 steps describe the best options for transferring files between your home machines and the ARSC supercomputers.
  1. Create a tar file of related data files before beginning the transfers. This will assist in ease of file transferring and may speed up transfer rates due to transferring just one file instead of many smaller files.

  2. If you have a large amount of data to transfer, it will be best to divide the data transfers into reasonably sized chunks of 100GB or smaller.

    Transferring smaller sets of files will aid in restarting the transfers if a problem occurs during the transfer.

  3. If transferring files from $ARCHIVE_HOME, use the batch_stage command to bring your files online before beginning the transfers. See "man batch_stage" for details.

  4. Choose the best copy method for your needs. There are a few different commands available: krcp -X, kftp, and mpscp. Here is a description of each and when to use them.

    krcp -X

    The "krcp -X" command is included with many of the kerberos kits and generally provides faster transfer rates when compared to scp. The -X flag turns encryption off, which should speed up the file transfers. The following is an example using "krcp -X" to copy files from my local machine to my $WORKDIR on midnight:

        krcp -X myData.tar


    The kftp command can be used for uploading files to ARSC systems. After obtaining a Kerberos ticket, upload files using the following syntax:



    If your home system is running Linux, try using the "mpscp" command (included in the HPMCP Kerberos Kit) to transfer large files from your local machine to an ARSC system. The syntax for mpscp is basically the same as "scp", but can open multiple unencrypted sockets for data transfer. You should see a noticeable speed up in data transfer when using mpscp as opposed to krcp. If mpscp is not included in the PATH environment variable on your local system, set the MPSCP_SERVER environment variable (see man mpscp). Here is an example of using mpscp to copy files to midnight from my local machine. The "-w 4" option directs the command to open 4 TCP-streams for copying data in parallel. We encourage the use of 4 streams or less because the midnight login nodes are shared among all users.

        mpscp -w 4 filename.tar
  5. Verify the copy worked as intended by comparing the file sizes, content of the files, and/or use an MD5 Checksum. If your copies arrived at their destination successfully, delete the original copy. For the copy methods described above (with the exception of kftp), a file transfer should continue beyond the lifetime of your Kerberos ticket as long as the transfer is not interrupted. Once your Kerberos ticket expires however, you will need to obtain a new ticket to initiate a new file transfer. File transfers initiated with kftp will quit in mid-transfer if the current Kerberos ticket expires before the transfer is finished.

Even More About Git

[ By Jed Brown ]

[ Editor's note: Jed, who has been using git for a few years, kindly offered to share how git fits into his workflow as a follow-up to Kate Hedstrom's recent git introduction article. ]
    git citool / git add -p
  • To commit part of a dirty tree, handy to commit orthogonal changes separately
    git rebase
  • To linearize history (before pushing to a remote SVN repo, or when your changes have not been shared and are small enough that you don't want to see an explicit merge in the history. These also come in the form of 'git svn rebase' and 'git pull --rebase'.
    git rebase -i
  • To reorder, edit, or merge history.

In my workflow, I will often have multiple topic branches each containing one or more patches. When the feature is done, I'll send the patches upstream, but it can take time for them to be integrated, and sometimes upstream will want them changed in some way. Also, if upstream moves much before they get around to reviewing my patch, they will want me to rebase it again to make their merge easier. So I'll normally rebase each of the topic branches onto upstream whenever I pull.

    $ git rebase origin/master feature1
    $ git rebase origin/master feature2
    $ git rebase origin/master feature3

This lets me immediately resolve any conflicts introduced upstream. If I actually use the software myself, I want to be testing the latest version (including all my patches), so after rebasing the features, I

    $ git checkout master
    $ git reset --hard origin/master
    $ git merge feature1 feature2 feature3
    $ make

to build after a clean merge of my features on top of upstream. To start a new feature,

    $ git checkout -b feature4 origin/master

Responses to Brain Teaser

The following brain teaser appeared in issue 410 of this newsletter:

  [[ We were sent this puzzle by a certain esteemed reader who thought our 
  [[ audience might enjoy it. We will put a little twist on it and say, 
  [[ send us your answer and your algorithm for computing it and we will 
  [[ publish all the solutions that we deem "reasonable" in the next issue. 
  [[ We know one solution. Are there others?
  [[   If these conditions apply:
  [[       2 + 3 = 10
  [[       7 + 2 = 63
  [[       6 + 5 = 66
  [[       8 + 4 = 96
  [[   Then, what is the result of:
  [[       9 + 7 = ????

Thanks to readers Dave Strenski, Greg Newby, Dale Clark, Scott Kajihara,
Craig Knox, Ryan Czerwiec, Jim Williams and Alec Bennett for sending in
solutions.  Ryan gets an official HPC Newsletter Gold Star for multiple
solutions.  As always, some of the journeys shared were as fun as the

# From Dave Strenski:

This brain teaser proved very interesting for both my spouse, Paula, and
I.  We attacked the problem is different ways, but came up with the same
solution. Paula decided to only look at the top two lines and find a
relationship. Since the "answers" differed by a lot, she chose to square
the first number and then stumbled on "square the first" then add "the
first times the second".

    2^2 + (2*3) = 10
    7^2 + (7*2) = 63
    6^2 + (6*5) = 66
    8^2 + (8*4) = 96

    9^2 + (9*7) = 144

I chose to look at the problem vertically. I was looking for relationships
between the first column and the first digit in the answer and the second
column and the second digit in the answer.  This was fruitless, but got
me thinking about what I would have to multiply the "sum" by when I
noticed the pattern of multipling the "sum" by the first column.

    2(2+3) = 10
    7(7+2) = 63
    6(6+5) = 66
    8(8+4) = 96

    9(9+7) = 144

A little algebra shows we both have the same solution.

# From Greg Newby, ARSC Chief Scientist:

#!/usr/bin/perl -w

use strict;

#    If these conditions apply:
#        2 + 3 = 10
#        7 + 2 = 63
#        6 + 5 = 66
#        8 + 4 = 96
#    Then, what is the result of:
#        9 + 7 = ????

# Method: answer is a function of the two numeric arguments,
#  answer = arg1 * (arg1 + arg2)

sub f{

    my $arg1 = shift ; my $arg2 = shift; 
    my $result = $arg1 * ($arg1 + $arg2);

    return $result;

# main:
print ("Enter two numbers, separated by a space, ^D ends\n==> ");

while (<>) {
    my @args = split; 
    print "\tResult is: " . f($args[0], $args[1]) . "\n==> ";


# Greg also contributed a variation of the brain teaser for your
# enjoyment:

      2 + 3 = 101
      7 + 2 = 12
      6 + 5 = 15
      8 + 4 = 14

  Then, what is the result of:
      9 + 7 = ???? 

# From Craig Knox:

#! /bin/bash

# answer:
# multiply the sum of the two numbers on the left-hand side (LHS) of the 
# equation by the first number (leftmost) on the LHS to get the number on 
# the right-hand side (RHS) like so:

if [ $# -ne 2 ]; then
    echo "Usage: number1 number2"
    exit 1
let "answer = ($1 + $2)*$1"
echo $answer

so, 9 + 7 = 144

# From Ryan Czerwiec:

The easy one is that you square the first number and add it to the product 
of the first and second numbers, or in other words multiply the first 
number by the sum of the 2 numbers, thus 2^2 + 2*3 = 2*(2+3) = 10.  By this 
formula, 9+7=144.  Another answer is that there are four equations, so a 
system of up to 4 unknowns can be solved.  If you take the first number as 
an x-coordinate, the second as the y, and the height (z-value) of the 
surface as the right-hand side, 4 unknowns is enough to map a full first-
order polynomial:


So for the x=2 and y=3 in the first equation, we get z=6A+2B+3C+D and so 
on.  This results in:


For x=9 and y=7 (9+7=?) we get 1480/9.

For the cryptological guys out there, I'd suggest solving for A,B,C,D where 
2+3=10 suggests that A+B=C where A mod D =2, B mod D =3, and C mod D =10.  
Meeting the other 3 given equations would narrow down the choices, but 
there are still probably infinite solutions.  Even tougher, make A,B,C,D 
all prime.

# And from our resident pragmatist, ARSC Consultant Alec Bennett:

I came up with an incredible solution to the Brain Teaser, based on years 
of experience in the computing field of using existing tools to find 
solutions to problems.  It involved three simple steps:

1. Open web browser to
2. Type "2+3=10" into search field.
3. Click "I'm Feeling Lucky"


This works for a multitude of other problems as well.  Your Mileage May 

Quick-Tip Q & A

A:[[ One of the programs I use to preprocess my data occasionally hangs 
  [[ when I give it a bad input file.   Is there an easy way to set a 
  [[ timeout for a command?
  [[ Usually the program runs in under a minute, but it's embarrassing 
  [[ when it hangs on the input file.
  [[ Yes I'm trying to fix the problem, but I'm hoping a timeout will help 
  [[ me avoid using all of my CPU time.
  [[ My script looks like this:
  [[ #!/bin/bash
  [[ ...
  [[ # I'd like to be able to specify the following command not run longer 
  [[ # than 90 seconds.
  [[ ./preprocess input
  [[ mpirun ./myjob

Thanks to Jed Brown, Don Bahls, Scott Kajihara and Ryan Czerwiec
for an interesting variety of solutions to this problem.

# From Jed Brown

(ulimit -t 90; ./preprocess input) 

 exit 1

sets a hard limit on CPU time so that ./preprocess is killed if it uses
more than 90 seconds of CPU time.  Unfortunately, this does not kill the
process if it's just blocked (not using CPU).  The following is not
completely free from race conditions, but should be adequate in the
present context.

( ./preprocess input &
for i in {1..90}; do
 sleep 1
 [ -z `ps -o pid --no-headers $pid` ] && exit 0
kill $pid
exit 1) 

 exit 1

# From Don Bahls

Here's a perl script using the "alarm" routine which kills a command
after a specified number of seconds.  It sends a kill signal to the whole 
process group spawned by the parent process.  I think this means you can 
send an arbitrary signal to the child process when the timeout occurs.

# Uses Perl alarm() routine
# See:
use English;
my $status=0;
if ( scalar(@ARGV) < 2 ) { &usage(); exit(1); }
my $wait=shift @ARGV;
if ( ! ( $wait =~ /^\d+$/ ) ) { &usage(); exit(1); }

eval {
   local $SIG{ALRM} = sub { die "alarm\n" };
   alarm $wait;
   if ( $status != 0 ) { exit(2); }
if ( $@ eq "alarm\n" )
       print STDERR "Command '@ARGV' exceeded timeout limit of $wait
       kill -2, $PID;     # kill everything in the process group with
signal 2-- SIGINT.
       # kill -30, $PID;     # kill everything in the process group
with signal 30-- SIGUSR1 (on OS X).
else {
   exit($status);   # this should never be used;

sub usage()
   print STDERR "Usage: runupto s [command] ...";
   print STDERR "\n";
   print STDERR "Purpose: Runs an arbitrary command for up to 's' seconds\n";
   print STDERR "\n";

# From Scott Kajihara

Assuming that Expect (command: expect) is available, the following
provides a timeout of 90 seconds and gives an error message as well:

expect <<EOF
spawn ./preprocess input
set timeout 90
expect {
 timeout {puts "Timed out after 90 seconds"; exit}

# From Ryan Czerwiec:

There's probably an elegant way of doing this in python.  Here's my brute 
force bash solution:

./preprocess input &
sleep 90
kill -9 %1
mpirun ./myjob

This will kill the preprocess job if it's still around after 90 seconds.  
The drawback is that you're forced to wait 90 seconds even if preprocess 
ran very quickly (which of course doesn't guarantee it ran correctly!), 
which may or may not be a problem.  If killing preprocess doesn't guarantee 
that myjob will crash quickly, add this below the kill command to exit 
before myjob runs, so you don't waste CPU time on it:
if [ $? -eq 0 ] ; then exit ; fi

If preprocess finishes in less than 90 seconds, and you can't afford to 
wait the balance of the 90 seconds before proceeding to myjob, this will 
work (fortunately, you've chosen bash, because this gets kind of tricky in 

./preprocess input &
#awk may need to be changed to nawk or gawk on your system
a=`jobs -l 
 awk '{print $2}'`
( sleep 90 ; kill -9 $a ) &
wait %1
unset a
#kill -9 %2
#if [ $? -ne 0 ] ; then exit ; fi
mpirun ./myjob

You can probably do without the "unset a" but it's in there for kicks in 
case having that set might affect anything else you're doing in the script. 
Uncomment the 2 lines after it if, like before, you don't want to let myjob 
even try to run if preprocess timed out.

Q: Occasionally I use the "tee" command to save the output from the make
  command to a file.  Unfortunately, the "tee" seems to mess up my error
  checking.  Here is an example script:


      make 2>&1 
 tee make.eo
      if [ $? -ne 0 ]; then
       echo "Error running make.";
       echo "make was successful.";

  A "make" error yields this disappointing result:

      mg56 % ./build.bash
      make: *** No rule to make target `fred.c', needed by `fred.o'.  Stop.
      make was successful.

  It would be really nice to have my script exit if the "make" fails!  How
  can I fix this?  I can use another language to do this if that's what I
  have to do.

[[ Answers, Questions, and Tips Graciously Accepted ]]

Current Editors:
Ed Kornkven ARSC HPC Specialist ph: 907-450-8669
Kate Hedstrom ARSC Oceanographic Specialist ph: 907-450-8678
Arctic Region Supercomputing Center
University of Alaska Fairbanks
PO Box 756020
Fairbanks AK 99775-6020
E-mail Subscriptions: Archives:
    Back issues of the ASCII e-mail edition of the ARSC T3D/T3E/HPC Users' Newsletter are available by request. Please contact the editors.
Back to Top