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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| class MatriceOpx extends Thread {
static int matrice1[][];
static int vecter[][];
static int matrice2[][];
static int resultat[][];
static int n;
static int m;
static int th;
MatriceOpx(int i) {
th = i;
this.start();
}
@Override
public void run() {
int i, j, rang;
for (rang = 0; rang < n; rang++) {
if (vecter[rang][0] == 0) {
for (i = 0; i < n; i++) {
resultat[rang][i] = 0;
for (j = 0; j < n; j++) {
resultat[rang][i] = resultat[rang][i] + matrice1[rang][j] * matrice2[j][i];
}
}
vecter[rang][0] = 1;
vecter[rang][1] = th;
}
}
}
public static void main(String args[]) {
int i, j, k;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("<-- Multiplication de 2 matrices carres des entiers naturels --> ");
Scanner e1 = new Scanner(System.in);
n = e1.nextInt();
System.out.println("Veuillez introduiez le nombre de lignes et de colonnes des matrices : ");
System.out.println("Veuillez introduiez le nombre de thread:");
try {
m = e1.nextInt();
} catch (Exception e) {
}
if (m > n) {
System.out.print("Non, m <= n");
System.out.print("Veuillez introduiez le nombre de thread:");
try {
m = e1.nextInt();
} catch (Exception e) {
}
}
matrice1 = new int[n][n];
matrice2 = new int[n][n];
resultat = new int[n][n];
vecter = new int[n][2];
for (i = 0; i < n; i++) {
vecter[i][0] = 0;
}
System.out.println("Veuillez remplir les cases de la matrice une : ");
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
try {
matrice1[i][j] = 150;
} catch (Exception e) {
}
}
}
System.out.println("Veuillez remplir les cases de la matrice deux : ");
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
try {
matrice2[i][j] = 50;
} catch (Exception e) {
}
}
}
MatriceOpx mat[] = new MatriceOpx[m];
for (i = 0; i < m; i++) {
mat[i] = new MatriceOpx(i);
}
try {
for (i = 0; i < m; i++) {
mat[i].join();
}
} catch (Exception e) {
}
System.out.println("Ci dessous le resultat :");
for (i = 0; i < n; i++) {
k = i + 1;
System.out.println("le ligne numéro:" + k + " dans la matrice resultat fait le calcule à l'aide de thread N° : " + vecter[i][1] + "");
for (j = 0; j < n; j++) {
System.out.println(resultat[i][j]);
}
}
}
} |
Partager