0% found this document useful (0 votes)
42 views7 pages

Computational Physics

The document outlines essential tools for computational physics, including hardware components like CPUs, RAM, and GPUs, as well as software aspects such as operating systems and programming languages. It discusses the importance of choosing the right tools based on development time, computational efficiency, and memory requirements. Additionally, it highlights various programming languages commonly used in physics, such as C++, Fortran, Python, and MATLAB, along with their advantages and disadvantages.

Uploaded by

fatimakhadim066
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views7 pages

Computational Physics

The document outlines essential tools for computational physics, including hardware components like CPUs, RAM, and GPUs, as well as software aspects such as operating systems and programming languages. It discusses the importance of choosing the right tools based on development time, computational efficiency, and memory requirements. Additionally, it highlights various programming languages commonly used in physics, such as C++, Fortran, Python, and MATLAB, along with their advantages and disadvantages.

Uploaded by

fatimakhadim066
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Tools of 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

Computational Physics Computer science


Computing has become a central tool in physics! The basic ideas behind computational physics are hardware and
From R. Landau “Computational Physics” (2015) software independent
However, for solving a problem in hand one may need to consider
advantages and disadvantages various choices.

Critical or important
• Development time
• Computational time

• Computational memory (RAM)

• Storage memory

• Physics: methods for computer simulations


Use right tools for your problem!
• Applied math: solving numerical problems

• Computer science: hardware and software (subject of this lecture)

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

• RAM -random-access memory (GB)


communication with CPU by bus

• GPU – Graphic Processor Unit (how many + how fast)


Can speed up calculations considerably!

• Network Interface (MB/GB per sec)

• HDD – Hard Disk Drive (TB)

7 8

Software
Principal parts

1. Operating system
2. Ideally IDE integrated development environment + language(s)
a) Editor

Part 3: b) Compiler(s) (for high-level languages)

c) Libraries (modules, toolboxes,...)


Software 3. Optional:
a) Lint and other static code analyzers
b) Debugger

c) Profilers
d) Report generators

9 10

Two major families UNIX family


1. Unix and Unix-like Developed in around 1970 in Bell Labs research center

a) Unix - commercial versions: AIX, HP-UX, Solaris, … 1. Powerful beyond imagination.

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.

2. Windows 4. Robust and small kernel.

5. Very safe: sandboxing and rich file permission system.

Share of operating systems for desktops/laptops 6. Plenty of tools


editors, programming languages, …

Philosophy of Unix/Linux: “Building blocks” + “glue”

• Building blocks: programs do only one thing, but do it well


Share of operating systems for clusters/supercomputers:
Linux now runs on all the fastest 500 supercomputers in the world • Glue: easy combine various blocks.

11 12

2
Windows
Generally available since 1992

1. Most popular OS in the world for personal computers and laptops.

2. The latest version is Windows 11.

Part 4:
Software: Programming languages

13 14

Programming languages Computer languages


Important questions Three basic modes to run a code

1. Which language to learn? 1. Interpreted: Python, Matlab, Mathematica, R.


2. Which language to use? 2. Compiled: Fortran, C/C++.
3. Do I need to learn new language(s)? 3. JIT (Just-in-Time) compilation: Julia
Most common in physics Interpreted languages can we used with:

• C and C++ (current standard C++20) 1. A command line

• Python 2. A script file.


• Fortran
• Matlab

• 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)

• Still widely used in science in engineering


weather forecast, nuclear weapon research and development, …

• Easy to learn, portable, nice array support, easy to parallelize

• Generally available on clusters and supercomputers

19 20

FORTRAN (formula translator) Python


Some disadvantages Designed by Guido von Rossum around 1991

• Small community of users • General purpose, multi-paradigm, interpreted language


• Most Fortran compilers are proprietary • Open source
• Intuitive – easy to learn
• Scientific computation modules: NumPy, SciPy, and SymPy

• Plotting modules: matplotlib and ggplot.

• Preinstalled on many systems (e.g. macOS)

21 22

Python MATLAB
Some disadvantages Started in the late 1970s, released commercially in 1984.

• Considerable time penalty https://www.mathworks.com/products/matlab.html

• Python’s memory usage is high • General purpose, multi-paradigm, interpreted language

• 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.

• Many useful toolboxes

• Great IDE (Integrated Development Environment)

• Interacts reasonably well with C/C++, Fortran, and R

Some disadvantages

• Can be expensive

• Tight integration with Java

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

• Mainly oriented toward symbolic computation

• Programming approach is different from other languages.


And more: C#, Javascript, PHP, Perl, Swift, Ruby, …

25 26

Summary C++ compilers and IDEs


Microsoft Visual C++ compiler
https://visualstudio.microsoft.com/vs/features/cplusplus/
• C++ good to learn (most powerful general programming language)
Windows (IDE included)
if you master C++ you can quickly learn anything else.
Xcode (from Apple)
• Fortran very powerful but learn only if needed (legacy codes or
https://developer.apple.com/xcode/
libraries)
macOS (IDE included)
• Python easy to learn, open source, but generally much slower than
C++ and Fortran Intel C++ compiler
www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compiler.html
• MATLAB easy to learn, convenient with great IDE, making graphs, Windows, macOS, Linux (works with Microsoft Visual Studio)
multiple toolboxes available
Dev-C++
• Mathematica good problem-solving environment but programming http://www.bloodshed.net
approach is different from other languages Windows (IDE included) (open source)
• Java – rather no, unless the use of Virtual machine is important

27 28

Fortran compilers and IDEs Python


ABSoft Python.org
https://www.absoft.com https://www.python.org
Windows, macOS, Linux (IDE included) Windows, macOS

NAG (Numerical Algorithmic Group) Anaconda


https://www.nag.com/content/nag-fortran-compiler https://www.anaconda.com/products/individual
Windows, macOS, Linux (IDE included) Windows, macOS

Intel Fortran compiler IDEs (for Windows, macOS and Linux)


www.intel.com/content/www/us/en/developer/tools/oneapi/fortran-compiler.html • IDLE https://docs.python.org/3/library/idle.html
Windows (IDE: Microsoft Visual Studio), macOS (IDE: Xcode), • Visual studio https://visualstudio.microsoft.com/vs/features/python/
Linux (IDE: Eclipse)
• Spyder https://www.spyder-ide.org
• Atom https://atom.io
Most clusters and supercomputers have Fortran!
• And many more …

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

Example: a circle using MATLAB Example: a circle using Python


% calculation: the diameter, circumference, and area # -*- coding: utf-8 -*-
% of a circle with a given radius """ From "COMPUTATIONAL PHYSICS" & "COMPUTER PROBLEMS in PHYSICS"
by RH Landau, et all."""
Pi = 3.1415926;
# Area.py: Area of a circle, simple program
prompt = 'Enter radius of a circle \n'; from math import pi
radius = input(prompt);
N = 1
diameter = 2.0*radius; r = 1.3
circumference = 2.0*Pi*radius; C = 2.* pi* r
area = pi*radius*radius; A = pi * r**2

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

Example: Fortran – Fibonacci prime numbers Other items


program fibonacci 1. Version Control
! the program generates Fibonacci numbers and chooses only prime numbers
! f(0) = 0
! f(1) = 1
2. Backups
! f(n) = f(n-1) + f(n-2) for n>1
implicit none 3. Dynamic notebooks (Jupiter, Markdown, …)
integer :: f(0:100)
integer :: i, j
character :: prime*5
f(0) = 0
f(1) = 1
do i=2,40
f(i) = f(i-1) + f(i-2)
! check for prime numbers
prime = 'prime'
do j=2,f(i)-1
if (f(i) == (f(i)/j)*j) then
prime = ' '
exit
end if
end do
write (*,102) i, f(i), prime
end do
102 format(i3, i12, a6)
stop
end

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:

• Multi-core/many-core CPUs (in a single machine or networked).

• Many-core coprocessors.
Part 4b:
• GPUs (graphics processing units).
High Performance Computing (HPC) • TPUs (tensor processing units).
• FPGAs (field-programmable gate arrays)

“Amateurs talk about the speed of their processors, but professionals


study coding techniques” from Gen. Robert H. Barrow, USMC (27th
Commandant of the US Marine Corps)

37 38

High-performance computing (HPC)


Resources

• Livermore National Lab https://hpc.llnl.gov/training/


• HPC carpentry https://www.hpc-carpentry.org
• More https://pages.tacc.utexas.edu/~eijkhout/istc/istc.html
• …
Part 5:
And many books
Libraries

39 40

You should not reinvent the wheel Few quotes


“Spend your intellectual energies on the current problem - not on fancy
§ Computational Physics Libraries
tools. When the volume and sophistication of your problems demand
§ Numerical Libraries and Depositories these weapons you will know it. That is the time to learn a new tool -
and learn it by re-doing an already-solved problem, not a new one.”
§ Large packages (example: the COMSOL Multiphysics)
F.S. Acton

"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

You might also like