The Speaker The Course Introduction Development Workflow 1. Introduction June 7, 2010 1. Introduction Introduction to C/C++, Tobias Weinzierl page 1 of 27
Sep 17, 2015
The Speaker The Course Introduction Development Workflow
1. Introduction
June 7, 2010
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 1 of 27
The Speaker The Course Introduction Development Workflow
Outline
The Speaker The Course
Concept Calendar Literature
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:Tools and Activities
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 2 of 27
The Speaker The Course Introduction Development Workflow
1.1. The Speaker
Excerp From my CV
19971999 Ringeisen Gymnasium Ursberg:3D software renderer (Pascal/C)
June 2000October 2000 sd&m AG, Munich:Stock exchange (C++)
March 2001September 2001 Chair of Systems & Software Engineering:Ubungen zur Einfuhrung in die Informatik(Java)
September 2002February 2003 sd&m AG, Munich:Financial services (Java)TUMLots of Mathematics and Scientific Computing
July 2009 Ph.D. DefenseA Framework for Parallel PDE Solvers onMultiscale Adaptive Cartesian Grids (C++)
October 2009now KAUST-TUM Scientific Project ManagerPeano frameworkSoftware Engineering, coding best practices,and domain-specific languages inHigh Performance Computing
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 3 of 27
The Speaker The Course Introduction Development Workflow
The Scientific Workflowan Iterative Scheme
Modelling NumericalTreatment Design of
Software
Implementation
NumericalExperiments
Postprocessing
Visualisation Tests
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 4 of 27
The Speaker The Course Introduction Development Workflow
Scientific Software Crisis
PITAC report 2005
PITAC report 2005: TodaysCSE 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
Introduction to C/C++, Tobias Weinzierl page 5 of 27
The Speaker The Course Introduction Development Workflow
However . . .
PITAC report 2005: Todays 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 caseits 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
Introduction to C/C++, Tobias Weinzierl page 6 of 27
The Speaker The Course Introduction Development Workflow
A Success StorySorry About the Sarcasm
Nature 447: In 2006, data from the array led a team of scientiststo the surprising conclusion that the worlds 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 artefact. In someof the buoys they are manufactured in separate batches asoftware glitch caused the temperature and salinity data to beassociated with the wrong depths. When the problem data areexcluded from the analysis, the cooling trend drops below thelevel of statistical significance. (pp. 7140)
http://www5.in.tum.de/~huckle/bugse.html
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 7 of 27
The Speaker The Course Introduction Development Workflow
1.2. The Course
Concept
Through C/C++ in a rush Programming means training
course cant replace it
Provide a deeper understanding ofunderlying mechanisms
Three slots a 45 minutes per day Provide some exercises Provide some programming support
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 8 of 27
The Speaker The Course Introduction Development Workflow
After the Course
Temple Church, London
Through C/C++ in a rush Programming means training
course cant 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
Introduction to C/C++, Tobias Weinzierl page 9 of 27
The Speaker The Course Introduction Development Workflow
Callendar
Monday, June 7, 3 slots, 9:3010:15, 10:3011:15, 11:3012:15 Tuesday, June 8, 2 slots, 10:3011:15, 11:3012:15 Wednesday, June 9, 3 slots, 9:3010:15, 10:3011:15, 11:3012:15 Thursday, June 10, 3 slots, 9:3010:15, 10:3011:15, 11:3012:15 Friday, June 11, 3 slots, 9:3010:15, 10:3011:15, 11:3012:15 Monday, June 14, 3 slots, 9:3010:15, 10:3011:15, 11:3012:15 Tuesday, June 15, 2 slots, 10:3011:15, 11:3012:15 Wednesday, June 16, 3 slots, 9:30-10:15, 10:3011:15, 11:3012:15 Thursday, June 17, 2 slots, 9:3010:15, 10:3011:15
I provide an additional hour programming support each day after the lectures. OnTuesday, the lectures start later as I have to do another lecture before. If I dont stay atthe lecture room after the course for the programming support, feel free to write me anemail ([email protected]).
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 10 of 27
The Speaker The Course Introduction Development Workflow
Literature
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
Introduction to C/C++, Tobias Weinzierl page 11 of 27
The Speaker The Course Introduction Development Workflow
1.3. Introduction
A Turing Machine
MemoryALU
IO
If we wanna handle a car/machine(efficiently), we have to know how itworks. That doesnt mean that wehave to be able to construct acar/machine ourselves.
Computer (von-Neumannarchitecture): ALU, Memory, IOController, Bus
Processor (Very) simple binary operations
such as add, increment, . . . Takes one or two numbers,
combines them, and writes backresult to memory
Has a program counter holdingone number
Memory
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 12 of 27
The Speaker The Course Introduction Development Workflow
Memory
Memory
ALU
IO
21:22;23;24; 425; 526;27;28:
Processor (Very) simple binary operations
such 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 locations
holds natural numbers Storage locations are
enumerated Example: Add entry 24 and entry
25 and write result back to entry21
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 13 of 27
The Speaker The Course Introduction Development Workflow
A First Machine Code
Memory
ALU
IO
21:22;23;24; 425; 526;27;28:
Processor (Very) simple binary operations
such 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 locations
holds natural numbers Storage locations are
enumerated Example: Add entry 24 and entry
25 and write result back to entry21
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 14 of 27
The Speaker The Course Introduction Development Workflow
Program Counter
Memory
ALU 21:22;23;24; 425; 526;27;28:
113: add114; 24115; 25116; 21
PC: 113
Processor (Very) simple binary operations
such 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 sequence
of natural numbers Each number equals command
(code) Program counter tells ALU which
command to execute next Program counter incremented
after each command Random access memory
machineRAM machine
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 15 of 27
The Speaker The Course Introduction Development Workflow
Instruction Streams
Memory
ALU 21:22;23;24; 425; 526;27;28:
113: add114; 24115; 25116; 21
PC: 113
Properties of machine instructions Code, i.e. number-to-command
mapping, is machine-specific Set of available commands is
machine-specific Constraints on codes (which
codes are allowed when) aremachine-specific
Performance of a command ismachine-specific
Writing machine code Cumbersome (small number of
directives) Error-prone Not portable
We need a more abstract program description (programming language).
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 16 of 27
The Speaker The Course Introduction Development Workflow
Translation Concepts
Algorithm
Machine Code Intermediate 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
Introduction to C/C++, Tobias Weinzierl page 17 of 27
The Speaker The Course 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
Introduction to C/C++, Tobias Weinzierl page 18 of 27
The Speaker The Course 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
Introduction to C/C++, Tobias Weinzierl page 19 of 27
The Speaker The Course Introduction Development Workflow
History of C++
Bjarne Stroustrup
Software Crisis (80s) Complex systems, difficult to
maintain 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
Introduction to C/C++, Tobias Weinzierl page 20 of 27
The Speaker The Course Introduction Development Workflow
C++State of the Art?
Memory
ALU 21: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
Introduction to C/C++, Tobias Weinzierl page 21 of 27
The Speaker The Course Introduction Development Workflow
1.4. Development Workflow
Three Tools Coin Our Work
Editor (vi, Emacs) to write simple textfiles
Compiler (g++) invoked on thecommand line
Linker (g++) invoked on the commandline
1. Introduction
Introduction to C/C++, Tobias Weinzierl page 22 of 27
The Speaker The Course Introduction Development Workflow
If Programming Were Cooking . . .
Editor (vi, Emacs). . . 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
Introduction to C/C++, Tobias Weinzierl page 23 of 27
The Speaker The Course Introduction Development Workflow
If Programming Were Cooking . . .
Editor (vi, Emacs) 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
Introduction to C/C++, Tobias Weinzierl page 24 of 27
The Speaker The Course Introduction Development Workflow
If Programming Were Cooking . . .
Editor (vi, Emacs) Compiler (g++) Linker (g++)
. . . would take the individual dishesand combine them into a completemeal with several courses. It isinvoked by g++ filename1.ofilename2.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
Introduction to C/C++, Tobias Weinzierl page 25 of 27
The Speaker The Course 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
Introduction to C/C++, Tobias Weinzierl page 26 of 27
The Speaker The Course Introduction Development Workflow
Exercise
vi first-appl.cpp
# inc lude i n t main ( ) {s td : : cout