Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * MatrixSys.java
- *
- * Created on 10 Ноябрь 2010 г., 16:19
- */
- package parallels.pipeline;
- import java.applet.*;
- import java.awt.*;
- import java.util.*;
- /**
- *
- * @author Student
- */
- interface DataSys {
- int n = 300;
- int s[] = new int[n];
- int a[][] = new int[n][n];
- int b[] = new int[n];
- long time[] = new long[n];
- }
- public class MatrixSys extends java.applet.Applet implements DataSys {
- Thread thr;
- public void init() {
- for (int m = 0; m <= n - 1; m++) {
- for(int p=0; p <= n-1; p++) {
- a[m][p] = 1;
- b[p] = 1;
- }
- }
- try {
- for(int i=0; i <= n-1; i++) {
- thr = new Thread(new ProcSys(i));
- thr.start();
- thr.join();
- }
- Thread.sleep(1);
- } catch(InterruptedException e) {};
- add(new Label(n+"Tpmax="+new MaxTime().max()));
- }
- /** Initialization method that will be called after the applet is loaded
- * into the browser.
- */
- // TODO overwrite start(), stop() and destroy() methods
- }
- class ProcSys implements Runnable, DataSys {
- int i;
- ProcSys(int i) {
- this.i = i;
- }
- public void run() {
- long t1 = new Date().getTime();
- new Index(i,i).index();
- long t2 = new Date().getTime();
- time[i] = t2 - t1;
- }
- }
- class Index implements DataSys {
- int i, j;
- Index(int i, int j) {
- this.i = i;
- this.j = j;
- }
- public void index() {
- for(int t=0; t <= n-1; t++) {
- j = (n+i-t) % n;
- new Step(i,j).mult();
- }
- }
- }
- class Step implements DataSys {
- int i, j;
- Step(int i, int j) {
- this.i = i;
- this.j = j;
- }
- synchronized void mult(){
- s[i] += a[i][j] * b[j];
- try {
- Thread.sleep(1);
- } catch(InterruptedException e) {}
- //System.out.println("S"+"["+i+"]=" + s[i]);
- }
- }
- class MaxTime implements DataSys {
- public long max() {
- long tpmax = time[0];
- for (int i=1; i<=n-1;i++)
- if(tpmax<=time[i])
- tpmax = time[i];
- return tpmax;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement