File: SeqMatrix.java

package info (click to toggle)
mpj 0.44%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,600 kB
  • ctags: 6,809
  • sloc: java: 49,853; ansic: 2,508; xml: 596; sh: 311; perl: 156; makefile: 26
file content (114 lines) | stat: -rwxr-xr-x 2,935 bytes parent folder | download | duplicates (3)
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
110
111
112
113
114
package mpi.perf; 

import mpi.*; 

public class SeqMatrix {

  public static int NUM = 3000 ; 
  public static int NRA=NUM; 		/* number of rows in matrix A */
  public static int NCA=NUM;		/* number of columns in matrix A */
  public static int NCB=NUM;   		/* number of columns in matrix B */

  int loops = 100 ;
  
  public static void main(String args[]) throws Exception {	
    SeqMatrix matrixCalc = new SeqMatrix(args) ; 	    
  }

  public SeqMatrix() { 
  }

  public SeqMatrix (String args[]) throws Exception { 
    
    byte[][] recvArray = new byte[loops][] ;
    byte[][] sendArray = new byte[loops][] ;

    int rank ; 
    int size ; 
    int partner ; 
    int tag = 998 ; 
    int l,m,n ;
    
    Request [] request = new Request[loops] ;

    for(l=0 ; l<loops ; l++) {
      sendArray[l] = new byte[1] ;
      recvArray[l] = new byte[1] ;
    }
    
    MPI.Init(args) ; 	  
    System.out.println("Name ="+MPI.Get_processor_name());
    
    rank = MPI.COMM_WORLD.Rank() ; 
    size = MPI.COMM_WORLD.Size() ; 
    partner = (rank == 0 ? 1 : 0) ; 


    for(l=0 ; l<loops ; l++) {
      request[l] = MPI.COMM_WORLD.Irecv(recvArray[l],0,1,MPI.BYTE,
                                        MPI.ANY_SOURCE , l);
    }
	  
    int numtasks,		/* number of tasks in partition */
        taskid,			/* a task identifier */
        numworkers,		/* number of worker tasks */
        source,			/* task id of message source */
        dest,			/* task id of message destination */
        nbytes,			/* number of bytes in message */
        mtype,			/* message type */
        rows,                   /* rows of matrix A sent to each worker */
        averow, extra, offset,  /* used to determine rows sent to each worker */
        i, j, k,		/* misc */
        count;
		
    double a[][] = new double[NRA][];//NCA 	/* matrix A to be multiplied */
    double b[][] = new double[NCA][];//NCB   	/* matrix B to be multiplied */
    double c[][] = new double[NRA][];//NCB	/* result matrix C */

    for (i=0; i<NRA; i++) {
      a[i] = new double[NCA];
      for (j=0; j<NCA; j++) {					
        a[i][j]= i+j;
      }
    }

    for (i=0; i<NCA; i++) {
      b[i] = new double[NCB];
      for (j=0; j<NCB; j++) {
        b[i][j]= i*j;
      }
    }
			
    for (i=0; i<NRA; i++) {
      c[i] = new double[NCB];
      for (j=0; j<NCB; j++) {
        c[i][j]= 0d;
      }
    }

    long start = System.nanoTime() ; 
    /* Compute */
    for (k=0; k<NCB; k++) {
      for (i=0; i<NRA; i++) {
        c[i][k] = 0.0;
        for (j=0; j<NCA; j++)
          c[i][k] = c[i][k] + a[i][j] * b[j][k];
      }
    }

    long stop = System.nanoTime() ; 

    System.out.println("time ="+ ((double)stop-start)/(1000*1000*1000));

    for(l=0 ; l<loops ; l++) {
      MPI.COMM_WORLD.Send(sendArray[l],0,1,MPI.BYTE,partner,l);
    }

    for(l=0 ; l<loops ; l++) {
      request[l].Wait() ;
    }

    MPI.Finalize() ; 

  } 
}//end of class