Computational Physics
Computational Physics
A. Godunov Part 1:
1. Major tools of computational physics Major parts
2. Hardware
3. Software
4. Programming languages
5. Libraries (numerical, plotting, codes)
1 2
Critical or important
• Development time
• Computational time
• Storage memory
3 4
Hardware 1.
Desktop or
Laptop
Part 2:
Tools: Hardware
5 6
1
Internal hardware Top 500
Most important for computing The TOP500 lists the 500 most powerful commercially available
computer systems https://top500.org
• CPU(s) - central processing unit (how many + how fast)
also - cache memory: cache 1, cache 2
7 8
Software
Principal parts
1. Operating system
2. Ideally IDE integrated development environment + language(s)
a) Editor
c) Profilers
d) Report generators
9 10
b) Apple - macOS 2. ALL the Top 500 supercomputers in the world run on Linux.
c) Linux – many distributions 3. Linus is based on Unix. macOS is based on Unix.
11 12
2
Windows
Generally available since 1992
Part 4:
Software: Programming languages
13 14
• Julia
• R
15 16
C C++
Created in the early 1970s by Dennis Ritchie at Bell Labs, Developed by Bjarne Stroustrup at Bells Labs in the early 1980s
• General purpose, multi-paradigm, compiled language • General purpose, multi-paradigm, compiled language
• By design, C's features reflect the capabilities of the targeted CPUs • C/C++ is the infrastructure of much of the modern computing world.
• It was designed to be compiled to provide low-level access to • Powerful language: you can code anything in C++
memory and language constructs that map efficiently to machine • Easy integration with multiprocessor programming
instructions
OpenMP, MPI, CUDA, OpenCL, ...
• The language was primary design for writing operating systems
• If you know Unix/Linux and C/C++, you can master everything else
• Many languages have based directly or indirectly on C, including • Excellent compilers (including open-source) and tools.
C++, C#, Java, JavaScript, Julia, Perl, PHP, Python, Ruby, Swift, …
• Top performance in terms of speed.
17 18
3
C++ FORTRAN (formula translator)
Some disadvantages Grandfather of all modern languages – developed in 1957 (IBM)
• It was not designed for scientific calculations! At the beginning almost all computing was for physicists!
• Hard language to learn, even harder to master • General purpose, multi-paradigm, compiled language
• Large specification: C++20 (This causes, at times, portability issues) • Last version Fortran 2018
• Matrix indexing starts at zero • Lot of high-quality libraries (both numerical and applications)
19 20
21 22
Python MATLAB
Some disadvantages Started in the late 1970s, released commercially in 1984.
• Python’s functional programming can be difficult to read • Widely used in engineering and industry
• Runtime Errors: One of the major drawbacks of this language is that • Plenty of codes around
its design has numerous issues for science, engineering and economics.
Some disadvantages
• Can be expensive
23 24
4
Other languages Compare times of calculation …
Julia Results depends on a model/test but here are some average numbers
• Modern, high-performance programming language designed for C++ 1.00
scientific computation and data manipulation. Fortran 0.90
• Designed for parallelism and cloud computing. Syntax close to Python 50.0
Matlab. However, at early stages of life (can be unstable) Matlab 10.0
Mathematica from 4.0 to 900
R
Julia 3.0
• High level, open-source language for statistical computation R 250
• Widely used for big data, easy to parallelize
Mathematica
25 26
27 28
29 30
5
Books … so many Example: a circle using C++
bb // calculation: the diameter, circumference, and area of a circle
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
const double pi=3.1415926;
double radius, diameter, circumference, area;
cout << "enter radius as float " << endl;
cin >> radius;
diameter = 2.0*radius;
circumference = 2.0*pi*radius;
area = pi*pow(radius,2);
cout.setf(ios::fixed | ios::showpoint);
cout.width(10);
cout.precision(5);
cout << "radius = " << radius << endl;
cout << "diameter = " << diameter << endl;
cout << "circumf. = " << circumference << endl;
cout << "area = " << area << endl;
return 0;
}
31 32
fprintf(' radius %8.4f \n',radius); print ('Program number =', N, '\n r, C, A = ', r, C, A)
fprintf(' diameter %8.4f \n',diameter);
fprintf(' circumference %8.4f \n',circumference);
fprintf(' area %8.4f \n',area);
%end
33 34
35 36
6
High-performance computing (HPC)
Deals with scientific problems that require substantial computational
power.
Usually, but not always, HPC involves the use of several processors:
• Many-core coprocessors.
Part 4b:
• GPUs (graphics processing units).
High Performance Computing (HPC) • TPUs (tensor processing units).
• FPGAs (field-programmable gate arrays)
37 38
39 40
"I realized that a large part of my life from then on was going to be
www.odu.edu/~agodunov/computing/lib_net.html spent in finding mistakes in my own programs.”
Maurice Wilkes, after the first attempts to write programs for the
Note 1: do not use routines as black boxes without understanding EDSAC computer
Note 2: Collect you own library! "I conclude that there are two ways of constructing a software design:
One way is to make it so simple that there are obviously no deficiencies
and the other way is to make it so complicated that there are no
obvious deficiencies.”
Charles Hoare, inventor of the QuickSort algorithm, in his 1990 ACM
Turing Award Lecture
41 42