[Menu Bar] Resourses at ARSC Science at ARSC Newsroom Support About ARSC ARSC Home

 

ARSC HPC Users' Newsletter 346, August 18, 2006

Newsletter Index Quick-Tip Index Search Newsletters

Contents

 

Compiler Warnings

The compiler can quickly point out many common bad coding practices if you use the right compiler flags. The GNU C compiler does a particularly good job of doing this, though most compilers have several levels of diagnostic messages. When you are developing code or moving to a new architecture it is a good idea to let the compiler give you as much information as possible.

The GNU C Compiler

The GNU C compiler (gcc) has some great diagnostic warnings that can help you track down bad coding habits and possible bugs in your code.

The following warnings flags are available:

Here's a short code illustrating bad C coding practices which gcc can catch.

c613n6% cat warning.c
#include <stdio.h>
#include <stdlib.h>

/*
Example code showing the 5 warning types that gcc can detect.
  -Wall will enable all of these.

*/

void bad_formatting(unsigned long long val)
{
    /* format %d does not match the type of val.  In this case,
       this mistake results in the wrong value being printed.
    */
    printf("val=%d\n",val);
}

no_return_type()
{
    /* this subroutine does not has an implicit return type (int) */
    return 0;
}

int main()
{
    /* the variable ii is declared but never used */
    int ii;
    unsigned long long jj=(1ll<<63);
    
    bad_formatting(jj);
    
    /* nested comments could potentially cause problems /* */
    
    /* main does not return an int value */
}

Here's a look at the various warnings we see with these warning flags:

c613n6% for f in "-Wformat" "-Wimplicit" "-Wunused" "-Wcomment" "-Wreturn-type";     
> do
> echo $f
> gcc $f warn.c -o warn
> echo 
> done
-Wformat
warn.c: In function `bad_formatting':
warn.c:15: warning: int format, different type arg (arg 2)

-Wimplicit
warn.c:19: warning: return type defaults to `int'

-Wunused
warn.c: In function `main':
warn.c:27: warning: unused variable `ii'

-Wcomment
warn.c:32:57: warning: "/*" within comment

-Wreturn-type
warn.c:19: warning: return type defaults to `int'
warn.c: In function `main':
warn.c:35: warning: control reaches end of non-void function

The XLC Compiler

The default behavior of the IBM xlc compiler is to show informational messages. At that warning level the xlc compiler only warns about one of the conditions in the code above (i.e. for "/*" being detected within a comment). The "-qflag" compiler option will alter the severity level of messages which should be written to the compiler listing and terminal (see the xlc man page for options)

Additionally xlc can produce warnings when 64 bit portability issues are detected:

 

WRF Tutorial

Topic: WRF Tutorial at ARSC

When: Thursday August 24th, 8:30 AM - 4:00 PM

Location: WRRB 009

Instructor: Dr. Don Morton (U. Montana & ARSC)

Description:

One-day tutorial will provide attendees with exposure to the mechanics of using WRF (the Weather Research and Forecasting Model) on ARSC resources. The tutorial will include hands-on use of ARSC's Cray XD1 system, nelchina. At the end of the tutorial, attendees shall have prepared, executed and viewed a "standard" tutorial case study (Hurricane Katrina model), and a simple case study of their own choosing within the Alaska region. Attendees will gain basic proficiency with WRF, and become aware of requirements for applying WRF to individual research purposes.

NOTE: This workshop is limited to 20 attendees so registration is required (see link). There are only a few spaces still open.

More Information:
http://www.arsc.edu/support/training/WRFtraining2006.html

 

Physics 693 & Fall Training

Classes will begin in a few weeks at UAF and ARSC staff along with the UAF Physics department will be teaching Physics 693 once again. The Core Skills for Computation Science class serves as an introduction to the basic skills required to operate in a modern high performance computing environment.

If you are in need of another class this semester, check out the Core Skills class. ARSC users are encouraged to attend any lecture they would find beneficial.

More information on class topics will be listed in future newsletters.

 

Quick-Tip Q & A

A:[[ I'm looking for a file that I changed a few minutes ago. 
  [[ Unfortunately I seem to have forgotten the name.  Is there a easy 
  [[ way to search for any files in directory or subdirectory that have 
  [[ changed in the last 10 minutes?


#
# Thanks to Jed Brown, Rich Griswold Jay Cliburn, and Jing Zhang
# for pointing out the -mmin flag in the GNU version of find.
#
  
To search for any file under the current directory which has been
modified in the last 10 minutes:

% find . -mmin -10


#
# Thanks to Brad Havel for this response.
#

For the above question I'd use a combination of find, awk, and sort
to generate a list of files which have been modified.  With find I'd
display files which have been modified in the last 24 hours by using
the parameters "-type f -mtime 1".  Then use awk to format a slightly
nicer output than the standard "ls -l" would provide.  Finally,
reverse sort the output so newer files are at the top of the list.
End result would be easy enough to view and identify the likely file.

% find ./ -type f -mtime 1 -exec ls -l {} \; | 
  awk '{ printf "%s %2d %s %s\n",$6,$7,$8,$9 }' | sort -r
Aug 7 10:07 ./adm/pacct
Aug 7 09:48 ./adm/SYSLOG
Aug 7 09:38 ./tmp/rc_host_0
Aug 7 09:38 ./adm/SYSLOG.auth
Aug 7 09:38 ./ace/sdconf.original
Aug 7 09:24 ./adm/wtmpx
Aug 7 09:24 ./adm/utmpx
Aug 7 09:24 ./adm/lastlog
Aug 7 09:09 ./ntp/ntp.drift
 
 
#
# Thanks to Lee Higbie for this response.
# 

Find the file that changed in the last ten minutes?

% find ~ -exec ls -dul {} \; | grep "Aug 09 11:[12]"

Notes on the above command: 

The tilde points to the directory where the search will begin.  The d
flag on the ls command (fifth item overall above) keeps the ls command
from listing the contents of directories.  The find command will reach
every file eventually as it searches down the tree from ~.  I've put
"Aug 09 11:[12]" as the date.  Check an ls -l listing for the exact
format of the date & time for your search.  You have to put quotes
around the date or escape the spaces because all the grep utilities
search based only on the first argument.  The square brackets tell
grep to search for either the string 'Aug 09 11:1' or 'Aug 09 11:2'.


Q:[[ I am writing a script which looks at the extension of a file.  
  [[ So far I'm not too commited to a particular scripting language.  
  [[ Is there an easy way to get the extension of a file without 
  [[ using sed!  

        

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

 

 


Current Editors:
Thomas J. Baring ARSC Web Specialist ph: 907-450-8619
Donald Bahls ARSC User Consultant ph: 907-450-8674
Arctic Region Supercomputing Center
University of Alaska Fairbanks
PO Box 756020
Fairbanks AK 99775-6020
Contact:
Send comments and questions to the current editors using this Contact Form.
Email Subscriptions: Archives:

 

Newsletter Index Quick-Tip Index Search Newsletters

 

Arctic Region Supercomputing Center
PO Box 756020, Fairbanks, AK 99775 | voice: 907-474-6935 | email:

home | search | about | support | news | science | resources