350 likes | 628 Views
MT 2009 (I). Introduction to Physics Computing (Tseng). 2. Outline. Objectives of the computing courseSome practical course detailsOverall lecture schemeLecture: basic concepts and constructs. MT 2009 (I). Introduction to Physics Computing (Tseng). 3. Objectives. Learn basic computing skillsComputation and numerical methodsData processing and analysisModelling and simulationAwareness of other uses of computers in physicsLectures
E N D
1. Introduction toPhysics Computing MT 2009
Lecture 1
J Tseng
2. MT 2009 (I) Introduction to Physics Computing (Tseng) 2 Outline Objectives of the computing course
Some practical course details
Overall lecture scheme
Lecture: basic concepts and constructs
3. MT 2009 (I) Introduction to Physics Computing (Tseng) 3 Objectives Learn basic computing skills
Computation and numerical methods
Data processing and analysis
Modelling and simulation
Awareness of other uses of computers in physics
Lectures – basic ideas
How to tell computers what to do
How computers work
Practical course – learn by doing
Actual programming
Actual applications
4. MT 2009 (I) Introduction to Physics Computing (Tseng) 4 Computers in physics Non-linear equations, non-analytic solutions
Data processing, pattern recognition, analysis
Modelling and simulation
Automated control
Data acquisition
Communication: e-mail, web
So how does logical manipulation become all this?So how does logical manipulation become all this?
5. MT 2009 (I) Introduction to Physics Computing (Tseng) 5 The Large Hadron Collider
6. MT 2009 (I) Introduction to Physics Computing (Tseng) 6 ATLAS
7. MT 2009 (I) Introduction to Physics Computing (Tseng) 7 LHC and ATLAS in action 10 Sep 2008 – first beam
Next beam: late 2009
8. MT 2009 (I) Introduction to Physics Computing (Tseng) 8 Computers everywhere Java ME (Micro Edition) A computer can really be just about anything. But electronic control -> easy to build computers -> easy to control other electronic devices.
How do we then tell computers how to do things?A computer can really be just about anything. But electronic control -> easy to build computers -> easy to control other electronic devices.
How do we then tell computers how to do things?
9. MT 2009 (I) Introduction to Physics Computing (Tseng) 9 Computers within computers Computer programs are also used to “emulate” other computers
Sometimes old computers simply don’t exist anymore, but you still want to run the programs
Operating systems (such as Windows 98) aren’t supported anymore, but your program can’t be upgraded
Want to run untrusted program safely – protect against viruses
Increase utilization of web servers
Partition computers in a “cloud”
Or, you’re just nuts
See http://www-jpc.physics.ox.ac.uk for some local information and demonstration on the topic
10. MT 2009 (I) Introduction to Physics Computing (Tseng) 10 Practical course details All students are signed up to do CO00 first, using the Handbook of the Physics Computing Course
This will take you through the elements of the C programming language as well as how to use the Mac systems
You should know when you are to show up in lab
There are 20-30 computers, so pre-allocation is intended to make sure everyone gets time to do it
If you get behind, you can show up for extra sessions. Check with the demonstrators on shift – pre-allocated students get priority
11. MT 2009 (I) Introduction to Physics Computing (Tseng) 11 Practical course details (II) You can also start CO00 at home
This will reduce the amount of time you actually have to sit in lab
Come to lab for questions and to be marked off by a demonstrator
The demonstrator is not responsible for figuring out problems with your home computer – be prepared to transfer your work to the lab machines
You will need a C compiler: check the “Downloads” section of the computing practical course webpage (Cygwin/GCC)
Asking for help or getting marked in lab
Get a demonstrator’s attention
Don’t be surprised if you may have to wait
Continue working as far as you can at your computer
Demonstrators should attend largely in sequence
12. MT 2009 (I) Introduction to Physics Computing (Tseng) 12 Lecture scheme 4 hours MT lectures: introduction
Basic concepts and the “hello world” program
Control flow and data structures
Data representation and input/output
Thinking about computing
Learn by doing in the practical lab
Lectures will try to convey more general concepts
Lectures 2 and 3 are perhaps not interesting if you already know how to program – and they’re not compulsory
13. MT 2009 (I) Introduction to Physics Computing (Tseng) 13 What is a program? Basic idea: it’s a sequence of instructions
14. MT 2009 (I) Introduction to Physics Computing (Tseng) 14 Programs for people
15. MT 2009 (I) Introduction to Physics Computing (Tseng) 15 Programs for people Inputs: hair, shampoo, water
Outputs: clean hair
Memory: hair
Processor: hands
Can reduce to an arbitrary level of detail until you hit philosophical issues of reductivism and free willInputs: hair, shampoo, water
Outputs: clean hair
Memory: hair
Processor: hands
Can reduce to an arbitrary level of detail until you hit philosophical issues of reductivism and free will
16. MT 2009 (I) Introduction to Physics Computing (Tseng) 16 Programs for computers Computers are not people
Computers are really, really, really stupid
They have to be told everything
There is minimal cultural context
Sequence is important: what does a computer know, and when does it know it?
“A computer does what you tell it to do, not what you want it to do”
17. MT 2009 (I) Introduction to Physics Computing (Tseng) 17 Programs for computers (2) How you might tell a robot:
Still have to tell the robot how to lather and rinse!
18. MT 2009 (I) Introduction to Physics Computing (Tseng) 18 Hello World A simpler example in C (no robots): The program – introducing the idea of control flow (simple in this case) and outputThe program – introducing the idea of control flow (simple in this case) and output
19. MT 2009 (I) Introduction to Physics Computing (Tseng) 19 Xcode Xcode is an “integrated development environment” (IDE)
Most modern development is done with IDE’s (though a lot of scientists seem to think they’re wimpy)
It provides program templates (projects) – code bits that get used over and over again
Provides tools to speed programming and “debugging”
For practical course programming, there is a special Practical Course Project already defined for Xcode – use this to start
20. MT 2009 (I) Introduction to Physics Computing (Tseng) 20 Building and running The program may not look very readable, but it’s still too much for a computer to understand
Compile – translate something “human readable” into something a computer can use
This doesn’t stop us from making our programs unreadable to us
Comments
Spacing
Link – resolve all outstanding names
In previous example, printf() is from the “standard library”
Compiling and linking all program units thus “builds” a single program
Run – tell a computer to start a program
Xcode allows you to write, build, and run in the same environment
For small programs, Xcode is perhaps overkill; for large programs it’s very useful
21. MT 2009 (I) Introduction to Physics Computing (Tseng) 21 Command-line Mac OS X is built on Unix, a popular operating system for scientific computing
Command line: keyboard control, like the DOS prompt underneath Windows (but a lot better!)
Edit
Compile/link
Execute
22. MT 2009 (I) Introduction to Physics Computing (Tseng) 22 Saying more than “hello” Do a simple calculation
23. MT 2009 (I) Introduction to Physics Computing (Tseng) 23 Storage If you want to save something for later, you put it in a pigeonhole (often called a “variable”, but not in the same sense as in mathematics)
Pigeonholes have a “type”
int: -231 to (231-1)
float: 6 digits, 10-38 to 1038
double: 15 digits, 10-308 to 10308
char: single characters (actually numerical representation)
Boolean type (true/false) represented by integer 1 or 0 Have you ever noticed how your pigeonhole may not accept large packages? The reason is that it’s probably made for letters and papers.Have you ever noticed how your pigeonhole may not accept large packages? The reason is that it’s probably made for letters and papers.
24. MT 2009 (I) Introduction to Physics Computing (Tseng) 24 Storage (2) Every pigeonhole has a name, a type, and a location (like a street address)
Every pigeonhole name in C must begin with a letter
Upper and lower case characters are different
There are “reserved words” which cannot be used as a pigeonhole name
You have to warn C that you are going to store something by declaring it in the beginning
This sounds restrictive, but you can also use it as a check on your programming logic
25. MT 2009 (I) Introduction to Physics Computing (Tseng) 25 Storage (3)
A pigeonhole is like a “hole in the wall”
Contents (for instance): Brasserie Blanc
Address: 71-72 Walton Street
Type: restaurant
Size: 2 shops
Imagine if you could think of property like this (not completely a joke)
Sometimes you will need a pigeonhole’s address (&a) rather than the contents
26. MT 2009 (I) Introduction to Physics Computing (Tseng) 26 For calculations, similar to arithmetic
* is multiplication and / division, rather than ? and ÷
Normal operator precedence: */ before +-:
Assignment is an operator!
Operators
27. MT 2009 (I) Introduction to Physics Computing (Tseng) 27 Relational operators Again, similar to what you would expect
> and <
>= and <= for including equality
!= for inequality
== for equality (since = is for assignment)
Evaluated after arithmetic operators
These operators take number types (int or float) and return an integer 0 for false and 1 for true, like a boolean value
28. MT 2009 (I) Introduction to Physics Computing (Tseng) 28 Boolean operators AND, OR, NOT of Boolean expressions
In C: &&, ||, and !
You will run into these again in digital electronics (electronics practical lab)
Even lower precedence than relational operators
It is good to use parentheses for clarity in spite of well-defined operator precedence
29. MT 2009 (I) Introduction to Physics Computing (Tseng) 29 Operator pitfalls Commas are operators
Common pitfall: using commas instead of semicolons can result in difficult-to-find errors!
Bitwise operators: &, |, ^
These are different from boolean operators!
Assignment vs equality: = vs ==
Not an exhaustive list of operators (or pitfalls!), merely a general introduction
30. MT 2009 (I) Introduction to Physics Computing (Tseng) 30 printf() – “print formatted”
Format codes dictate how data is printed:
%d – int
%f – float
%s – strings
Also plain text
\n tells the computer to advance one line on the screen
Pretty output
31. MT 2009 (I) Introduction to Physics Computing (Tseng) 31 Make the program more useful by allowing the user to enter own values
Now can use this program with different values without having to rebuild
Same format codes as printf()
Note use of &: scanf() needs to know where to store the values
Input
32. MT 2009 (I) Introduction to Physics Computing (Tseng) 32 Adding machine Source code for program; remember that programs are step-by-step instructions for the computerSource code for program; remember that programs are step-by-step instructions for the computer
33. MT 2009 (I) Introduction to Physics Computing (Tseng) 33 Additional tips “Debugging”:
Very few programs work the first time
Test for unacceptable circumstances, print or return something descriptive
Print intermediate values and compare with your expectations
Comments:
Like a log book: will you understand in 6 months?
Describe at least major sections of code
34. MT 2009 (I) Introduction to Physics Computing (Tseng) 34 Next lecture Same time and place (Mon 10am Martin Wood)
Data representation
Control flow