physics 2660: fundamentals of scientific...

40
Physics 2660: Fundamentals of Scientific Computing Lecture 1 Instructor: Prof. Chris Neu ([email protected])

Upload: others

Post on 03-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Physics 2660: Fundamentals of Scientific Computing

Lecture 1 Instructor: Prof. Chris Neu ([email protected])

Page 2: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Assessment

2

0

2

4

6

8

10

12

14

0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100

Num

bero

fstude

nts

Score[%]

Assessment-Mul7pleChoice

Page 3: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Assessment

3

0

10

20

30

40

50

60

70

80

90

100

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

CorrectPercentage[%

]

Ques7onNumber

Ques7on-by-Ques7onAnalysis

Page 4: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Assessment

4

0

10

20

30

40

50

60

70

80

90

100

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

CorrectPercentage[%

]

Ques7onNumber

Ques7on-by-Ques7onAnalysis

General/Computers Linux Elements of C

Page 5: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Announcements

•  Weekly readings will be assigned and available through the class wiki home page

•  HW01 will be assigned there as well–  Will be assigned on Thursday this week after labs–  Due Thursday 1 February

•  Electronic submission: by 12:00 noon EST

•  This week: Lab01–  Will be posted on Thursday

•  Office hours: all held in our computer lab, room 022-C of this bldg–  Me: After lecture 3:30-4:30 every Tuesday–  TAs:

•  Mondays: 3-5pm and 6-8pm•  Wednesdays: 5-9pm

5

No office hours this week!

Page 6: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Computers

6

Page 7: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Computer Hardware

7

CPUand cache

PCIe Bus(for graphics card)

Peripherals(keyboard, mouse) Hard drive / disk

Memory(aka RAM)

Northbridge(aka front side bus, MCH)

Southbridge(aka back side bus, ICH)

fast

fast fast

slowslow

slow

“ICH” = I/O controller hub

“MCH” = memory controller hub

Page 8: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Computer Hardware

•  Since the advent of the personal computer (PC) in the early 80s, the architecture has not changed much:–  Central Processing Unit (CPU): does the computer’s actual work

–  Northbridge / Southbridge: middlemen, handling fast and slow input/output and inter-component communications

–  Memory: temporary storage of data needed rapidly when running programs

–  Hard drive / disk: permanent, long-term storage of data

–  Input devices: enables interaction with users

–  Graphics card: middleman to allow for visual output to be displayed

8

Page 9: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Disk, Memory and Cache

•  These are confusing to many computing newcomers

•  Disk: large capacity, slow access•  Memory: reasonable capacity,

fast access•  Cache: meager capacity, really

fast access (internal to CPU)

–  Computers are designed to predict what data from the disk one needs when running a program. This is stored in memory.

–  Similar prediction game is played when pu^ing select important data into the cache.

9

Page 10: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

How a Program Runs

•  Users write programs in some human-readable language–  Ex: C, C++, java, FORTAN, etc.

•  Problem: CPUs don’t speak any human readable language!•  Compiler translates into low-level instructions for the CPU

10

•  CPU gets ordered instructions from memory

•  Location in memory stored in a register on CPU

•  CPU executes instructions in number order and moves on

CPUs are all different, depending on manufacturer and specifications

èinstructions need to be matched to CPU.

Different compilers are necessary for different computers. Not an issue on galileo.

Page 11: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

CPUs

•  The story behind the CPU is rich and interesting in its own right

•  We will not get deep into it here and now

•  There have been many different CPU architectures over the years

•  Two most prominent modern examples:–  x86-32 (aka i386 or x86): 32-bit CPUs

made by Intel and AMD (declining utility)

–  x86-64: 64-bit CPUs made by AMD and Intel

•  Multicore processors–  Multiple CPUs (cores) in one motherboard

11

Page 12: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

GPUs

•  Graphical Processing Units:–  lots of effort put in to making

graphics processors that execute commands really fast!

–  Gamers: anyone enjoy a time lag between pressing a bu^on and the visualization of the action taking place? NO.

–  Fast processors can also execute non-graphics commands quickly tooHighly-parallelizedcomputing on GPUsis the new paradigm.

12

h^p://www.nvidia.com/docs/IO/143716/how-gpu-acceleration-works.png

Page 13: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Operating Systems and Linux

13

Page 14: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

What is an Operating System?

•  Beyond the hardware, we need some management structure to tie all the pieces together–  This is the role of the operating system

•  Functions: many handled by the kernel

–  middleman for handling I/O–  middleman for handling memory allocation–  order of execution of processes–  parallelization of processes–  handling of network information

•  Every standard computer has some sort of operating system

•  Examples: Windows, Mac OS X, Android, iOS, Linux…14

h^p://upload.wikimedia.org/wikipedia/commons/e/e1/Operating_system_placement.svg

Page 15: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

What is an Operating System?

15

h^ps://www.cs.bgu.ac.il/~spl151/wiki.files/1.PNG

h^p://m.eet.com/media/1180999/f9-4.jpg

API: Application Programming Interface:A set of rules, definitions, protocols, and tools easing communication between pieces of softwareallows you to write programs aka “apps”

Kernel is a big part of any OS!We will not develop / change the kernel or the API or write device drivers or change the design of the filesystem or any of that…. but you could.

Example: Linux

Page 16: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

What is Linux?

•  Linux is an operating system borne out of the desire to have a freely available computer programming environment–  In the early days of computing, many saw the need to ensure freely

open software – proprietary nature of some software was very off-pu^ing to many developers

–  Many tools existed (see the GNU project) that were “open-source” –  Linus Torvalds in 1991 wrote an operating system+kernel and

brought together these disparate pieces…and Linux was born

•  Features:–  can run programs for any purpose (no usage restrictions) –  can edit programs (open source)–  can redistribute without oversight

•  Rich interesting history starting from Unix, on to GNU and eventually Linux

16

late 60s 70s-80s

90s

Page 17: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

What is Linux?

•  Linux is an operating system borne out of the desire to have a freely available computer programming environment–  In the early days of computing, many saw the need to ensure freely

open software – proprietary nature of some software was very off-pu^ing to many developers

–  Many tools existed (see the GNU project) that were “open-source” –  Linus Torvalds in 1991 wrote an operating system+kernel and

brought together these disparate pieces…and Linux was born

•  Features:–  can run programs for any purpose (no usage restrictions) –  can edit programs (open source)–  can redistribute without oversight

•  Rich interesting history starting from Unix, on to GNU and eventually Linux

17

late 60s 70s-80s

90s

Page 18: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

What is Linux?

•  Linux is an operating system borne out of the desire to have a freely available computer programming environment–  In the early days of computing, many saw the need to ensure freely

open software – proprietary nature of some software was very off-pu^ing to many developers

–  Many tools existed (see the GNU project) that were “open-source” –  Linus Torvalds in 1991 wrote an operating system+kernel and

brought together these disparate pieces…and Linux was born

•  Features:–  can run programs for any purpose (no usage restrictions) –  can edit programs (open source)–  can redistribute without oversight

•  Rich interesting history starting from Unix, on to GNU and eventually Linux

18

Why a penguin?h^p://www.sjbaker.org/wiki/index.php?title=The_History_of_Tux_the_Linux_Penguin

late 60s 70s-80s

90s

Page 19: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Operating Systems

19

h^p://johnzpchut.com/wordpress/wp-content/uploads/2011/12/operating-systems-diagram.png

Page 20: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

The Shell

20

Two major types:–  Command line interface (CLI)–  Graphical user interface (GUI)

Page 21: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

The Command Line Interface•  More emphasis in Linux than in other OS’s in user-interactions

executed through the command line rather than through graphical user interface (GUI) than eg Windows

21

[phys2660@node5 ~]$ [phys2660@node5 ~]$ ls -lrttotal 9748drwxr-xr-x 4 phys2660 phys2660 4096 Feb 22 2007 libdrwxr-xr-x 4 phys2660 phys2660 4096 Apr 4 2007 localdrwxr-x--- 2 phys2660 phys2660 4096 Aug 10 2007 Desktopdrwxr-xr-x 11 phys2660 phys2660 4096 Mar 20 2008 usr

promptwrite

commands here

a command: running a program

output

Page 22: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Commands and Arguments

22

ccn4g@galileo /home/ccn4g] lsbtag/ Desktop/ mail/ phys2660_spring2012/ phys5630_fall2010/ public/ public_html/ ROOT_intro/ccn4g@galileo /home/ccn4g] ls -1btag/Desktop/mail/phys2660_spring2012/phys5630_fall2010/public/public_html/ROOT_intro/ccn4g@galileo /home/ccn4g] ls -lrttotal 32drwxr-x--- 2 ccn4g ccn4g 4096 Aug 10 2007 Desktop/drwx------ 2 ccn4g ccn4g 4096 Feb 15 2010 mail/drwxr-xr-x 2 ccn4g ccn4g 4096 Feb 16 2010 ROOT_intro/drwxr-xr-x 2 ccn4g ccn4g 4096 Feb 16 2010 btag/drwxr-xr-x 2 ccn4g ccn4g 4096 Aug 24 2010 public_html/drwxrwxrwx 2 ccn4g ccn4g 4096 Sep 19 2010 public/drwxr-xr-x 5 ccn4g ccn4g 4096 Sep 19 2010 phys5630_fall2010/drwxr-xr-x 3 ccn4g ccn4g 4096 Jan 23 14:46 phys2660_spring2012/

Look at the different output of the program ‘ls’ when passing

different arguments

Page 23: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Command Line Interface

•  Virtues of the command line:–  Can narrow results with wildcard expressions using “ * ”–  Text interactions are easily reproduced user-to-user or session-to-

session (command history) whereas it is more awkward to describe graphical interactions

–  Allow for aliasing commands to more familiar, user-defined choices–  Establishment of environment variables for convenient consistent

functions–  Graphical interactions are nice but typically of limited use–  Linux has graphical interfaces but they are inconsistent among

different Linux variants–  Not every computer has graphical tools installed, especially if it was

built for performance – but there will ~always be command-line interactions

–  Many simple things do not need a fancy graphical output (think ‘ls’ instead of Windows Explorer..)

23

Page 24: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Illustration of the Linux Filesystem

24

Page 25: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Navigating Filesystem and Special Directories

•  Think of the filesystem as a nested collection of folders, a user has a home location and a current location

•  How to tell your current location: pwd

•  Change to a different directory: cd

•  A user’s “home” directory:

25

[phys2660@node1 phys2660_spring2012]$ pwd/home/ccn4g/phys2660_spring2012

[phys2660@node1 phys2660_spring2012]$ lsprelab_01[phys2660@node1 phys2660_spring2012]$ cd prelab_01/[phys2660@node1 prelab_01]$

ccn4g@galileo /home/ccn4g/phys2660_spring2012] echo $HOME/home/ccn4g

Page 26: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

The PATH Environment Variable

26

ccn4g@galileo /home/ccn4g/phys2660_spring2012] echo $PATH/home/phys2660/usr/bin:.:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:.:/local/bin:/cluster/bin:/common/bin:/bin:/usr/bin:/usr/games:/usr/X11R6/bin:/usr/openwin/bin:/common/CERN/pro/bin:/common/lib/scilab/bin:/common/lib/LASSP/bin:/usr/NX/bin:/opt/real/RealPlayer

•  Typing commands = running a program•  Compiled version of program can be anywhere on the disk•  PATH variable tells your shell what locations within the

context of the filesystem to look for these executables

•  For instance, most common Linux commands reside under /bin or /usr/bin

Page 27: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Convenience: Command History

•  On galileo, one can use up arrow to access commands in your history

27

ccn4g@galileo /home/ccn4g/phys2660_spring2012] history 10 559 9:12 su phys2660 560 9:16 echo $HOME 561 9:16 ls 562 9:16 cd phys2660_spring2012/ 563 9:16 echo $HOME 564 9:19 echo $PATH 565 9:24 history 566 9:24 man history 567 9:24 history --help 568 9:24 history 10

Page 28: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Convenience: Manual Pages Within Linux

•  good programs have easy-to-read manual pages, called man pages. Use: man <commandname> 28

ccn4g@galileo /home/ccn4g/phys2660_spring2012] man lsLS(1) User CommandsNAME ls - list directory contents

SYNOPSIS ls [OPTION]... [FILE]...

DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort.

Mandatory arguments to long options are mandatory for short options too.

-a, --all do not ignore entries starting with .

-A, --almost-all do not list implied . and ..

Page 29: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Some Common Linux Commands

29

Page 30: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Editing Files

•  One of the main tasks you will do is edit human-readable files

•  Many tools available to you to do this:–  nano (you’ll use this in lab01)–  pico (similar to nano)–  nedit–  emacs (lab01)–  See this wiki page for some more discussion

30

Page 31: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Caution on Caps

31

Page 32: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Local vs. Remote Computing

32

Page 33: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Galileo: Where We Will Do Our Work

33

h_p://galileo.phys.virginia.edu/

Page 34: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Remote Shells

•  So far we have tacitly overlooked one key component:–  What if I am not si^ing in front of the specific computer / Linux

machine I want to work on?–  How do I establish a connection to that machine?–  Use the network!

•  Remote shell access:–  We will use a program called ssh

•  Secure Shell•  Replaced an old lovable program called telnet, which, in terms of

security, had more holes than swiss cheese! Totally Unencrypted•  Tip: Never ever type the command telnet or even consider typing it

–  FYI There is no ssh version for Windows by default but you can install a Windows version for free. See Software for home on the class home page.

34

Page 35: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Galileo: Where We Will Do Our Work

•  The computer / Linux “machine” where we will do all our work is in the physics department and goes by the name galileo

•  galileo is actually the head node of a cluster of computers running Linux

35

d-172-25-103-246 /Users/neu] ssh -Y -l ccn4g [email protected]'s password: Warning: No xauth data; using fake authentication data for X11 forwarding.Last login: Mon Jan 23 14:08:26 2012 from d-128-100-66.bootp.virginia.edu .cshrc sourced ccn4g@galileo /home/ccn4g]

Page 36: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

A Note on Our Computer Lab

36

Room 022 Room ??

Page 37: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

The Computers in the Lab

37

•  The desktop machines in our computer lab run Lubuntu v12.04, kernel v3.2.0-24-generic–  a “lightweight” Linux

operating system based on Ubuntu.

–  Ubuntu is a popular (most popular?) type of Linux OS distributions with its own desktop environment.

–  There are several such distributions popular in the community today, Ubuntu is just one

The actual nodes on galileo run a Linux distribution

called CentOS, release 5-11.The kernel is v 2.6.18-407.el5

Use ‘lsb_release –a’

Page 38: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Remote Graphics

38

•  X Server: running on your local computer

•  X Client: program to display graphics from any other program

•  Can be on different computers!

Page 39: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

Connecting to galileo from other locations/laptops

•  It would be nice to connect to galileo to do your work from say, your laptop while si^ing in the library for instance

•  Many hints on how to do this are located here: h^p://faculty.virginia.edu/comp-phys/phys2660/wiki/doku.php?id=software:sw_main

•  If you run Windows–  I recommend installing and using pu^y with Xming–  Another option for Windows: NXClient for speedier graphics

connections. See me if interested – might be be^er than pu^y+XMing

•  If you run Mac OS X–  ssh is installed but you still need an X Server to see graphics.

See ssh and X11 for Mac 39

Page 40: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/... · • More emphasis in Linux than in other OS’s in user-interactions executed

We’ll pick up from here next time.

Don’t forget lab on Thursday! See you then.

40