File: Bandwidth.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 (125 lines) | stat: -rwxr-xr-x 3,372 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
115
116
117
118
119
120
121
122
123
124
125
package mpi.perf; 
import mpi.*;
import java.nio.ByteBuffer ;
import java.io.* ; 

public class Bandwidth {
  public Bandwidth() {
  }
  public Bandwidth(String[] args) throws Exception {  
    int WARM_UP = 10000 ;
    int REPEAT = 20000 ;
    long[] delays = new long[REPEAT];
    long[] latency = new long[REPEAT];
    long start= 0L, stop=0L, init = 0L;
    MPI.Init(args);				
    int me = MPI.COMM_WORLD.Rank(); 
    System.out.println("Name ="+MPI.Get_processor_name());
    byte byteArray [] = null;
    int j=1, i=0;   	       		   	
    int LOG2N_MAX = 1000000,log2nbyte=0,padding=0;	
    long timed = 0L;		
    byteArray = new byte[16777216];
    PrintStream out = null ;
    FileOutputStream fos = null ;

    
    for(i =0;i < byteArray.length;i++) {
      byteArray[i] = 's';
    }

    /* Can do a warm-up here */
    if(me == 1) {
      fos = new FileOutputStream("bw_delays.out");
      out = new PrintStream (fos);
    }
    else {
      fos = new FileOutputStream("bw.out"); 
      out = new PrintStream (fos);
    } 

    for(i=0;i < 100 ;i++) {
      if(me == 0) {
        MPI.COMM_WORLD.Recv(byteArray,0,1,MPI.BYTE,1,998);
        MPI.COMM_WORLD.Send(byteArray,0,1,MPI.BYTE,1,998);
      }
      else if(me == 1) {
        MPI.COMM_WORLD.Send(byteArray,0,1,MPI.BYTE,0,998);
        MPI.COMM_WORLD.Recv(byteArray,0,1,MPI.BYTE,0,998);
      }
    }

    /* Logrithmic Loop */
    for (log2nbyte = 0; log2nbyte<= LOG2N_MAX && j<16*1024*1024; ++log2nbyte) { 

        //MPI.COMM_WORLD.Barrier();

	j = (1 << log2nbyte);

	/* Latency Calculation Loop */
	for (i = 0; i < REPEAT ; i++) {	   			
	  if(me == 0) {
	    myDelay( (int) (Math.random() * 1000)) ;
	    init = System.nanoTime() ; 
            MPI.COMM_WORLD.Send(byteArray,0,j,MPI.BYTE,1,998);	   		  	    MPI.COMM_WORLD.Recv(byteArray,0,j,MPI.BYTE,1,998);
	    latency[i] = ((System.nanoTime() - init)/1000) ; 
	  } else if(me == 1) {
            MPI.COMM_WORLD.Recv(byteArray,0,j,MPI.BYTE,0,998);
            start = System.nanoTime() ;
	    myDelay( (int)(Math.random() * 1000));
	    delays[i] = (System.nanoTime() - start)/1000 ;
            MPI.COMM_WORLD.Send(byteArray,0,j,MPI.BYTE,0,998);			
	  }
	}

        if(me == 0) {
          for(int k=WARM_UP; k<REPEAT ; k++) {
            out.println(latency[k]+"   ");
          }
        }

        else {
          for (i = WARM_UP ; i < REPEAT ; i++) {
            out.println(delays[i]+"   ");
          }
        }
        
        MPI.COMM_WORLD.Barrier() ;   

	//if(me == 0) { 
        //System.out.println(j+"           "+(latency*1000)+
	//	"           "+(( 8*j ) /( 1024*1024* (latency/(1000)))) );
	//}
    }//end logrithmic loop

    fos.close() ;
    out.close() ;  	 		

    MPI.Finalize();	  	
  }//end args constructor.
  
  static double tripsPerMS = 1000000 ;
  static int dummy ;

  static void myDelay(int us) {

    int trips = (int) (tripsPerMS * us) ;
    long start = System.nanoTime() ;

    for(int i = 0 ; i < trips ; i++) {
      dummy ++ ;
    }

    long actualDelay = System.nanoTime() - start ;

    if(actualDelay > 0 ) {
      long newTripsPerMS = (trips * 1000 ) / actualDelay ;

      if(newTripsPerMS > 0) {
        tripsPerMS = newTripsPerMS ;
      }
    }

  }
 
}//end class.