Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2016 2017 #1

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1634e4f
adding figure
cgravier Feb 23, 2016
ac9ffc0
add image
cgravier Feb 23, 2016
537eaf1
add image
cgravier Feb 23, 2016
f28cecf
Update README.md
cgravier Feb 23, 2016
e1fdf89
labs project structure
cgravier Feb 23, 2016
3aa9ff9
Merge branch '2015-2016' of https://github.com/telecom-se/hpp into 20…
cgravier Feb 23, 2016
3de6b2a
introduction
cgravier Feb 23, 2016
b2cdc9f
Updated README.md
cgravier Feb 25, 2016
e3de0a9
Updated README.md
cgravier Feb 25, 2016
069113e
Updated README.md
cgravier Feb 25, 2016
d9b52f7
Updated README.md
cgravier Feb 25, 2016
57dc5c6
Updated README.md
cgravier Feb 25, 2016
e4e38d4
illustration
cgravier Feb 25, 2016
ca80db3
illustration
cgravier Feb 25, 2016
d5d24c2
Update README.md
cgravier Mar 1, 2016
2c87c9c
Update README.md
cgravier Mar 1, 2016
d6c21e3
Update README.md
cgravier Mar 1, 2016
9b939c6
Update README.md
cgravier Mar 1, 2016
2c10207
Update README.md
cgravier Mar 1, 2016
b11b771
Update README.md
cgravier Mar 1, 2016
15dbef8
Update README.md
cgravier Mar 1, 2016
218e699
Update README.md
cgravier Mar 1, 2016
6fe6021
Update README.md
cgravier Mar 1, 2016
1a24bb9
Update README.md
cgravier Mar 1, 2016
761679a
Update README.md
Mar 14, 2016
5cc4420
Update README.md
cgravier Mar 21, 2016
cda108d
Update README.md
cgravier Mar 21, 2016
e606fe5
Update README.md
cgravier Mar 21, 2016
f19631e
Update README.md
cgravier Mar 21, 2016
398bc25
Update README.md
cgravier Mar 21, 2016
a871d17
Update README.md
cgravier Mar 21, 2016
e824bb5
Update README.md
cgravier Mar 21, 2016
eba58d7
Update README.md
cgravier Mar 21, 2016
fbd098b
Update README.md
cgravier Mar 21, 2016
00085dc
Update README.md
cgravier Mar 21, 2016
6a1af25
multithreading
Apr 27, 2016
01164ad
Update README.md
cgravier Mar 3, 2017
238527f
Sequential and random walks for arrays updated in Java
cgravier Mar 3, 2017
a2f4e85
typo
cgravier Mar 3, 2017
e4ad267
On linkedlist task with contiguous and non-contiguous memory layout f…
cgravier Mar 3, 2017
db26b2f
On automatic optimisations and SIMD
cgravier Mar 3, 2017
95a7ad2
Update README.md
cgravier Mar 3, 2017
e9cc102
Added branch prediction
cgravier Mar 6, 2017
3f974cf
Update README.md
cgravier Mar 6, 2017
e78e463
Plugging JMH session
cgravier Mar 6, 2017
ccc5b3f
Update README.md
cgravier Mar 6, 2017
fb7aaea
introduces and motivates benchmarking framework
cgravier Mar 6, 2017
56e9328
Update README.md
cgravier Mar 7, 2017
77f5cd0
Update README.md
Apr 19, 2017
33593d0
new MT TP
Apr 25, 2017
6d366ed
remove files
Apr 25, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ bin/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

./DS_STORE
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Module FISE2 - HPP 2015-2016
# Module FISE2 - HPP 2016-2017

## Introduction to this course

Expand All @@ -12,14 +12,14 @@ The first part (Mechanical Sympathy) will be offered in **C++**, while the latte

Following those two main course part, you will be invited to then experiment the thrill of high performance programming by trying to optimize an open source library, from a hand-picked list that we will provide to you (you will be able to choose between **C++** or **Java** library, in order to match your programming language tastes).

## Organsiation
## Organization

The two instructors for this course are (by order of appearance) :
- Christophe Gravier <[email protected]>
- Julien Subercaze <[email protected]>

The timeframe for the aforementionned activities is as provided by the following picture :

![](./resources/figures/organisation.png)
## Labs materials

[Mechanical sympathy](./lab1/README.md)
Expand All @@ -29,5 +29,3 @@ The timeframe for the aforementionned activities is as provided by the following
[Advanced multithreading](./lab3/README.md)

[Project instructions](./project/README.md)


341 changes: 341 additions & 0 deletions lab1/README.md

Large diffs are not rendered by default.

Binary file added multithreading/TD10-2017-2018-intro.pdf
Binary file not shown.
Binary file added multithreading/TD10-2017-2018.pdf
Binary file not shown.
26 changes: 26 additions & 0 deletions multithreading/code/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.tse.fise2.info4</groupId>
<artifactId>lab10</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Lab10 - Multithreading</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- Lorem Ipsum Generator -->
<dependency>
<groupId>de.sven-jacobs</groupId>
<artifactId>loremipsum</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.tse.fise2.info4.lab10.example;

public class Example1Thread1 implements Runnable {
int number;

public Example1Thread1(int number) {
super();
this.number = number;
}

@Override
public void run() {
int i = 0;
while (i < 5) {
System.out.println("Thread " + number);
i++;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fr.tse.fise2.info4.lab10.example;

public class Exemple1 {

/**
* @param args
*/
public static void main(String[] args) {
Example1Thread1 thread1 = new Example1Thread1(1);
Example1Thread1 thread2 = new Example1Thread1(2);
new Thread(thread1).start();
new Thread(thread2).start();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package fr.tse.fise2.info4.lab10.exercise1;

public class Counter {

int counter;

public Counter() {
this.counter = 0;
}

public void incrementCounter() {

int tmp = counter;
tmp++;
try {
Thread.sleep((long) (Math.random() * 50));
} catch (InterruptedException e) {
e.printStackTrace();
}
this.counter = tmp;

}

public int getCounter() {
return counter;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package fr.tse.fise2.info4.lab10.exercise1;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
* Exercise 1 : Synchronize a counter
*
* in this exercise, the {@link Counter} is not properly synchronized. Ten
* threads are trying to increment i ten times, therefore the expected results
* is 100.
*
* Dans cet exercice, le compteur (Class compteur) n'est pas synchronis�
* correctement. 10 threads tentent de l'incr�menter 10 fois chacun, le r�sultat
* attendu est donc 100.
*
* Cependant si vous ex�cutez ce programme vous n'obtiendrez pas ce r�sultat.
* Vous allez synchroniser ce programme de 3 mani�res diff�rentes
* <ol>
* <li>Utiliser le mot cl� synchronized pour r�soudre le probl�me</li>
* <li>Dans la classe compteur, utiliser des locks pour synchroniser</li>
* <li>Rechercher dans le package java.util.concurrent.atomic une classe
* permettant de r�aliser la synchonisation</li>
* </ol>
*
* @author Julien Subercaze
*
*/
public class Exercise1 {

/**
* @param args
*/
public static void main(String[] args) {
// Use a threadpool to manage multiple threads. Read doc for more
Counter counter = new Counter();
incrementCounterWithThreads(counter);
System.out.println("Counter value:" + counter.getCounter());
}

public static void incrementCounterWithThreads(Counter counter){
ExecutorService service = Executors.newFixedThreadPool(10);
// Start 10 threads that increments the counter
for (int i = 0; i < 10; i++) {
service.execute(new ThreadModifier(counter));
}
//Finish
shutdownAndAwaitTermination(service);
}

/**
* Good practice: code imported from Oracle example
*
* @param pool
*/
static void shutdownAndAwaitTermination(ExecutorService pool) {
pool.shutdown(); // Disable new tasks from being submitted
try {
// Wait a while for existing tasks to terminate
if (!pool.awaitTermination(60, TimeUnit.SECONDS)) {
pool.shutdownNow(); // Cancel currently executing tasks
// Wait a while for tasks to respond to being cancelled
if (!pool.awaitTermination(60, TimeUnit.SECONDS))
System.err.println("Pool did not terminate");
}
} catch (InterruptedException ie) {
// (Re-)Cancel if current thread also interrupted
pool.shutdownNow();
// Preserve interrupt status
Thread.currentThread().interrupt();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.tse.fise2.info4.lab10.exercise1;

public class ThreadModifier implements Runnable {

private Counter counter;

public ThreadModifier(Counter compteur) {
this.counter = compteur;
}

@Override
public void run() {
for (int i = 0; i < 10; i++) {
counter.incrementCounter();
try {
Thread.sleep((long) (Math.random() * 50));
} catch (InterruptedException e) {
e.printStackTrace();
}

}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fr.tse.fise2.info4.lab10.exercise2;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
* TODO Modify this class so that:
* <ul>
* <li>It counts the number of words in an application wide
* {@link AtomicInteger} shared among the {@link Consumer}</li>
* <li>Counts the occurrence of each word using an application wide
* {@link ConcurrentHashMap} shared among the {@link Consumer}</li>
* </ul>
*
*
*/
public class Consumer implements Runnable {

@Override
public void run() {

}

public int countWords(String sentence) {
// TODO complete
return -1;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package fr.tse.fise2.info4.lab10.exercise2;

import java.util.concurrent.BlockingQueue;

/**
* TODO complete this class as follows:
* <ol>
* <li>Constructor takes as parameter the number of sentences to generate and
* the {@link BlockingQueue} in which to write the sentences</li>
* <li>When {@link #run()} is called, the producer starts producing sentences in the queue</li>
* <li>You must keep track of the number of words generated</li>
*
* </ol>
*
*
*
*/
public class Producer implements Runnable {

@Override
public void run() {

}

/**
*
* @param words
* the number of words in the sentence
* @return the generated sentence
*/
public String generateSentence(int words) {
// Use the lorem ipsum generator
// Library already in the pom (see maven dependencies)
// Refer to the documentation : http://loremipsum.sourceforge.net/
// TODO complete this method
return null;
}

/**
*
* @return the number of words generated by the producer. If production is not finished throw an {@link IllegalStateException}
*/
public int generatedWords(){
//TODO complete this method
return -1;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fr.tse.fise2.info4.lab10.exercise1;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Test;

public class Exercise1Test {

@After
public void tearDown() throws Exception {
}

@Test
public void test() {
//Run the test multiple times, to reduce chances of 'lucky strike'
for (int i = 0; i < 10; i++) {
Counter counter = new Counter();
Exercise1.incrementCounterWithThreads(counter);
int expected = 100;
assertEquals(expected, counter.getCounter());
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.tse.fise2.info4.lab10.exercise2;

import static org.junit.Assert.*;

import org.junit.Test;

public class TestConsumer {

@Test
public void test() {
fail("Not yet implemented");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.tse.fise2.info4.lab10.exercise2;

import org.junit.Test;

public class TestExercise2 {

/**
* TODO Write a test that:
* <li>Creates a {@link Producer}, n {@link Consumer}s</li>
* <li>Asserts that the number of words produced by the {@link Producer} is the same as the one obtained from the {@link Consumer}s</li>
*/
@Test
public void test() {


}

}
Loading