File: PingPong.java

package info (click to toggle)
mpj 0.44%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 7,592 kB
  • sloc: java: 49,853; ansic: 2,508; xml: 596; sh: 311; perl: 156; makefile: 27
file content (92 lines) | stat: -rw-r--r-- 2,324 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
package microbenchmarkmpiJava.pingpong.Bsend; 
//
// mpiJava version : Taboada
//                   July 2002
// DES
//

import java.io.*;
import java.text.NumberFormat;
import java.lang.Math;
import mpi.*;
import java.nio.ByteBuffer ;
//no detach thing.

public class PingPong {

	static private byte A[];
	//static final private byte B[] = new byte [10000000];
	//static final private mpi.Buffer B = new mpi.Buffer(10000000+100);  
	static final private ByteBuffer B = 
		ByteBuffer.allocate( 10000000+100);  

  public static void main(String[] args) throws MPIException {
  }

  public PingPong() {
  }

  public PingPong(String[] args) throws Exception {
	  

    double      startwtime, endwtime; 
    int         i, iterations, size, ns, my_pe, npes, pot2size;
    Status      status;
	int 		MPI_BSEND_OVERHEAD = 10000000;
	long 		time;
	
    MPI.Init(args);

    my_pe = MPI.COMM_WORLD.Rank();
    npes  = MPI.COMM_WORLD.Size();

	
	  iterations = Integer.parseInt(System.getProperty("ITERATIONS"));
	
	  size = Integer.parseInt(System.getProperty("SIZE"));
	  
     A = new byte [size];
    // byte B[] = new byte [MPI_BSEND_OVERHEAD];
	        

          
		MPI.Buffer_attach(B);

		pot2size = (int)(Math.log((double) size)/1.386294361);
		if (pot2size < 0) pot2size = 0;

		for (i = 0; i < size; i++) {
	    	A[i] = (byte)'0'; //(double) 1. / (i + 1);
      	}
			
		MPI.COMM_WORLD.Barrier();			  

	if (my_pe == 0) {
		for (ns = 0; ns < iterations; ns++) {		
		
			startwtime = MPI.Wtime();	
			MPI.COMM_WORLD.Bsend(A, 0, size, MPI.BYTE, 1, 10);
			status = MPI.COMM_WORLD.Recv(A, 0, size, MPI.BYTE, 1, 20);			  	
			endwtime = MPI.Wtime();

			//Format the Number to Display
			NumberFormat nf = NumberFormat.getInstance();
			nf.setMaximumFractionDigits(6);
			nf.setMinimumFractionDigits(6);			  
			
			time = (long) (500000.*(endwtime - startwtime));	
			System.out.println(nf.format((double) time/1000000)+" \t "+time+" \t "+nf.format((double) size/time)+" \t "+size+" \t "+pot2size);
		}
	}
	if (my_pe == 1) {
		for (ns = 0; ns < iterations; ns++) {			
			status = MPI.COMM_WORLD.Recv(A, 0 , size, MPI.BYTE, 0, 10);
			MPI.COMM_WORLD.Bsend(A, 0, size, MPI.BYTE, 0, 20);
		}	  		
	}
    MPI.Finalize();    
    if(my_pe == 0) {
       System.out.println(" Bsend PingPong TEST COMPLETE");	    
    }
  }
}