Posted by poutchi1 (poutchi1), 14 April 2005Hi all, my knowledge of java language isnt great, so would appricviete it if any of you could help me out with this problem as soon as possible .
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=?C? 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):
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[i][j ] = Math.random(); initialization of matrix A.
for(int I = 0; I < N; i++)
B[i][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.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.
- do not use the method stop() for the 3 threads notices
- matriecs A and B are created and of same dimension.(n*m) .
Sorry for such a long problem, but really need help . THANKS IN ADVANCE
Posted by admin (Graham Ellis), 14 April 2005Hello - I think you've accidentally double posted an identical question both here and in the "learning to program" board. This is the more revelant place for it, so I'll leave this thread and lock the othe one.
Can you tell me a bit more about the application, by the way. Some of it looks rather arteficial - what has made you decide to request that the stop method isn't used, for example? This isn't, per chance, a coursework question that you've been set is it? If so, I can offer some guidance but little more since you'll not learn much if I or anyone else does too much for you.
Posted by admin (Graham Ellis), 14 April 2005Quote:
The best way to deal with a long problem is to split it down into smaller problems - draw yourself a flowchart or some other simple diagrams (along the lines of UML diagrams perhaps) - just the bear bones - then work on each part individually. Then work on each of the component parts individually. Have a look at some simple examples of threads - http://www.wellho.net/resources/J804.html for example - and put an overall structure together before you write the rest - use stubbs (dummy code that just returns a constant result) to get this overview operational before going on to write the detail required within.
Please do post any further short snippets of code if you're having any problems with specific code.
Posted by admin (Graham Ellis), 17 April 2005Hello ... still happy to provide some specific advise (and I know you were on a tight timescale on this). But I still don't know why you've chosen the complexity of using a threaded approach, the applied some limits even to that approach. I suspect that someone else may have given you the spec ... and I question that spec.
I'm teaching on site for the next two weeks (and it's Tcl and Python that are the subjects) so that although I will be able to give you responses they may be slower than usual and my mind will be tuned in to other technologies.
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho