├── .gitignore
├── .pre-commit-config.yaml
├── Assignment1
├── Assignment1.iml
└── src
│ └── com
│ └── assignment
│ ├── part1
│ ├── Ball.java
│ ├── BallThread.java
│ ├── BounceFrame.java
│ ├── Main.java
│ ├── ObjectCanvas.java
│ ├── Pool.java
│ ├── Score.java
│ ├── ScoreListener.java
│ └── ScoreThread.java
│ ├── part2
│ ├── Control.java
│ ├── Main.java
│ ├── PrintThread1.java
│ └── PrintThread2.java
│ └── part3
│ ├── Counter.java
│ └── Main.java
├── Assignment2
├── Assignment2.iml
└── src
│ └── com
│ └── assignment
│ ├── Algorithm.java
│ ├── Main.java
│ ├── basic
│ └── BasicAlgorithm.java
│ ├── fox
│ ├── FoxAlgorithm.java
│ └── FoxAlgorithmThread.java
│ ├── striped
│ ├── StripedAlgorithm.java
│ ├── StripedAlgorithmCallable.java
│ ├── StripedAlgorithmCallable2.java
│ ├── StripedAlgorithmThread.java
│ └── StripedAlgorithmThread2.java
│ └── utils
│ └── Matrix.java
├── Assignment3
├── Assignment3.iml
└── src
│ └── com
│ └── assignment
│ ├── task1
│ ├── Bank.java
│ ├── Main.java
│ └── TransferThread.java
│ ├── task2
│ ├── Consumer.java
│ ├── Drop.java
│ ├── Main.java
│ └── Producer.java
│ └── task3
│ ├── Group.java
│ ├── Journal.java
│ ├── Main.java
│ └── Teacher.java
├── Assignment4
├── Assignment4.iml
├── out
│ └── production
│ │ └── Assignment4
│ │ ├── Assignment4.iml
│ │ ├── commonWords
│ │ ├── 1.txt
│ │ └── 2.txt
│ │ ├── keyWords
│ │ ├── 1.txt
│ │ ├── 2.txt
│ │ └── 3.txt
│ │ ├── resources
│ │ ├── commonWords
│ │ │ ├── 1.txt
│ │ │ └── 2.txt
│ │ ├── keyWords
│ │ │ ├── 1.txt
│ │ │ ├── 2.txt
│ │ │ └── 3.txt
│ │ └── text.txt
│ │ ├── src
│ │ └── com
│ │ │ └── assignment
│ │ │ ├── task1
│ │ │ ├── ForkJoinWordCount.java
│ │ │ ├── Main.java
│ │ │ ├── SimpleWordCount.java
│ │ │ └── TextLoader.java
│ │ │ ├── task2
│ │ │ ├── Algorithm.java
│ │ │ ├── Main.java
│ │ │ ├── basic
│ │ │ │ └── BasicAlgorithm.java
│ │ │ ├── fox
│ │ │ │ ├── FoxAlgorithm.java
│ │ │ │ └── FoxAlgorithmForkJoin.java
│ │ │ └── utils
│ │ │ │ └── Matrix.java
│ │ │ ├── task3
│ │ │ ├── Document.java
│ │ │ ├── DocumentSearchTask.java
│ │ │ ├── Folder.java
│ │ │ ├── FolderSearchTask.java
│ │ │ ├── Main.java
│ │ │ └── WordCounter.java
│ │ │ └── task4
│ │ │ ├── Document.java
│ │ │ ├── DocumentSearchTask.java
│ │ │ ├── Folder.java
│ │ │ ├── FolderSearchTask.java
│ │ │ ├── Main.java
│ │ │ └── WordCounter.java
│ │ └── text.txt
├── resources
│ ├── commonWords
│ │ ├── 1.txt
│ │ └── 2.txt
│ ├── keyWords
│ │ ├── 1.txt
│ │ ├── 2.txt
│ │ └── 3.txt
│ └── text.txt
└── src
│ └── com
│ └── assignment
│ ├── task1
│ ├── ForkJoinWordCount.java
│ ├── Main.java
│ ├── SimpleWordCount.java
│ └── TextLoader.java
│ ├── task2
│ ├── Algorithm.java
│ ├── Main.java
│ ├── basic
│ │ └── BasicAlgorithm.java
│ ├── fox
│ │ ├── FoxAlgorithm.java
│ │ └── FoxAlgorithmForkJoin.java
│ └── utils
│ │ └── Matrix.java
│ ├── task3
│ ├── Document.java
│ ├── DocumentSearchTask.java
│ ├── Folder.java
│ ├── FolderSearchTask.java
│ ├── Main.java
│ └── WordCounter.java
│ └── task4
│ ├── Document.java
│ ├── DocumentSearchTask.java
│ ├── Folder.java
│ ├── FolderSearchTask.java
│ ├── Main.java
│ └── WordCounter.java
├── Assignment5
├── Assignment5.iml
└── src
│ └── com
│ └── assignment
│ ├── Create.java
│ ├── Element.java
│ ├── FunRand.java
│ ├── Model.java
│ ├── Process.java
│ └── SimModel.java
├── Assignment6
├── CMakeLists.txt
├── Makefile
├── hostfile
└── src
│ ├── task1
│ └── main.cpp
│ └── task2
│ └── main.cpp
├── AssignmentsList.pdf
├── LICENSE
├── Makefile
├── README.md
└── mpj-examples
├── HelloWorldParallel.java
├── MatrixMul4.java
├── MatrixMul8.java
├── MultiplyMatrixToVector.java
├── MultiplyVectorToScalar.java
├── TestAllGather.java
├── TestAllGatherv.java
├── TestAllReduce.java
├── TestAllToAll.java
├── TestAllToAllv.java
├── TestBcast.java
├── TestCreateIntracomm.java
├── TestGather.java
├── TestGatherv.java
├── TestISendAndIRecv.java
├── TestProbe.java
├── TestReduce.java
├── TestReduceScatter.java
├── TestScan.java
├── TestScatter.java
├── TestScatterv.java
├── TestSendAndRecv.java
└── Transport.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | # idea files
26 | .idea
27 |
28 | # VScode
29 | .vscode
30 |
31 | # Prerequisites
32 | *.d
33 |
34 | # Compiled Object files
35 | *.slo
36 | *.lo
37 | *.o
38 | *.obj
39 |
40 | # Precompiled Headers
41 | *.gch
42 | *.pch
43 |
44 | # Compiled Dynamic libraries
45 | *.so
46 | *.dylib
47 | *.dll
48 |
49 | # Fortran module files
50 | *.mod
51 | *.smod
52 |
53 | # Compiled Static libraries
54 | *.lai
55 | *.la
56 | *.a
57 | *.lib
58 |
59 | # Executables
60 | *.exe
61 | *.out
62 | *.app
63 |
64 | # IntelliJ
65 | out/
66 |
67 | # CMake
68 | cmake-build-*/
69 |
70 | # os
71 | os
72 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | repos:
2 | - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
3 | rev: v1.6.1
4 | hooks:
5 | - id: pretty-format-java
6 | args: [--autofix]
7 | - id: pretty-format-yaml
8 | args: [--autofix, --indent, '2']
9 | - repo: https://github.com/bmorcos/pre-commit-hooks-cpp
10 | rev: master
11 | hooks:
12 | - id: clang-format
13 | - id: cppcheck
14 |
--------------------------------------------------------------------------------
/Assignment1/Assignment1.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part1/Ball.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part1;
2 |
3 | import java.awt.*;
4 | import java.awt.geom.Ellipse2D;
5 | import java.util.Random;
6 |
7 | class Ball {
8 | private final Component canvas;
9 | private static final int RADIUS = 10;
10 | private static final int DIAMETER = RADIUS * 2;
11 | private int x = 0;
12 | private int y = 0;
13 | private int dx = 2;
14 | private int dy = 2;
15 | private final Color color;
16 | public boolean isInPool = false;
17 |
18 | public Ball(Component c, Color color) {
19 | this.canvas = c;
20 | this.color = color;
21 |
22 | if (Math.random() < 0.5) {
23 | x = new Random().nextInt(this.canvas.getWidth());
24 | y = 0;
25 | } else {
26 | x = 0;
27 | y = new Random().nextInt(this.canvas.getHeight());
28 | }
29 | }
30 |
31 | public Ball(Component c, Color color, int x, int y) {
32 | this.canvas = c;
33 | this.color = color;
34 |
35 | this.x = x;
36 | this.y = y;
37 | }
38 |
39 | public static void f() {
40 | int a = 0;
41 | }
42 |
43 | public void draw(Graphics2D g2) {
44 | g2.setColor(this.color);
45 | g2.fill(new Ellipse2D.Double(x, y, DIAMETER, DIAMETER));
46 | }
47 |
48 | public void move() {
49 | x += dx;
50 | y += dy;
51 | if (x < 0) {
52 | x = 0;
53 | dx = -dx;
54 | }
55 | if (x + DIAMETER >= this.canvas.getWidth()) {
56 | x = this.canvas.getWidth() - DIAMETER;
57 | dx = -dx;
58 | }
59 |
60 | if (y < 0) {
61 | y = 0;
62 | dy = -dy;
63 | }
64 | if (y + DIAMETER >= this.canvas.getHeight()) {
65 | y = this.canvas.getHeight() - DIAMETER;
66 | dy = -dy;
67 | }
68 |
69 | this.canvas.revalidate();
70 | this.canvas.repaint();
71 | }
72 |
73 | public boolean isInPool(Pool pool) {
74 | double distance =
75 | Math.sqrt(Math.pow(pool.getX() - this.x, 2) + Math.pow(pool.getY() - this.y, 2));
76 |
77 | return distance + RADIUS < Pool.getRADIUS();
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part1/BallThread.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part1;
2 |
3 | import javax.swing.*;
4 |
5 | public class BallThread extends Thread {
6 | private final Ball ball;
7 | private int TIME = 10000;
8 |
9 | public BallThread(Ball ball) {
10 | this.ball = ball;
11 | }
12 |
13 | @Override
14 | public void run() {
15 | try {
16 | for (int i = 1; (i < TIME) & (!Thread.currentThread().isInterrupted()); i++) {
17 |
18 | ball.move();
19 |
20 | if (ball.isInPool) {
21 | // Thread.currentThread().interrupt();
22 | break;
23 | }
24 |
25 | System.out.println("Thread name = " + Thread.currentThread().getName());
26 | Thread.sleep(5);
27 | }
28 | } catch (InterruptedException ignored) {
29 | System.out.println("Thread " + Thread.currentThread().getName() + " was interrupted!");
30 | }
31 | }
32 |
33 | public void setTIME(int TIME) {
34 | this.TIME = TIME;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part1/BounceFrame.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part1;
2 |
3 | import java.awt.*;
4 | import java.awt.event.ActionEvent;
5 | import java.awt.event.ActionListener;
6 | import javax.swing.*;
7 |
8 | public class BounceFrame extends JFrame {
9 | private final ObjectCanvas canvas;
10 | private static final int N_BLUE_BALLS = 1000;
11 | private static final int N_RED_BALLS = 1;
12 | private static final int N_JOIN_EXPERIMENT = 10;
13 | public static final int WIDTH = 850;
14 | public static final int HEIGHT = 750;
15 |
16 | public BounceFrame() {
17 |
18 | this.setSize(WIDTH, HEIGHT);
19 | this.setTitle("Bounce program");
20 | this.canvas = new ObjectCanvas();
21 |
22 | Pool p1 = new Pool(canvas, Color.CYAN, 0, 0);
23 | canvas.add(p1);
24 | Pool p2 = new Pool(canvas, Color.CYAN, WIDTH, 0);
25 | canvas.add(p2);
26 | Pool p3 = new Pool(canvas, Color.CYAN, 0, HEIGHT - 100);
27 | canvas.add(p3);
28 | Pool p4 = new Pool(canvas, Color.CYAN, WIDTH, HEIGHT - 100);
29 | canvas.add(p4);
30 |
31 | System.out.println(
32 | new StringBuilder()
33 | .append("In Frame Thread name = ")
34 | .append(Thread.currentThread().getName())
35 | .toString());
36 |
37 | Container content = this.getContentPane();
38 | content.add(this.canvas, BorderLayout.CENTER);
39 |
40 | JPanel buttonPanel = new JPanel();
41 | buttonPanel.setBackground(Color.lightGray);
42 |
43 | JPanel labelPanel = new JPanel();
44 | labelPanel.setBackground(Color.lightGray);
45 |
46 | JButton buttonAddBlueBall = new JButton("Add blue ball");
47 | JButton buttonAddRedBall = new JButton("Add red ball");
48 | JButton buttonPriorityExperiment = new JButton("Red/Blue priority experiment");
49 | JButton buttonJoinExperiment = new JButton("Join experiment");
50 | JButton buttonStop = new JButton("Stop");
51 |
52 | JLabel labelScore = new JLabel("Score: " + Score.getScore());
53 | /*
54 | // also, we can use daemon thread
55 |
56 | ScoreThread scoreThreadad = new ScoreThread(labelScore);
57 | scoreThreadad.setDaemon(true);
58 | scoreThreadad.setPriority(Thread.MAX_PRIORITY);
59 | scoreThreadad.start();
60 | */
61 |
62 | Score.addListener(
63 | new ScoreListener() {
64 | @Override
65 | public void actionPerformed() {
66 | labelScore.setText("Score: " + Score.getScore());
67 | labelScore.repaint();
68 | }
69 | });
70 |
71 | buttonAddBlueBall.addActionListener(
72 | new ActionListener() {
73 | @Override
74 | public void actionPerformed(ActionEvent e) {
75 | Color color = Color.BLUE;
76 | createBall(color, Thread.NORM_PRIORITY);
77 | }
78 | });
79 |
80 | buttonAddRedBall.addActionListener(
81 | new ActionListener() {
82 | @Override
83 | public void actionPerformed(ActionEvent e) {
84 | Color color = Color.RED;
85 | createBall(color, Thread.NORM_PRIORITY);
86 | }
87 | });
88 |
89 | buttonPriorityExperiment.addActionListener(
90 | new ActionListener() {
91 | @Override
92 | public void actionPerformed(ActionEvent e) {
93 | createPriorityExperiment();
94 | }
95 | });
96 |
97 | buttonJoinExperiment.addActionListener(
98 | new ActionListener() {
99 | @Override
100 | public void actionPerformed(ActionEvent e) {
101 | Runnable updatePanel =
102 | new Runnable() {
103 | public void run() {
104 | createJoinExperiment();
105 | }
106 | };
107 | Thread t = new Thread(updatePanel);
108 | t.start();
109 | }
110 | });
111 |
112 | buttonStop.addActionListener(
113 | new ActionListener() {
114 | @Override
115 | public void actionPerformed(ActionEvent e) {
116 |
117 | System.exit(0);
118 | }
119 | });
120 |
121 | buttonPanel.add(buttonAddBlueBall);
122 | buttonPanel.add(buttonAddRedBall);
123 | buttonPanel.add(buttonPriorityExperiment);
124 | buttonPanel.add(buttonJoinExperiment);
125 | buttonPanel.add(buttonStop);
126 |
127 | labelPanel.add(labelScore);
128 |
129 | content.add(buttonPanel, BorderLayout.SOUTH);
130 | content.add(labelPanel, BorderLayout.NORTH);
131 | }
132 |
133 | private void createBall(Color color, int priority) {
134 | Ball b = new Ball(canvas, color);
135 | canvas.add(b);
136 |
137 | BallThread thread = new BallThread(b);
138 | thread.setPriority(priority);
139 | thread.start();
140 |
141 | System.out.println("Thread name = " + thread.getName());
142 | }
143 |
144 | private void createBall(Color color, int priority, int x, int y) {
145 | Ball b = new Ball(canvas, color, x, y);
146 | canvas.add(b);
147 |
148 | BallThread thread = new BallThread(b);
149 | thread.setPriority(priority);
150 | thread.start();
151 |
152 | System.out.println("Thread name = " + thread.getName());
153 | }
154 |
155 | private void createBall(Color color, int priority, int x, int y, int TIME) {
156 | Ball b = new Ball(canvas, color, x, y);
157 | canvas.add(b);
158 |
159 | BallThread thread = new BallThread(b);
160 | thread.setTIME(TIME);
161 | thread.setPriority(priority);
162 | thread.start();
163 |
164 | try {
165 | thread.join();
166 | } catch (InterruptedException e) {
167 | e.printStackTrace();
168 | }
169 |
170 | System.out.println("Thread name = " + thread.getName());
171 | }
172 |
173 | private void createPriorityExperiment() {
174 | Color color = Color.BLUE;
175 | for (int i = 0; i < N_BLUE_BALLS; i++) {
176 | createBall(color, 1, WIDTH / 2, HEIGHT / 2);
177 | }
178 |
179 | color = Color.RED;
180 | for (int i = 0; i < N_RED_BALLS; i++) {
181 | createBall(color, 10, WIDTH / 2, HEIGHT / 2);
182 | }
183 | }
184 |
185 | private void createJoinExperiment() {
186 | int TIME = 1000;
187 |
188 | for (int i = 0; i < N_JOIN_EXPERIMENT; i++) {
189 | Color color;
190 | if (i % 2 == 0) {
191 | color = Color.BLUE;
192 | } else {
193 | color = Color.RED;
194 | }
195 | createBall(color, Thread.MIN_PRIORITY, WIDTH / 2, HEIGHT / 2, TIME);
196 | }
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part1/Main.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part1;
2 |
3 | import javax.swing.*;
4 |
5 | public class Main {
6 |
7 | public static void main(String[] args) {
8 | BounceFrame frame = new BounceFrame();
9 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
10 |
11 | frame.setVisible(true);
12 | System.out.println("Thread name = " + Thread.currentThread().getName());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part1/ObjectCanvas.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part1;
2 |
3 | import java.awt.*;
4 | import java.util.ArrayList;
5 | import javax.swing.*;
6 |
7 | public class ObjectCanvas extends JPanel {
8 | private final ArrayList balls = new ArrayList<>();
9 | private final ArrayList pools = new ArrayList<>();
10 |
11 | public void add(Ball b) {
12 | this.balls.add(b);
13 | }
14 |
15 | public void add(Pool p) {
16 | this.pools.add(p);
17 | }
18 |
19 | public void remove(Ball b) {
20 | Score.increase();
21 | this.balls.remove(b);
22 | }
23 |
24 | @Override
25 | public void paintComponent(Graphics g) {
26 | super.paintComponent(g);
27 | Graphics2D g2 = (Graphics2D) g;
28 |
29 | try {
30 | for (Ball b : balls) {
31 | for (Pool p : pools) {
32 | if (b.isInPool(p)) {
33 | b.isInPool = true;
34 | remove(b);
35 | break;
36 | }
37 | }
38 | if (!b.isInPool) {
39 | b.draw(g2);
40 | }
41 | }
42 | } catch (Exception ignored) {
43 | }
44 |
45 | for (Pool p : pools) {
46 | p.draw(g2);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part1/Pool.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part1;
2 |
3 | import java.awt.*;
4 | import java.awt.geom.Ellipse2D;
5 |
6 | public class Pool {
7 | private final Component canvas;
8 | private static final int RADIUS = 40;
9 | private static final int DIAMETER = RADIUS * 2;
10 | private int x = 0;
11 | private int y = 0;
12 | private final Color color;
13 |
14 | public Pool(Component c, Color color) {
15 | this.canvas = c;
16 | this.color = color;
17 | }
18 |
19 | public Pool(Component c, Color color, int x, int y) {
20 | this.canvas = c;
21 | this.color = color;
22 | this.x = x;
23 | this.y = y;
24 | }
25 |
26 | public static void f() {
27 | int a = 0;
28 | }
29 |
30 | public void draw(Graphics2D g2) {
31 | g2.setColor(this.color);
32 | g2.fill(new Ellipse2D.Double(x - RADIUS, y - RADIUS, DIAMETER, DIAMETER));
33 | }
34 |
35 | public int getX() {
36 | return x;
37 | }
38 |
39 | public int getY() {
40 | return y;
41 | }
42 |
43 | public static int getRADIUS() {
44 | return RADIUS;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part1/Score.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part1;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class Score {
7 | private static int score = 0;
8 |
9 | private static final List listeners = new ArrayList();
10 |
11 | public static void addListener(ScoreListener toAdd) {
12 | listeners.add(toAdd);
13 | }
14 |
15 | public static void increase() {
16 | Score.score += 1;
17 |
18 | // Notify everybody that may be interested.
19 | for (ScoreListener hl : listeners) hl.actionPerformed();
20 | }
21 |
22 | public static int getScore() {
23 | return score;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part1/ScoreListener.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part1;
2 |
3 | public interface ScoreListener {
4 | void actionPerformed();
5 | }
6 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part1/ScoreThread.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part1;
2 |
3 | import javax.swing.*;
4 |
5 | public class ScoreThread extends Thread {
6 | private final JLabel label;
7 |
8 | public ScoreThread(JLabel label) {
9 | this.label = label;
10 | }
11 |
12 | @Override
13 | public void run() {
14 | System.out.println("Daemon thread name = " + Thread.currentThread().getName());
15 | while (!Thread.currentThread().isInterrupted()) {
16 | label.setText("Score: " + Score.getScore());
17 | label.repaint();
18 | try {
19 | Thread.sleep(5);
20 | } catch (InterruptedException ignored) {
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part2/Control.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part2;
2 |
3 | public class Control {
4 | public volatile boolean flag = false;
5 | }
6 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part2/Main.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part2;
2 |
3 | public class Main {
4 | public static void main(String[] args) throws InterruptedException {
5 | Runnable task1 =
6 | () -> {
7 | System.out.println("Part 5.1:");
8 | run51();
9 | };
10 | Thread taskThread1 = new Thread(task1);
11 | taskThread1.start();
12 | taskThread1.join();
13 |
14 | Thread.sleep(10);
15 |
16 | Runnable task2 =
17 | () -> {
18 | System.out.println("\nPart 5.2:");
19 | run52();
20 | };
21 | Thread taskThread2 = new Thread(task2);
22 | taskThread2.start();
23 | taskThread2.join();
24 | }
25 |
26 | public static void run51() {
27 | PrintThread1 p1 = new PrintThread1("-");
28 | PrintThread1 p2 = new PrintThread1("|");
29 |
30 | Thread t1 = new Thread(p1);
31 | Thread t2 = new Thread(p2);
32 |
33 | t1.start();
34 | t2.start();
35 | }
36 |
37 | public static void run52() {
38 | Control control = new Control();
39 | PrintThread2 p1 = new PrintThread2("-", control);
40 | PrintThread2 p2 = new PrintThread2("|", control);
41 |
42 | p1.start();
43 | p2.start();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part2/PrintThread1.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part2;
2 |
3 | public class PrintThread1 implements Runnable {
4 | private String text = "";
5 | private final int n_max = 500;
6 |
7 | public PrintThread1(String text) {
8 | this.text = text;
9 | }
10 |
11 | @Override
12 | public void run() {
13 | for (int i = 0; i < n_max; i++) {
14 | System.out.print(this.text);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part2/PrintThread2.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part2;
2 |
3 | public class PrintThread2 extends Thread {
4 | private String text = "";
5 | private final Control control;
6 | private final int n_max = 500;
7 |
8 | public PrintThread2(String text, Control control) {
9 | this.text = text;
10 | this.control = control;
11 | }
12 |
13 | @Override
14 | public void run() {
15 | synchronized (control) {
16 | for (int i = 0; i < n_max; i++) {
17 | while (control.flag && this.text.equals("-")) {
18 | try {
19 | control.wait();
20 | } catch (InterruptedException e) {
21 | e.printStackTrace();
22 | }
23 | }
24 |
25 | while (!control.flag && this.text.equals("|")) {
26 | try {
27 | control.wait();
28 | } catch (InterruptedException e) {
29 | e.printStackTrace();
30 | }
31 | }
32 |
33 | System.out.print(this.text);
34 | control.flag = !control.flag;
35 | control.notifyAll();
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part3/Counter.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part3;
2 |
3 | public class Counter {
4 | private int count = 0;
5 |
6 | public void incrementUnsynchronized() {
7 | count++;
8 | }
9 |
10 | public void decrementUnsynchronized() {
11 | count--;
12 | }
13 |
14 | public synchronized void incrementSynchronizedMethod() {
15 | count++;
16 | }
17 |
18 | public synchronized void decrementSynchronizedMethod() {
19 | count--;
20 | }
21 |
22 | public void incrementSynchronizedBlock() {
23 | synchronized (this) {
24 | count++;
25 | }
26 | }
27 |
28 | public void decrementSynchronizedBlock() {
29 | synchronized (this) {
30 | count--;
31 | }
32 | }
33 |
34 | public int getCount() {
35 | return count;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Assignment1/src/com/assignment/part3/Main.java:
--------------------------------------------------------------------------------
1 | package com.assignment.part3;
2 |
3 | import java.util.concurrent.locks.ReentrantLock;
4 |
5 | public class Main {
6 | public static void main(String[] args) throws InterruptedException {
7 | Counter counter1 = new Counter();
8 |
9 | Runnable part61 =
10 | () -> {
11 | run61(counter1);
12 | };
13 | Thread part61Thread = new Thread(part61);
14 |
15 | part61Thread.start();
16 | part61Thread.join();
17 |
18 | System.out.println("Counter for part 6.1 = " + counter1.getCount());
19 |
20 | Counter counter2 = new Counter();
21 |
22 | Runnable part62 =
23 | () -> {
24 | try {
25 | run62(counter2);
26 | } catch (InterruptedException e) {
27 | e.printStackTrace();
28 | }
29 | };
30 | Thread part62Thread = new Thread(part62);
31 |
32 | part62Thread.start();
33 | part62Thread.join();
34 |
35 | System.out.println("Counter for part 6.2 = " + counter2.getCount());
36 |
37 | Counter counter3 = new Counter();
38 |
39 | Runnable part63 =
40 | () -> {
41 | try {
42 | run63(counter3);
43 | } catch (InterruptedException e) {
44 | e.printStackTrace();
45 | }
46 | };
47 | Thread part63Thread = new Thread(part63);
48 |
49 | part63Thread.start();
50 | part63Thread.join();
51 |
52 | System.out.println("Counter for part 6.3 = " + counter3.getCount());
53 |
54 | Counter counter4 = new Counter();
55 |
56 | Runnable part64 =
57 | () -> {
58 | try {
59 | run64(counter4);
60 | } catch (InterruptedException e) {
61 | e.printStackTrace();
62 | }
63 | };
64 | Thread part64Thread = new Thread(part64);
65 |
66 | part64Thread.start();
67 | part64Thread.join();
68 |
69 | System.out.println("Counter for part 6.4 = " + counter4.getCount());
70 | }
71 |
72 | public static void run61(Counter counter) {
73 | int n_times = 1_000_000;
74 |
75 | Runnable task1 =
76 | () -> {
77 | for (int i = 0; i < n_times; i++) counter.incrementUnsynchronized();
78 | };
79 | Thread taskThread1 = new Thread(task1);
80 |
81 | Runnable task2 =
82 | () -> {
83 | for (int i = 0; i < n_times; i++) counter.decrementUnsynchronized();
84 | };
85 | Thread taskThread2 = new Thread(task2);
86 |
87 | taskThread1.start();
88 | taskThread2.start();
89 | }
90 |
91 | public static void run62(Counter counter) throws InterruptedException {
92 | int n_times = 1_000_000;
93 |
94 | Runnable task1 =
95 | () -> {
96 | for (int i = 0; i < n_times; i++) counter.incrementSynchronizedMethod();
97 | };
98 | Thread taskThread1 = new Thread(task1);
99 |
100 | Runnable task2 =
101 | () -> {
102 | for (int i = 0; i < n_times; i++) counter.decrementSynchronizedMethod();
103 | };
104 | Thread taskThread2 = new Thread(task2);
105 |
106 | taskThread1.start();
107 | taskThread2.start();
108 |
109 | taskThread1.join();
110 | taskThread2.join();
111 | }
112 |
113 | public static void run63(Counter counter) throws InterruptedException {
114 | int n_times = 1_000_000;
115 |
116 | Runnable task1 =
117 | () -> {
118 | for (int i = 0; i < n_times; i++) counter.incrementSynchronizedBlock();
119 | };
120 | Thread taskThread1 = new Thread(task1);
121 |
122 | Runnable task2 =
123 | () -> {
124 | for (int i = 0; i < n_times; i++) counter.decrementSynchronizedBlock();
125 | };
126 | Thread taskThread2 = new Thread(task2);
127 |
128 | taskThread1.start();
129 | taskThread2.start();
130 |
131 | taskThread1.join();
132 | taskThread2.join();
133 | }
134 |
135 | public static void run64(Counter counter) throws InterruptedException {
136 | int n_times = 1_000_000;
137 |
138 | ReentrantLock lock = new ReentrantLock();
139 |
140 | Runnable task1 =
141 | () -> {
142 | for (int i = 0; i < n_times; i++) {
143 | lock.lock();
144 | counter.incrementUnsynchronized();
145 | lock.unlock();
146 | }
147 | };
148 | Thread taskThread1 = new Thread(task1);
149 |
150 | Runnable task2 =
151 | () -> {
152 | for (int i = 0; i < n_times; i++) {
153 | lock.lock();
154 | counter.decrementUnsynchronized();
155 | lock.unlock();
156 | }
157 | };
158 | Thread taskThread2 = new Thread(task2);
159 |
160 | taskThread1.start();
161 | taskThread2.start();
162 |
163 | taskThread1.join();
164 | taskThread2.join();
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/Assignment2/Assignment2.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Assignment2/src/com/assignment/Algorithm.java:
--------------------------------------------------------------------------------
1 | package com.assignment;
2 |
3 | import com.assignment.utils.Matrix;
4 |
5 | public interface Algorithm {
6 | public Matrix multiply();
7 | }
8 |
--------------------------------------------------------------------------------
/Assignment2/src/com/assignment/Main.java:
--------------------------------------------------------------------------------
1 | package com.assignment;
2 |
3 | import com.assignment.basic.BasicAlgorithm;
4 | import com.assignment.fox.FoxAlgorithm;
5 | import com.assignment.striped.StripedAlgorithm;
6 | import com.assignment.utils.Matrix;
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.stream.Collectors;
11 |
12 | public class Main {
13 | public static void main(String[] args) {
14 | simpleRun(false);
15 | // threadNExperiment();
16 | // sizeMatrixExperiment();
17 | }
18 |
19 | public static void simpleRun(boolean printMatrices) {
20 | int sizeAxis0 = 2000;
21 | int sizeAxis1 = 2000;
22 |
23 | Matrix A = new Matrix(sizeAxis0, sizeAxis1);
24 | Matrix B = new Matrix(sizeAxis0, sizeAxis1);
25 |
26 | A.generateRandomMatrix();
27 | B.generateRandomMatrix();
28 |
29 | // A.matrix = new double[][] {{1.1, 1, 1}, {2, 2.1, 2}, {3, 3, 3}};
30 | // B.matrix = new double[][] {{1, 1, 1}, {2, 5, 2}, {3, 3, 3}};
31 |
32 | int nThread = Runtime.getRuntime().availableProcessors(); // sizeAxis0
33 |
34 | BasicAlgorithm ba = new BasicAlgorithm(A, B);
35 | StripedAlgorithm sa = new StripedAlgorithm(A, B, nThread);
36 | FoxAlgorithm fa = new FoxAlgorithm(A, B, nThread);
37 |
38 | long currTime = System.nanoTime();
39 | Matrix C = ba.multiply();
40 | currTime = System.nanoTime() - currTime;
41 |
42 | if (printMatrices) C.print();
43 |
44 | System.out.println("Time for Basic Algorithm: " + currTime / 1_000_000);
45 |
46 | currTime = System.nanoTime();
47 | C = sa.multiply();
48 | currTime = System.nanoTime() - currTime;
49 |
50 | if (printMatrices) C.print();
51 |
52 | System.out.println("Time for Striped Algorithm: " + currTime / 1_000_000);
53 |
54 | currTime = System.nanoTime();
55 | C = fa.multiply();
56 | currTime = System.nanoTime() - currTime;
57 |
58 | if (printMatrices) C.print();
59 |
60 | System.out.println("Time for Fox Algorithm: " + currTime / 1_000_000);
61 | System.out.println("\n");
62 | }
63 |
64 | public static void threadNExperiment() {
65 | int sizeAxis0 = 1000;
66 | int sizeAxis1 = 1000;
67 | int nExperiments = 3;
68 |
69 | int[] threadsNStriped = new int[] {5, 10, 50, 100, 500, 1000};
70 | int[] threadsNFox = new int[] {4, 5, 10, 25, 50, 75};
71 | Map timeResultStriped = new HashMap<>();
72 | Map timeResultFox = new HashMap<>();
73 |
74 | Matrix A = new Matrix(sizeAxis0, sizeAxis1);
75 | Matrix B = new Matrix(sizeAxis0, sizeAxis1);
76 |
77 | A.generateRandomMatrix();
78 | B.generateRandomMatrix();
79 |
80 | for (int nThread : threadsNStriped) {
81 | StripedAlgorithm sa = new StripedAlgorithm(A, B, nThread);
82 |
83 | long acc = 0;
84 | for (int i = 0; i < nExperiments; i++) {
85 | long currTime = System.nanoTime();
86 | Matrix C = sa.multiply();
87 | acc += System.nanoTime() - currTime;
88 | }
89 | acc /= nExperiments;
90 |
91 | timeResultStriped.put(nThread, acc / 1_000_000);
92 | }
93 |
94 | for (int nThread : threadsNFox) {
95 | FoxAlgorithm fa = new FoxAlgorithm(A, B, nThread);
96 |
97 | long acc = 0;
98 | for (int i = 0; i < nExperiments; i++) {
99 | long currTime = System.nanoTime();
100 | Matrix C = fa.multiply();
101 | acc += System.nanoTime() - currTime;
102 | }
103 | acc /= nExperiments;
104 |
105 | timeResultFox.put(nThread, acc / 1_000_000);
106 | }
107 |
108 | List keysStriped =
109 | timeResultStriped.keySet().stream().sorted().collect(Collectors.toList());
110 |
111 | System.out.println("**Number of threads experiment (Striped)**");
112 |
113 | System.out.printf("%30s", "Number of thread:");
114 | for (int key : keysStriped) {
115 | System.out.printf("%10d", key);
116 | System.out.print(" ");
117 | }
118 |
119 | System.out.println();
120 |
121 | System.out.printf("%30s", "Time:");
122 | for (int key : keysStriped) {
123 | System.out.printf("%10d", timeResultStriped.get(key));
124 | System.out.print(" ");
125 | }
126 | System.out.println("\n");
127 |
128 | List keysFox = timeResultFox.keySet().stream().sorted().collect(Collectors.toList());
129 |
130 | System.out.println("**Number of threads experiment (Fox)**");
131 |
132 | System.out.printf("%30s", "Number of thread:");
133 | for (int key : keysFox) {
134 | System.out.printf("%10d", key);
135 | System.out.print(" ");
136 | }
137 |
138 | System.out.println();
139 |
140 | System.out.printf("%30s", "Time:");
141 | for (int key : keysFox) {
142 | System.out.printf("%10d", timeResultFox.get(key));
143 | System.out.print(" ");
144 | }
145 | System.out.println("\n");
146 | }
147 |
148 | public static void sizeMatrixExperiment() {
149 | int nThread = Runtime.getRuntime().availableProcessors();
150 | int nExperiments = 3;
151 |
152 | int[] sizesArray = new int[] {10, 100, 500, 1000, 1500};
153 | Map timeResultStriped = new HashMap<>();
154 | Map timeResultFox = new HashMap<>();
155 |
156 | for (int size : sizesArray) {
157 | Matrix A = new Matrix(size, size);
158 | Matrix B = new Matrix(size, size);
159 |
160 | A.generateRandomMatrix();
161 | B.generateRandomMatrix();
162 |
163 | StripedAlgorithm sa = new StripedAlgorithm(A, B, nThread);
164 |
165 | long acc = 0;
166 | for (int i = 0; i < nExperiments; i++) {
167 | long currTime = System.nanoTime();
168 | Matrix C = sa.multiply();
169 | acc += System.nanoTime() - currTime;
170 | }
171 | acc /= nExperiments;
172 |
173 | timeResultStriped.put(size, acc / 1_000_000);
174 |
175 | FoxAlgorithm fa = new FoxAlgorithm(A, B, nThread);
176 |
177 | acc = 0;
178 | for (int i = 0; i < nExperiments; i++) {
179 | long currTime = System.nanoTime();
180 | Matrix C = fa.multiply();
181 | acc += System.nanoTime() - currTime;
182 | }
183 | acc /= nExperiments;
184 |
185 | timeResultFox.put(size, acc / 1_000_000);
186 | }
187 |
188 | List keys = timeResultStriped.keySet().stream().sorted().collect(Collectors.toList());
189 |
190 | System.out.println("**Size of matrix experiment**");
191 |
192 | System.out.printf("%30s", "Size of matrix:");
193 | for (int key : keys) {
194 | System.out.printf("%10d", key);
195 | System.out.print(" ");
196 | }
197 |
198 | System.out.println();
199 |
200 | System.out.printf("%30s", "Time for Striped:");
201 | for (int key : keys) {
202 | System.out.printf("%10d", timeResultStriped.get(key));
203 | System.out.print(" ");
204 | }
205 |
206 | System.out.println();
207 |
208 | System.out.printf("%30s", "Time for Fox:");
209 | for (int key : keys) {
210 | System.out.printf("%10d", timeResultFox.get(key));
211 | System.out.print(" ");
212 | }
213 |
214 | System.out.println("\n");
215 | }
216 | }
217 |
--------------------------------------------------------------------------------
/Assignment2/src/com/assignment/basic/BasicAlgorithm.java:
--------------------------------------------------------------------------------
1 | package com.assignment.basic;
2 |
3 | import com.assignment.Algorithm;
4 | import com.assignment.utils.Matrix;
5 |
6 | public class BasicAlgorithm implements Algorithm {
7 | Matrix A;
8 | Matrix B;
9 |
10 | public BasicAlgorithm(Matrix A, Matrix B) {
11 | this.A = A;
12 | this.B = B;
13 | }
14 |
15 | @Override
16 | public Matrix multiply() {
17 | Matrix C = new Matrix(A.getSizeAxis0(), B.getSizeAxis1());
18 |
19 | for (int i = 0; i < A.getSizeAxis0(); i++) {
20 | for (int j = 0; j < B.getSizeAxis1(); j++) {
21 | C.matrix[i][j] = 0;
22 | for (int k = 0; k < A.getSizeAxis1(); k++) {
23 | C.matrix[i][j] += A.matrix[i][k] * B.matrix[k][j];
24 | }
25 | }
26 | }
27 | return C;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Assignment2/src/com/assignment/fox/FoxAlgorithm.java:
--------------------------------------------------------------------------------
1 | package com.assignment.fox;
2 |
3 | import com.assignment.Algorithm;
4 | import com.assignment.utils.Matrix;
5 | import java.util.ArrayList;
6 | import java.util.concurrent.ExecutionException;
7 | import java.util.concurrent.ExecutorService;
8 | import java.util.concurrent.Executors;
9 | import java.util.concurrent.Future;
10 |
11 | public class FoxAlgorithm implements Algorithm {
12 | Matrix A;
13 | Matrix B;
14 | private int nThread;
15 |
16 | public FoxAlgorithm(Matrix A, Matrix B, int nThread) {
17 | this.A = A;
18 | this.B = B;
19 | this.nThread = nThread;
20 | }
21 |
22 | private int findNearestDivider(int s, int p) {
23 | /*
24 | https://ru.stackoverflow.com/questions/434403/%D0%9F%D0%BE%D0%B8%D1%81%D0%BA-%D0%B1%D0%BB%D0%B8%D0%B6%D0%B0%D0%B9%D1%88%D0%B5%D0%B3%D0%BE-%D0%B4%D0%B5%D0%BB%D0%B8%D1%82%D0%B5%D0%BB%D1%8F
25 | */
26 | int i = s;
27 | while (i > 1) {
28 | if (p % i == 0) break;
29 | if (i >= s) {
30 | i++;
31 | } else {
32 | i--;
33 | }
34 | if (i > Math.sqrt(p)) i = Math.min(s, p / s) - 1;
35 | }
36 |
37 | return i >= s ? i : i != 0 ? p / i : p;
38 | }
39 |
40 | @Override
41 | public Matrix multiply() {
42 | Matrix C = new Matrix(A.getSizeAxis0(), B.getSizeAxis1());
43 |
44 | if (!(A.getSizeAxis0() == A.getSizeAxis1()
45 | & B.getSizeAxis0() == B.getSizeAxis1()
46 | & A.getSizeAxis0() == B.getSizeAxis0())) {
47 | try {
48 | throw new Exception("Matrix A and B have different dimensions!");
49 | } catch (Exception e) {
50 | e.printStackTrace();
51 | System.exit(-1);
52 | }
53 | }
54 |
55 | this.nThread = Math.min(this.nThread, A.getSizeAxis0());
56 | this.nThread = findNearestDivider(this.nThread, A.getSizeAxis0());
57 | int step = A.getSizeAxis0() / this.nThread;
58 |
59 | ExecutorService exec = Executors.newFixedThreadPool(this.nThread);
60 | ArrayList threads = new ArrayList<>();
61 |
62 | int[][] matrixOfSizesI = new int[nThread][nThread];
63 | int[][] matrixOfSizesJ = new int[nThread][nThread];
64 |
65 | int stepI = 0;
66 | for (int i = 0; i < nThread; i++) {
67 | int stepJ = 0;
68 | for (int j = 0; j < nThread; j++) {
69 | matrixOfSizesI[i][j] = stepI;
70 | matrixOfSizesJ[i][j] = stepJ;
71 | stepJ += step;
72 | }
73 | stepI += step;
74 | }
75 |
76 | for (int l = 0; l < nThread; l++) {
77 | for (int i = 0; i < nThread; i++) {
78 | for (int j = 0; j < nThread; j++) {
79 | int stepI0 = matrixOfSizesI[i][j];
80 | int stepJ0 = matrixOfSizesJ[i][j];
81 |
82 | int stepI1 = matrixOfSizesI[i][(i + l) % nThread];
83 | int stepJ1 = matrixOfSizesJ[i][(i + l) % nThread];
84 |
85 | int stepI2 = matrixOfSizesI[(i + l) % nThread][j];
86 | int stepJ2 = matrixOfSizesJ[(i + l) % nThread][j];
87 |
88 | FoxAlgorithmThread t =
89 | new FoxAlgorithmThread(
90 | copyBlock(A, stepI1, stepJ1, step),
91 | copyBlock(B, stepI2, stepJ2, step),
92 | C,
93 | stepI0,
94 | stepJ0);
95 | threads.add(exec.submit(t));
96 | }
97 | }
98 | }
99 |
100 | for (Future mapFuture : threads) {
101 | try {
102 | mapFuture.get();
103 | } catch (InterruptedException | ExecutionException e) {
104 | e.printStackTrace();
105 | }
106 | }
107 |
108 | exec.shutdown();
109 |
110 | return C;
111 | }
112 |
113 | private Matrix copyBlock(Matrix matrix, int i, int j, int size) {
114 | Matrix block = new Matrix(size, size);
115 | for (int k = 0; k < size; k++) {
116 | System.arraycopy(matrix.matrix[k + i], j, block.matrix[k], 0, size);
117 | }
118 | return block;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/Assignment2/src/com/assignment/fox/FoxAlgorithmThread.java:
--------------------------------------------------------------------------------
1 | package com.assignment.fox;
2 |
3 | import com.assignment.utils.Matrix;
4 |
5 | public class FoxAlgorithmThread extends Thread {
6 | private final Matrix A;
7 | private final Matrix B;
8 | private final Matrix C;
9 |
10 | private final int stepI;
11 | private final int stepJ;
12 |
13 | public FoxAlgorithmThread(Matrix A, Matrix B, Matrix C, int stepI, int stepJ) {
14 | this.A = A;
15 | this.B = B;
16 | this.C = C;
17 |
18 | this.stepI = stepI;
19 | this.stepJ = stepJ;
20 | }
21 |
22 | @Override
23 | public void run() {
24 | Matrix blockRes = multiplyBlock();
25 |
26 | for (int i = 0; i < blockRes.getSizeAxis0(); i++) {
27 | for (int j = 0; j < blockRes.getSizeAxis1(); j++) {
28 | C.matrix[i + stepI][j + stepJ] += blockRes.matrix[i][j];
29 | }
30 | }
31 | // System.out.println(Thread.currentThread().getName());
32 | }
33 |
34 | private Matrix multiplyBlock() {
35 | Matrix blockRes = new Matrix(A.getSizeAxis1(), B.getSizeAxis0());
36 | for (int i = 0; i < A.getSizeAxis0(); i++) {
37 | for (int j = 0; j < B.getSizeAxis1(); j++) {
38 | for (int k = 0; k < A.getSizeAxis1(); k++) {
39 | blockRes.matrix[i][j] += A.matrix[i][k] * B.matrix[k][j];
40 | }
41 | }
42 | }
43 | return blockRes;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Assignment2/src/com/assignment/striped/StripedAlgorithm.java:
--------------------------------------------------------------------------------
1 | package com.assignment.striped;
2 |
3 | import com.assignment.*;
4 | import com.assignment.utils.Matrix;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 | import java.util.Map;
8 | import java.util.concurrent.*;
9 |
10 | public class StripedAlgorithm implements Algorithm {
11 | Matrix A;
12 | Matrix B;
13 | private final int nThread;
14 |
15 | public StripedAlgorithm(Matrix A, Matrix B, int nThread) {
16 | this.A = A;
17 | this.B = B;
18 | this.nThread = nThread;
19 | }
20 |
21 | @Override
22 | public Matrix multiply() {
23 | Matrix C = new Matrix(A.getSizeAxis0(), B.getSizeAxis1());
24 |
25 | C = version1(C);
26 | // C = version2(C);
27 | // C = version3(C);
28 | // C = version4(C);
29 |
30 | return C;
31 | }
32 |
33 | public Matrix version1(Matrix C) {
34 | B.transpose();
35 |
36 | ExecutorService executor = Executors.newFixedThreadPool(this.nThread);
37 |
38 | List>> list = new ArrayList<>();
39 |
40 | for (int j = 0; j < B.getSizeAxis0(); j++) {
41 | for (int i = 0; i < A.getSizeAxis0(); i++) {
42 | Callable