File: Reduce_scatter.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,593 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.reducescatter;

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

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

public class Reduce_scatter {

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

  }

  public Reduce_scatter() {
  }

  public Reduce_scatter(String[] args) throws Exception {
	  
    double      startwtime, endwtime, pot2npesd;
    int         i, iterations, size, ns, my_pe, npes, ndoubles, doublesxPe, pot2npes, pot2size;

    Status      status;

    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"));
	
	  ndoubles = size/8;	

	  doublesxPe = ndoubles / npes;
	  
	  int [] dbl = new int [] {doublesxPe, doublesxPe, doublesxPe, doublesxPe, doublesxPe, doublesxPe, doublesxPe, doublesxPe, doublesxPe, doublesxPe};
	  
      double A[] = new double [ndoubles];
      double B[] = new double [ndoubles];	
	  
	  double timesBcast[] = new double [iterations];
	  double timesBcastReduce[] = new double [iterations];
	        
      for (i = 0; i < ndoubles; i++) {
	    A[i] = (double) 1. / (i + 1);
      }

		pot2npes = (int)(Math.log(npes)/0.69314718);
		pot2npesd = (double)(Math.log(npes)/0.69314718);
		
		pot2size = (int)(Math.log(size)/1.386294361);
		if (pot2size < 0) pot2size = 0;	 
		
	    for (ns = 0; ns < iterations; ns++) {
	   		  MPI.COMM_WORLD.Barrier();		  
			  startwtime = MPI.Wtime();					
	          MPI.COMM_WORLD.Reduce_scatter(A, 0, B, 0, dbl, MPI.DOUBLE, MPI.MAX);
			  endwtime = MPI.Wtime();
			  
		  	  timesBcast[ns] = (double) (1000000*(endwtime - startwtime));	
		  			  
			}
   		
		MPI.COMM_WORLD.Reduce(timesBcast, 0, timesBcastReduce, 0, iterations, MPI.DOUBLE, MPI.MAX, 0);

		if (my_pe == 0) {
			//Format the Number to Display
			NumberFormat nf = NumberFormat.getInstance();
            nf.setMaximumFractionDigits(6);
            nf.setMinimumFractionDigits(6);	
			  
		    for (i = 0; i < iterations; i++) {
			  		System.out.print(nf.format((double) timesBcastReduce[i]/1000000)+" \t "+(long) timesBcastReduce[i]+" \t "+nf.format((double)(size/(timesBcastReduce[i])))); 
 			  		System.out.println(" \t "+npes+" \t "+pot2npes+" \t "+nf.format(pot2npesd)+" \t "+size+" \t "+pot2size);     		  
			}
		}
		
    MPI.Finalize();    
    if(my_pe == 0) {
      System.out.println("Reduce_scatter TEST COMPLETE "); 	    
    }
  }
}