Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel...

47
Parallel Systems: Introduction Informatica les 1 Java versus Python Jan Lemeire Informatica 2 e semester februari – mei 2017

Transcript of Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel...

Page 1: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Parallel Systems: Introduction

Informatica

les 1

Java versus Python

Jan Lemeire

Informatica 2e semester

februari – mei 2017

Page 2: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.
Page 3: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Parallel Systems: Introduction

Page 4: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Parallel Systems: Introduction

Gravitational waves are extremely weak

ripples of

speed of light. They were first detected on

September 14, 2015 by Advanced LIGO

(the Laser

wave Observatory).The origin of these

gravitational waves has been attributed to

the merger of two black holes, more than

1.3 billion years ago, with masses around

29 and 36 solar masses. This resulted in

the formation of a single more massive

black hole. About 3 solar masses were

converted into gravitational waves in the

last fraction of the second of the merger

which was then detected by LIGO. This is

also the first time that the collision of two

black holes has been observed.

September 14, 2015

Page 5: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

In faze

In tegenfaze

Superpositie van signalen

Page 6: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.
Page 7: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.
Page 8: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.
Page 9: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 9Pag. / 499

GPU vs CPU Peak Performance Trends

GPU peak performance has grown aggressively.

Hardware has kept up with Moore’s law

Source : NVIDIA

2010350 Million triangles/second3 Billion transistors GPU

19955.000 triangles/second800.000 transistors GPU

201614.000 Million triangles/second15 Billion transistors GPU

Page 10: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 10Pag. / 49Informatica II: les 4

Page 11: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 11Pag. / 49Informatica II: les 4

Page 12: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

The third pillar

of the scientific world:

computational science

Page 13: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 13Pag. / 4916/02/2017

13

Page 14: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Informatica = tool

Page 15: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 15Pag. / 49

Jan Lemeire ([email protected])

Burgerlijk ingenieur, 1994, VUB

+ bijkomende masters in de computerwetenschappen (1995)

Werkte 4 jaar in de privé, voor 2 IT-consultancybedrijven

2000-2007: doctoreerde aan de VUB als assistent

Gaf oefeningen informatica

Sinds 2008: professor aan VUB

Vak ‘parallel systems’ in de masters

Sinds 2011: titularis ‘Informatica’ eerste bachelors

Sinds oktober 2013: geeft ook les aan industrieel ingenieurs

Bachelors: Informatica en Basiselektronica

Masters: Computerarchitectuur

Onderzoeksdomeinen: parallel & GPU computing & data mining/machine learning/probabilistische modellen

http://parallel.vub.ac.be

Page 16: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

+ Eerste semester

Variabelen

Gebruiken van lijsten

Maken van een while-lus

Maken van een eigen functie

Recursie

Maken van een for-lus

Algoritmes

Python: procedureel programmeren

Page 17: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Zonder voorkennis

Evaluatie Informatica IR

Page 18: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Beheers het gebruik van bibliotheken:• Programmeervaardigheden• Klassestructuur• Voorbeelden• Documentatie

Basis-programmeervaardigheden

While – forLijsten/arrays

FunctiesRecursie

Java & Object-georiënteerdprogrammeren

RegelsOrganisatie van de code

Gebruik klasses

AlgoritmenBasisalgoritmen

Slimme algoritmenSorteren

DatastructurenArrays – ArrayLists

Stack, Queue, Linked lists Trees - Maps

GUI-klassenJFrames – Jpanels – Jbuttons - …Events – Eventlisteners - mouse

Paint, layout, JApplet

CURSUS III: technologie, historiek

en economische aspecten

1e semester

PROJECT

Utility-klassenTimer, Thread, Random, File, …

CURSUS I

CURSUS II

Page 19: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 19Pag. / 49

2e semester

Cursustekst deel I

Cursustekst deel II

Verschillen met vorig jaar: op website

Cursustekst deel III

Slides: alles staat in cursus

Indien niet: staat duidelijk aangegeven

http://parallel.vub.ac.be:

Code & alle info

Informatica II: les 1

Page 20: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 20Pag. / 49

2e zit en vrijstellingen

Zie parallel.vub.ac.beMet een 10/20 gemiddeld over alle onderdelen ben je geslaagd, anders 2e zit.

Vanaf 12/20 heb je een officieuze vrijstelling voor een onderdeel (theorie/oefeningen/project) van 1e naar 2e zit.

In juni bieden we de mogelijkheid om facultatief je punten van het 1e semester te verbeteren, indien je een 7, 8 of 9 behaalde in het eerste semester (gemiddelde over theorie en oefeningen) en je slaagt voor je mondeling examen met minstens een 12/20.

Informatica II: les 1

Page 21: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 22Pag. / 49

Deel I

4 pagina’s referentie java

Java’s spelregels

Pijlers van object-georiënteerdeprogrammeertalen

Page 22: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 23Pag. / 49

TIOBE Index for June 2016

http://www.tiobe.com/tiobe_indexInformatica II: les 1

Page 23: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 24Pag. / 49

Java versus Python

1. Object-georiënteerde taal.

2. public static void main

3. Puntkomma’s en accolades

4. System.out.println

5. Typeren: sterk en statisch

6. Arrays en ArrayLists

7. Verschil tussen letters en woorden

8. De for-lus

9. VariaInformatica II: les 1

p. 8

Page 24: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 25Pag. / 49Informatica II: les 1

p. 9

Statements eindigen met ‘;’

Page 25: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 26Pag. / 49

Wat berekent GHI?”

Informatica II: les 1

p. 10

Page 26: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 27Pag. / 49

Hetzelfde in python

Informatica II: les 1

def berekenGHI(x, y):

while x != y:

if x > y:

x = x-y

else:

y = y-x

return x;

s = raw_input("Geef 2 getallen: ")

a = int(s)

s = raw_input()

b = int(s)

ggd = berekenGHI(a, b)

print “GGD van", a, "en", b, "is", ggd

p. 10

Page 27: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 28Pag. / 49

Getypeerde parameters

public static int berekenGrootstGemeneDeler(int x, int y)

Java: Enkel op te roepen met integers

In python: ook reëel getal mogelijk! Elk type, dus ook string…

– Parameters 4.5 & 5.5 werkt

– Parameters 4.5 en 5.1 werkt het niet => NOK

Informatica II: les 1

p. 12

Page 28: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 29Pag. / 49

Type checking nuttig

Je weet als gebruiker wat mee te gevenIn python: input documenteren

Geruststelling, je kan ‘niets fouts’ doenHier: negatieve waarden geeft fouten: checken

In Python: steeds extra checks doen op type

Parameters kunnen ingewikkelde objectenzijn

Informatica II: les 1

Page 29: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 30Pag. / 49

Functie: maar 1 teruggeefwaarde

Java, zoals de meeste programmeertalen

Functie

kan maar 1 waarde teruggeven

Voorbeeld: celsius-conversie, ggd

Indien meerdere waarden: ‘truken’ nodig

Informatica II: les 1

p. 16

Page 30: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 31Pag. / 49

Voorlopige conclusie

Python

Snel, voor kleine programma’s

High-level, handige basisfunctionaliteiten

Cf Matlab

Java

Voor grote programma’s en bibliotheken, te delen met andere programmeurs

Iets meer low-level

Meest-gebruikte industriële taal

Informatica II: les 1

Voorlopige conclusie

Page 31: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 32Pag. / 49

Java versus Python

1. Object-georiënteerde taal.

2. public static void main

3. Puntkomma’s en accolades

4. System.out.println

5. Typeren: sterk en statisch

6. Arrays en ArrayLists

7. Verschil tussen letters en woorden

8. De for-lus

9. VariaInformatica II: les 1

Page 32: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Objecten

Page 33: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 34Pag. / 49Informatica II: les 1

Persoon-object

p. 17

Page 34: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 35Pag. / 49Informatica II: les 1

p. 18

operator: … ? ... : … p. 16

Page 35: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 36Pag. / 49

Persoonobjecten

Informatica II: les 1

p. 19

Page 36: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 37Pag. / 49

Objecten

Gedefinieerd met een klasse (type object)

Heeft attributen

De eigenschappen van het object

Aangemaakt met een constructor

Object is instantiatie van een welbepaalde klasse

Heeft methodes

Methode heeft toegang tot de attributen, kandeze veranderen

Informatica II: les 1

Page 37: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Overerving

Page 38: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 39Pag. / 49

Een student is een persoon

Informatica II: les 1

public class Student extends Persoon{

enum Faculteit {IR, WE, GF, LK, LW, ES, RC, PE};

int rolnummer;Faculteit faculteit = Faculteit.IR;

Student(String voornaam, String naam, int

rolnummer){

super(voornaam, naam);

this.rolnummer=rolnummer;

}}

p. 20

Page 39: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 40Pag. / 49

Overerving (inheritance)

Subklasse erft alle attributen en methodes over van moederklasse

Subklasse kan attributen toevoegen

Subklasse kan methodes toevoegen of methodesoverschrijven

Constructor van subklasse moet een constructor van moederklasse oproepen (superconstructor)

Informatica II: les 1

p. 5 – regel 6

Page 40: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 41Pag. / 49

Specializatie

Overerving (Inheritance): hiërarchie

Vehicle

Car

Truck

Racing

Car

Light

Vehicle

Heavy

Vehicle

Bus

Generalizatie

Page 41: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 42Pag. / 49

Pijlers van object-georiënteerde

programmeertalen

p. 7

Page 42: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 43Pag. / 49

Super-constructor

Het aanmaken van een Student-object vergt ook het aanmaken van een Persoon-object

Op de eerste lijn van de Student-constructor roep je een constructor van Persoon op met super(voornaam, naam);

Informatica II: les 1

Page 43: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Objectattributen

Page 44: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 45Pag. / 49Informatica II: les 1

p. 21

Page 45: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 47Pag. / 49Informatica II: les 1

public class Student extends Persoon{

enum Faculteit {IR, WE, GF, LK, LW, ES, RC, PE};

int rolnummer;Faculteit faculteit = Faculteit.IR;ArrayList<Vak> vakken;Map<Vak, Integer> punten;float score;

Student(String voornaam, String naam, int rolnummer, Faculteit fac){super(voornaam, naam);this.rolnummer=rolnummer;this.faculteit = fac;vakken = new ArrayList<Vak>();punten = new HashMap<Vak, Integer>();

}}public class Vak {

String naam, titularis;

int SP;

Vak(String naam, String titularis, int SP){

this.naam = naam;

this.titularis = titularis;

this.SP = SP;

}}

Page 46: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 48Pag. / 49

Aanmaken objecten

Informatica II: les 1

public static void main(String[] args) {

Student rik = new Student("Rik", "Vermeulen", 37365, Faculteit.IR);Student jana = new Student("Jana", "Laplace", 101670, Faculteit.WE);

Vak informatica = new Vak("Informatica", "Jan Lemeire", 7);Vak materiaalkunde = new Vak("Materiaalkunde", "Herman Terryn", 4);Vak mechanica = new Vak("Mechanica", "Dirk Lefeber", 7);

rik.vakken.add(informatica);rik.punten.put(informatica, 14);rik.vakken.add(materiaalkunde);rik.punten.put(materiaalkunde, 12);rik.vakken.add(mechanica);rik.punten.put(mechanica, 17);

jana.vakken.add(informatica);jana.punten.put(informatica, 16);jana.vakken.add(mechanica);jana.punten.put(mechanica, 13);

}

Page 47: Parallel Systems Introductionparallel.vub.ac.be/education/java/theorie/java HOC 1...Parallel Systems: Introduction Gravitational waves are extremely weak ripples of speed of light.

Jan Lemeire 49Pag. / 49

Berekening score

Informatica II: les 1

int berekenTotaal(){

score=0;int totaalSP=0;for(Vak vak: vakken){

score += punten.get(vak) * vak.SP;totaalSP += vak.SP;

}score /= totaalSP;return score;

}

for-lusp. 15-16

float scoreRik = rik.berekenTotaalScore();float scoreJana = jana.berekenTotaalScore();System.out.println(rik+" behaalde "+scoreRik+"/20");System.out.println(jana+" behaalde "+scoreJana+"/20");