csce 206 1 csce 206 scientific applications programming this is not a course in “programming”...
Post on 20-Dec-2015
215 views
TRANSCRIPT
CSCE 206
1
CSCE 206Scientific Applications Programming
This is not a course in “programming”
This is a course in “computing”
We will do a lot of programming
It will at times seem like a course in programming, because we will sometimes get bogged down in details…
CSCE 206
2
CSCE 206
This will at times seem like a course in programming, because we will sometimes get bogged down in details…
Try to remember• that this is a course in “computing”• that to know “computing” you must know
“programming”• that our goal is “computing” for numerical
applications
CSCE 206
3
Numerical Applications
Top 500 list www.top500.orgFinding roots of equationsInterpolation of functionsCurve fittingNumerical differentiationNumerical integrationMatrix operationsAverages, deviations, momentsDifferential equations
CSCE 206
4
Why Fortran?
Why not Matlab? MathCad? Maple? Mathematica?
For “small” applications, these are fine
For “large” applications, they are too slow and inflexible
“Real” computing requires a “real” language
CSCE 206
5
Which Fortran?
195x – FORTRAN1962 – FORTRAN II1966 – FORTRAN IV (a.k.a. FORTRAN 66)1977 – FORTRAN 771990 – Fortran 901995 – Fortran 952003 – Fortran 2000 a.k.a. Fortran 2k
Various other versions have also existed (HPF, IBM FORTRAN G, H, …)
CSCE 206
6
Which Fortran?
The big change was to Fortran 90 from FORTRAN 77
We will do F90, which is the “modern” Fortran
Differences between F90, F95, and F2K are nonexistent at the level of this course
Vendors have always “enhanced” their languages as a way of making vendor switching hard
We will concentrate on ANSI Standard Fortran 90(ANSI = American National Standards Institute)
CSCE 206
7
Why Unix?
For small jobs, for simple experimentation, you should use Matlab, or something similar.
The reason for using a real programming language is to solve problems too big for desktops.
There aren’t any non-Unix machines on the Top 500 list (and I don’t think there ever have been any).
Real computing is done on Unix machines.
CSCE 206
8
Which Unix?
It is almost true that all Unix is alike.UnixLinuxSolaris (Sun Microsystems)HPIX (Hewlett-Packard)Irix (Silicon Graphics)UNICOS (Cray Research, Inc.)AIX (IBM)
CSCE 206
9
Why Unix?
“I view different computer operating systems as being like different cuisines. Using an Apple is like keeping kosher; the believers would not live any other way, but they cannot eat with members of other religions. Using Unix is like preparing your own meals from recipes in the Joy of Cooking; the effort involved initially exceeds the palatability of the results, but experience eventually brings satisfaction. Using Microsoft Windows is like eating at a McDonald’s; you can find one anywhere, and the food will keep you going, but it would be sad if there were no other restaurant in town.”
(Gerald Folland, American Math Monthly, March 2000)
CSCE 206
10
Bottom Line
We will, therefore, cover• computing• in the modern (standard) version of Fortran• on numerical applications• on a standard Unix platformThis will be computing done the way it’s done in
the major leagues (Los Alamos, NCAR, Livermore, aircraft/auto/oil industry)
This will (I hope) prepare you to be adaptable to Fortran (and other languages) on other platforms using other compilers and tools
CSCE 206
11
How-to-write-programs Issues
The operating system (in this case, Unix)The development environment• editor (you are free to choose)• we will not use a GUI (graphical user
interface)• we will use a command line interface• we will use a makefile for convenienceCompiler to translate source code to an
executableLibraries of standard routines (math functions,
etc.)
CSCE 206
12
CSE Dept: How to Write Programs
I don’t use Blackboard; I do use the CSE web server, and almost everything will be on the web
• look up the CSE secure web page https://www.cse.sc.edu
• CSCE dropbox for submitting your programs• CSCE206 group mailing list for broadcast• CSCE individual email accountswww.cse.sc.eduwww.cse.sc.edu/~buell
CSCE 206
13
Bonus Points
Computing is a human endeavor
You should know the human history of how we got to where we are
In-class bonus points: 1 point on the total grade
Exam bonus points: 2 points on the total grade per exam
CSCE 206
14
Some Thoughts on Programming
“Lesser artists borrow; great artists steal.”Stravinsky
There is a lot of code available to look at and use.
CSCE 206
15
From Whom Can You Steal?
Yourself—of course, from one program to the next
From the text—yesFrom the Internet—noFrom yourself—yesFrom other reference books—noFrom yourself—yesFrom the Internet—no
There is a program that lets me compare one program against another for similarities.
CSCE 206
17
Chapter 0 (or 1?)
Computer organisation and architecture
How is the machine put together
p17-ComputerComponents.pdf
CSCE 206
18
The Program Translation Process
Program source code (C, Fortran, Java, …)
Source is translated by a compiler
into object code
and then into machine code
which forms an executable module
CSCE 206
19
Source Code
Has symbolic names for things and permits writing programs in a way that is understandable by people.
PROGRAM hello_world
IMPLICIT none
REAL :: r,s
PRINT *, “hello, world”
PRINT *, “My name is Duncan Buell”
r = 64.0
s = SQRT(r)
PRINT *, “r is”,r,“and its square root is”,s
STOP
END PROGRAM hello_world
CSCE 206
20
Machine Code
Machines don’t understand Fortran
Computers don’t have a single “instruction” that prints a line of output, for example
Machine code is the numerical language for the specific instructions of the machine
one machine code instruction = one machine operation
The compiler (and other language translators) turn source code into machine code
CSCE 206
21
Object Code
Object code is intermediate between source and executable
We won’t deal much with object code, and we won’t even define it carefully
Characteristic of object code• the compiler turns your source into object• references outside your own source (e.g., math
libraries) may not be fully turned into machine code by the compiler—that happens later
CSCE 206
22
The Programming Process
Problem analysis and specification
Data organisation and algorithm design
Coding (programming)
Execution and testing
Maintenance
CSCE 206
23
Political Correctness—“Safe” programming
Programs have bugsPrograms have always had bugsWe all do stupid, careless, things
It’s possible to be careless and still get a working program
But it’s more likely that you’ll get working programs if you follow “safe” programming practices
And I’m going to beating these practices into you the entire semester!!!!!
CSCE 206
24
Prudent Programming Practices
“Failure is the norm. You’re going to fail. So fail in such a way that you can recover quickly and get it right the second time.” (John Mashey)
A working program that doesn’t quite do what is desired has some value.
A program that would do everything desired, if it worked, but doesn’t work, has almost no value.
“Make it right before you make it better.”