Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
The Course The Course The Motivation The Speaker Introduction Development Workflow
1. Introduction
27. Juni 2011
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 1 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Outline
• The Course
• The Motivation
• The Introduction
• What is a computer?von-Neuman architecture
• What is a high-level language?bytecode, intermediatelanguages, and the real world
• Where does it all come from?historic overview & the softwarecrisis
• The Development Workflow:Algorithms, Tools, and Activities
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 2 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
—1.1. The Course—
There ain’t no such thing as a free lunch.
R. A. Heinlein, The Moon Is a Harsh Mistress
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 3 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
—1.2. The Course—
Concept
• Through C/C++ in a rush
• Programming means training—course can’t replace it
• Provide a deeper understanding ofunderlying mechanisms
• Three slots a 45 minutes per day
• Provide some exercises throughoutthe course lectures
• Provide some programming support
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 4 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Didactic Concept
In theory there is no difference between theory and practice. In practice there is.
Yogi Berra
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 5 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
After the Course
Temple Church, London
• Through C/C++ in a rush
• Programming means training—course can’t replace it
• Provide a deeper understanding ofunderlying mechanisms
• Content is tailored to Ph.D. students(not undergrads)
• Content is aligned with scientificsoftware
• Three slots a 45 minutes per day
• Provide some exercises
• Provide some programming support
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 6 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Calendar
• From Monday, June 26, till Friday, July 8.
• Each day three sessions a 45 minutes.
• We start at 9:30 and end around 12:15.
I provide additional programming support each day after the lectures. If I don’t stay atthe lecture room after the course for the programming support, feel free to write me anemail ([email protected]).
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 7 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
The Guttenberg Slide
• Martin Fowler: Refactoring• Erich Gamma, Richard Helm, Ralph Johnson, John M. Vlissides. Design Patterns:
Elements of Reusable Software• Randall Hyde: Write Great Code I: Understanding the machine• Randall Hyde: Write Great Code II: Thinking Low-level, Writing High-level• Scott Meyers. Effective C++• Scott Meyers. More Effective C++• Walter Savitch. Absolute C++• Bjarne Stroustrup. The C++ Programming Language
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 8 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
—1.3. The Motivation—. . . about the Leaning Tower
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 9 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
The two pillars of science
Theory ExperimentWhat happens if these pillars can’t be realised or should not be realised?
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 10 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
The three pillars of science
Theory ExperimentSimulation
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 11 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
The Scientific Workflow—an Iterative Scheme
Modelling NumericalTreatment
Design ofSoftware
Implementation
NumericalExperiments
Postprocessing
Visualisation Tests
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 12 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Scientific Software Crisis
PITAC report 2005
PITAC report 2005: Today’sCSE ecosystem is unbalan-ced, with a software basethat is inadequate to keeppace with and support evol-ving hardware and applicati-on needs.
It is consequently of uttermost importanceto have skilled and trained programmers.Programming comprises both a craft and anart, and, hence, coding is not just an unim-portant task which can be left to “less” intel-ligent henchmen.
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 13 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
However . . .
PITAC report 2005: Today’s CSE ecosystem is unbalanced, witha software base that is inadequate to keep pace with and supportevolving hardware and application needs.
It is consequently of uttermost importance to have skilled and trained programmers.Programming comprises both a craft and an art, and, hence, coding is not just anunimportant task which can be left to “less” intelligent henchmen.
Almost everybody almost all the time: I agree – but in my caseit’s different. I have better/more urgent things to do than to thinkabout software as, before, I have to understand the underlyingphysical/technological/medical principles.
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 14 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
A Success Story—Sorry About the Sarcasm
Nature 447: In 2006, data from the array led a team of scientiststo the surprising conclusion that the world’s oceans had cooledduring 2003 exceptionally warm years in terms of global surfacetemperature. The team published its findings in Geophysical Re-search Letters[1]. Such apparent cooling was seized on by peo-ple keen to highlight the uncertainties in forecasts of global war-ming[2].That cooling has now been shown to be an artifact. In some of thebuoys – they are manufactured in separate batches – a softwareglitch caused the temperature and salinity data to be associatedwith the wrong depths. When the problem data are excluded fromthe analysis, the cooling trend drops below the level of statisticalsignificance. (pp. 7140)
http://www5.in.tum.de/~huckle/bugse.html
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 15 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Why Matlab sometimes doesn’t work
Herb Sutter. The free lunch is over: A fundamental turn toward concurrency insoftware, Dr. Dobb’s Journal, 30(3),
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 16 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Statements
• More and more insight will stem from simulations.• New insight requires more computing power.• More computing power will result from parallelism and other hardware stuff.• Mathematicians, engineers, physicians, etc. will write the applications—the
computer guys write web apps and earn tons of bucks with Google & Co.• If you wanna use a tool, you have to learn how to handle it.• So learn C/C++/FORTRAN, and, more important, understand what’s happening
there.
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 17 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
—1.4. The Speaker—
Excerpt From my CV
June 2000-October 2000 Worksd&m AG, Munich: Stock exchange (C++)
October 2000–October 2005 Computer Science at TUMworked at sd&m AG, Munich: Financial services (Java)Hiwi at Chair of Systems & Software Engineering:Ubungen zur Einfuhrung in die Informatik (Java)
July 2009 Ph.D. DefenseA Framework for Parallel PDE Solvers onMultiscale Adaptive Cartesian Grids (C++)
October 2009–now KAUST-TUM Scientific Project ManagerPeano frameworkSoftware Engineering, coding best practices,and domain-specific languages inHigh Performance Computing
July 2011– Habil at TUMLots of HPC software ...
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 18 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
—1.5. Introduction—
A Turing Machine
MemoryALU
IO
• If we wanna handle a car/machine(efficiently), we have to know how itworks. That doesn’t mean that wehave to be able to construct acar/machine ourselves.
• Computer (von-Neumannarchitecture): ALU, Memory, IOController, Bus
• Processor
• (Very) simple binary operationssuch as add, increment, . . .
• Takes one or two numbers,combines them, and writes backresult to memory
• Has a program counter holdingone number
• Memory
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 19 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Memory
Memory
ALU
IO
21:22;23;24; 425; 526;27;28:
• Processor
• (Very) simple binary operationssuch as add, increment, . . .
• Takes one or two numbers,combines them, and writes backresult to memory
• Has a program counter holdingone number
• Memory
• Long linear sequence of post its(storage locations)
• Sequence of storage locationsholds natural numbers
• Storage locations areenumerated
• Example: Add entry 24 and entry25 and write result back to entry21
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 20 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
A First Machine Code
Memory
ALU
IO
21:22;23;24; 425; 526;27;28:
• Processor
• (Very) simple binary operationssuch as add, increment, . . .
• Takes one or two numbers,combines them, and writesback result to memory
• Has a program counter holdingone number
• Memory
• Long linear sequence of post its(storage locations)
• Sequence of storage locationsholds natural numbers
• Storage locations areenumerated
• Example: Add entry 24 and entry25 and write result back to entry21
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 21 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Program Counter
Memory
ALU21:22;23;24; 425; 526;27;28:
113: add114; 24115; 25116; 21
PC: 113
• Processor
• (Very) simple binary operationssuch as add, increment, . . .
• Takes one or two numbers,combines them, and writes backresult to memory
• Has a program counter holdingone number
• Memory
• Computer program is a sequenceof natural numbers
• Each number equals command(code)
• Program counter tells ALU whichcommand to execute next
• Program counter incrementedafter each command
• Random access memorymachine—RAM machine
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 22 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Instruction Streams
Memory
ALU21:22;23;24; 425; 526;27;28:
113: add114; 24115; 25116; 21
PC: 113
• Properties of machine instructions
• Code, i.e. number-to-commandmapping, is machine-specific
• Set of available commands ismachine-specific
• Constraints on codes (whichcodes are allowed when) aremachine-specific
• Performance of a command ismachine-specific
• Writing machine code
• Cumbersome (small number ofdirectives)
• Error-prone• Not portable
⇒We need a more abstract program description (programming language).
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 23 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Algorithm
An algorithm is a method/recipe expressedas• finite list of• effective instructions/actions for• calculating a function/solving a
problem.
Where do we find algorithms on a daily ba-sis?
Abu Abdullah Muhammad bin Musa al-KhwarizmiPersian mathematician, 780–850 A.D.
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 24 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Cooking
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 25 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Cooking—by Isaac Nassi and Ben Shneiderman
Open Door of Appartment
All guys enter room
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 26 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Cooking—by Isaac Nassi and Ben Shneiderman
Open Door of Appartment
All guys enter room
Hungry?
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 27 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Cooking—by Isaac Nassi and Ben Shneiderman
Open Door of Appartment
All guys enter room
Hungry?No Yes
Call Pizzaservice
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 28 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Cooking—by Isaac Nassi and Ben Shneiderman
Open Door of Appartment
All guys enter room
Hungry?No Yes
Call Pizzaservice
For each buddy
Open abeer
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 29 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Create your own diagram
Write down a Nassi–Shneiderman diagram(belonging to structured programming) forthe following formula:
s(n) =∑
k
k with n mod k = 0.
Hint: Just run over all k and find out whetherthey fit into n.
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 30 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Translation Concepts
Algorithm
Machine CodeIntermediate Code
To be done for each architectureSell/give it to the customerInstall it on the computer
To be done once
Compiler(Translator)
Compiler(Translator)
Machine Code
Interpreter(Simultan Translator)
Sell/give it to the customerInstall it on the computer
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 31 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
A Compiler . . .
• . . . is a big translation table, i.e. a = 4; b = 5; c = a + b becomes
move4to 24move5to 25add2425to 21
• . . . does all the management and linearisation of the memory stream
• . . . provides more abstract commands than the machine language can do
• . . . manages the program counter
• . . . and does a lot more
⇒ Each real computer scientist has to invent at least one new language and write thecorresponding compiler once in his/her lifetime!
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 32 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
History of C
• Origins (1970s)
• Zoo of languages & compilers• Among them A and B (Ken Thompson, invented UNIX)• Use to write operating systems
• History of C
• 1972, Dennis M. Ritchie, Bell Laboratories, AT&T• 1973/74, Brian W. Kernighan• Purpose: Write operating systems and compilers
• Fundamental concepts of C
• Powerful to write an operation system• Small number of commands• Structuredness (no sequences of assembler code)
• State of C
• Used to write UNIX• General purpose language• Available on all UNIX systems
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 33 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
History of C++
Bjarne Stroustrup
• Software Crisis (80s)
• Complex systems, difficult tomaintain
• Lack of abstraction• Lack of modelling facilities
⇒ Smalltalk and the OOP
• History of C++
• early 80s, Bjarne Stroustrup, BellLaboratories, AT&T
• extension of C, i.e. C programsare C++ programs
• with new ideas of OOP
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 34 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
C++—State of the Art?
Memory
ALU21:22;23;24; 425; 526;27;28:
113: add114; 24115; 25116; 21
PC: 113
• Popular languages such as Java or C#are C ++−−
• They now adopt concepts of C++formerly deprecated
• New paradigms are discussed, buthave to stand the test of time
• Next generation C++0x is not yetreleased
• Many application areas (in particularHPC and Scientific Computing) havenot yet fully adopted and understoodOOP and C++
This course teaches C++ from scratch. However, it does not follow the historic pathneither does it start directly with sophisticated OOP concepts. It rather follows theacademic path, i.e. introduces one fundamental concept at a time. As OOP (as aconcept) still is considered to be sophisticated in our disciplines, it will be the last thingwe talk about.
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 35 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
—1.6. Development Workflow—
Three Tools Coin Our Work
• Editor (vi, Emacs, Notepad, whatever)to write simple text files
• Compiler (g++) invoked on thecommand line
• Linker (g++) invoked on the commandline
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 36 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
If Programming Were Cooking . . .
• Editor (vi, Emacs, Notepad, whatever). . . we would write down with the editorthe recipe of one single dish such asthe dessert or the main course. Therecipe then is the algorithm and it iswritten down as source code which istypically a simple text file with theextensions .c, .cpp, and so forth.
• Compiler (g++)
• Linker (g++)
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 37 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
If Programming Were Cooking . . .
• Editor (vi, Emacs, Notepad, whatever)
• Compiler (g++). . . would take the recipe (sourcecode) and cook it. The results arecalled object code or object files. Theytypically have the extension .o. It isinvoked by g++ -c filename.c.
• Linker (g++)
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 38 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
If Programming Were Cooking . . .
• Editor (vi, Emacs, Notepad, whatever)
• Compiler (g++)
• Linker (g++). . . would take the individual dishesand combine them into a completemeal with several courses. It isinvoked by g++ filename1.o
filename2.o -o outputfile andproduces an executable.
. . . there would be a menu card given by several header text files as well. They typicallyhave the extension .h or .hpp.
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 39 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Standard Workflow
• Write down your source codes (files file1.cpp, file2.cpp, ...) into text fileswith an editor of your choice
• Write down your descriptions (files file1.h, file2.h, ...) (we will do this lateras it is a matter of style) into text files with an editor of your choice
• Open your command line and typeg++ -c file1.cpp . produces file1.og++ -c file2.cpp . produces file2.og++ file1.o file2.o myappl . produces executable myappl./myappl . execute myappl
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 40 of 41
The Course The Course The Motivation The Speaker Introduction Development Workflow
Exercise
• vi first-appl.cpp
# inc lude <iostream>i n t main ( ) {s td : : cout << ” He l lo yourname ” ;r e t u r n 0 ;
}
• g++ -c first-appl.cpp
• ls
• g++ first-appl.o -o myappl
• ls
• ./myappl
1. Introduction
Einfuhrung in die Programmierung—Introduction to C/C++, Tobias Weinzierl page 41 of 41