# JAVA-Synchronization -VERY beginner-Help

chazz lee

Greenhorn

Posts: 2

posted 11 years ago

Hi all, my knowledge of java language isnt great, so would appricviete it if any of you could help me out with this problem .

im trying to propose an application java multi process (threads) implementing the algorithm of the calculation of the "standard line" of a matrix A and B. This standard line called Z and its defined by : z=�UC�U or C=A*B;

A=(a ik)//ik are the indices of matrix A. B = (B kj)// kj are the indices of the matrix B. C = (C ij)// ij are the indices of the matrix C.

ij = ��a (ik) * B (kj)// K of 1 A p.

D (i) = ����C (ij) �� J of 1 A m.

Z = max (D (I))// I of 1 A N.

N, m, p, A, B should be read

I have been given this methode that im trying to use , but i am still not sure how to impliment it ( so, will need help with that):

steps are:

To calculate "Z" of a matrix C how its:

1- C is calculated from the product of A and B

2- make the sum of each line of the matrix C and put it in tables named D.

3- from there take the maximum of this table and the max of D it is standard Z of the matrix

B the indication to be added in relation to the java language

1 in the program will use 3 threads that we call: T1, T2, T3.

** the first thread T1 will carry out the product of both matrix A and B.

** the second thread T2 makes the sum of the lines of the matrix C.

** the third thread T3 will do the maximum of tables D.

2 if the matrix C result of product A and B has a dimension of (n*m) and for precise parallelism we will make of the first thread (n*m) other thread each will deal with the product of only one element of the matrix C.

i.e. if have a matrix C of (4*4) we will have 16 threads created of the first thread T1, the 16 thrads each will make the product of only one element of the matrix C.

3-Entering matrix A and B will not be done using the interface in javas but its the console which will deal with entering them

i.e. it is the computer which gives the values of the two matrices in a random way by using the methods randome

"for(int I = 0; I < N; i++ for(int J = 0; J < m; j++)

A [j ] = Math.random(); initialization of matrix A.

for(int I = 0; I < N; i++)

For(int j=0;j

B [j ] = Math.random(); initialization of the matrix B "and the dimensions used will be " int N = A.length; "for the lines and int m = A[0].length;for the columns.

we enter them and use for example "system.in.readln(n)" and "system.in.readln(m)".

4- after having implemented the methods run() and start() of the three thread we add the key word (synchroniserd) for the 3 threads since thread T2 cannot work except if it has the elements from the first thread T1 and similarly for the third thread T3.

NOTES:

- do not use the method stop() for the 3 threads notices

- matriecs A and B are created and of same dimension.(n*m) .

im trying to propose an application java multi process (threads) implementing the algorithm of the calculation of the "standard line" of a matrix A and B. This standard line called Z and its defined by : z=�UC�U or C=A*B;

A=(a ik)//ik are the indices of matrix A. B = (B kj)// kj are the indices of the matrix B. C = (C ij)// ij are the indices of the matrix C.

ij = ��a (ik) * B (kj)// K of 1 A p.

D (i) = ����C (ij) �� J of 1 A m.

Z = max (D (I))// I of 1 A N.

N, m, p, A, B should be read

I have been given this methode that im trying to use , but i am still not sure how to impliment it ( so, will need help with that):

steps are:

To calculate "Z" of a matrix C how its:

1- C is calculated from the product of A and B

2- make the sum of each line of the matrix C and put it in tables named D.

3- from there take the maximum of this table and the max of D it is standard Z of the matrix

B the indication to be added in relation to the java language

1 in the program will use 3 threads that we call: T1, T2, T3.

** the first thread T1 will carry out the product of both matrix A and B.

** the second thread T2 makes the sum of the lines of the matrix C.

** the third thread T3 will do the maximum of tables D.

2 if the matrix C result of product A and B has a dimension of (n*m) and for precise parallelism we will make of the first thread (n*m) other thread each will deal with the product of only one element of the matrix C.

i.e. if have a matrix C of (4*4) we will have 16 threads created of the first thread T1, the 16 thrads each will make the product of only one element of the matrix C.

3-Entering matrix A and B will not be done using the interface in javas but its the console which will deal with entering them

i.e. it is the computer which gives the values of the two matrices in a random way by using the methods randome

"for(int I = 0; I < N; i++ for(int J = 0; J < m; j++)

A [j ] = Math.random(); initialization of matrix A.

for(int I = 0; I < N; i++)

For(int j=0;j

B [j ] = Math.random(); initialization of the matrix B "and the dimensions used will be " int N = A.length; "for the lines and int m = A[0].length;for the columns.

we enter them and use for example "system.in.readln(n)" and "system.in.readln(m)".

4- after having implemented the methods run() and start() of the three thread we add the key word (synchroniserd) for the 3 threads since thread T2 cannot work except if it has the elements from the first thread T1 and similarly for the third thread T3.

NOTES:

- do not use the method stop() for the 3 threads notices

- matriecs A and B are created and of same dimension.(n*m) .

posted 11 years ago

Welcome to the JavaRanch, Chazz.

While we love to discuss all things Java, it's pretty clear that you are working on a homework assignment. Since the only way to learn to write code is to write code, we're going to ask you to do your own work. If you have specific questions, like a compile error you can't solve or how synchronization works between threads for example, we'd be glad to help.

While we love to discuss all things Java, it's pretty clear that you are working on a homework assignment. Since the only way to learn to write code is to write code, we're going to ask you to do your own work. If you have specific questions, like a compile error you can't solve or how synchronization works between threads for example, we'd be glad to help.

chazz lee

Greenhorn

Posts: 2