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 (80 lines) | stat: -rw-r--r-- 1,960 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
package microbenchmarkmpiJava.pingpong.Ssend; 

//
// mpiJava version : Taboada
//                   July 2002
// DES
//

import java.io.*;
import java.text.NumberFormat;
import java.lang.Math;
import mpi.*;

public class PingPong {

  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;
	long 		time;
	
    MPI.Init(args);

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

    MPI.COMM_WORLD.Barrier();

	  iterations = Integer.parseInt(System.getProperty("ITERATIONS"));
	
	  size = Integer.parseInt(System.getProperty("SIZE"));
	  
      byte A[] = new byte [size];
      
      for (i = 0; i < size; i++) {
	    A[i] = (byte)'0'; //(double) 1. / (i + 1);
      }

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


		MPI.COMM_WORLD.Barrier();			  

	if (my_pe == 0) {
		for (ns = 0; ns < iterations; ns++) {	
			startwtime = MPI.Wtime();	
			MPI.COMM_WORLD.Ssend(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.Ssend(A, 0, size, MPI.BYTE, 0, 20);
		}	  		
	}
    MPI.Finalize();    
    if(my_pe == 0) {
       System.out.println(" Ssend PingPong TEST COMPLETE");	    
    }
  }
}