Advertisement
Guest User

Untitled

a guest
May 5th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. public static void multiplySquareMtxSimple(Node node)
  2. {
  3. int myId = node.getMyId();
  4. int meshSideSize = (int) Math.sqrt(node.getNumberOfAllNodes());
  5. int myRow = Topology.meshRowOfId(myId, meshSideSize);
  6. int myCol = Topology.meshColOfId(myId, meshSideSize);
  7. int nNodes = node.getNumberOfAllNodes();
  8.  
  9. // TODO
  10. // ...
  11. // System.out.println(myId + " " + myRow + " " + myCol);
  12.  
  13. double[] myDataA = node.A.getMatrixRowwise();
  14. double[] myDataB = node.B.getMatrixRowwise();
  15.  
  16. // Matrix otherDtataA = new Matrix(node.A.getNRows(), node.A.getNCols());
  17. // Matrix otherDtataB = new Matrix(node.B.getNRows(), node.B.getNCols());
  18. //
  19. // Matrix resultData = new Matrix(node.A.getNRows(), node.B.getNCols());
  20.  
  21. // .Matrix(node.A.getNRows(), node.B.getNCols(), data );
  22.  
  23. Matrix[] dataA = new Matrix[meshSideSize];
  24. /* for (int i = 0; i < meshSideSize; i++)
  25. {
  26. dataA[i] = new Matrix(node.A.getNRows(), node.A.getNCols());
  27. }
  28. */
  29. Matrix[] dataB = new Matrix[meshSideSize];
  30. /*for (int i = 0; i < meshSideSize; i++)
  31. {
  32. dataB[i] = new Matrix(node.B.getNRows(), node.B.getNCols());
  33. }*/
  34. int ACounter = 0;
  35. int BCounter = 0;
  36. double[] otherData;
  37. for (int i=0; i<nNodes; i++)
  38. {
  39. if (myRow == Topology.meshRowOfId(i, node.A.getNRows())& i!=myId)
  40. {
  41. otherData = BasicCommunication.exchangeWith(node, i, myDataA);
  42. dataA[ACounter] = new Matrix(node.A.getNRows(), node.A.getNCols(), otherData);
  43. //ACounter++;
  44. //System.out.println(myId + " -> " + i);
  45. }
  46. if (i==myId)
  47. {
  48. dataA[ACounter] = new Matrix(node.A.getNRows(), node.A.getNCols(), myDataA);
  49. //ACounter++;
  50. }
  51. if (myCol == Topology.meshColOfId(i, node.B.getNCols())& i!=myId)
  52. {
  53. otherData = BasicCommunication.exchangeWith(node, i, myDataB);
  54. dataB[BCounter] = new Matrix(node.B.getNRows(), node.B.getNCols(), otherData);
  55. BCounter++;
  56. //System.out.println(myId + " -> " + i);
  57. }
  58. if (i==myId)
  59. {
  60. dataB[BCounter] = new Matrix(node.B.getNRows(), node.B.getNCols(), myDataB);
  61. BCounter++;
  62. }
  63. }
  64.  
  65. Matrix resultMatrix = new Matrix(node.A.getNRows(), node.B.getNCols());
  66. for (int i = 0; i < meshSideSize; i++)
  67. {
  68. for (int j = 0; j < meshSideSize; j++)
  69. resultMatrix.addInPlace(dataA[i].times(dataB[j]));
  70. }
  71.  
  72. if (true)
  73. {
  74. System.out.println(myId);
  75. }
  76.  
  77.  
  78.  
  79.  
  80.  
  81. node.C = resultMatrix.divideInPlace(meshSideSize);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement