File: scatterv.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 (121 lines) | stat: -rw-r--r-- 2,884 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
package mpi.ccl;

/*
 MPI-Java version :
 Sang Lim (slim@npac.syr.edu)
 Northeast Parallel Architectures Center at Syracuse University
 12/2/98
 */

import mpi.*;

public class scatterv {
  static public void main(String[] args) throws Exception {
    try {
      scatterv c = new scatterv(args);
    }
    catch (Exception e) {
    }
  }

  public scatterv() {
  }

  public scatterv(String[] args) throws Exception {

    final int MAXLEN = 10;

    int myself, tasks;
    MPI.Init(args);
    myself = MPI.COMM_WORLD.Rank();
    tasks = MPI.COMM_WORLD.Size();

    if (tasks > 8) {
      if (myself == 0)
	System.out.println("scatterv must run with less than 8 tasks! ");
      MPI.Finalize();
      return;
    }

    int root, i = 0, j, k, stride = 15;
    int out[] = new int[tasks * stride];
    int in[] = new int[MAXLEN];
    int dis[] = new int[MAXLEN];
    int scount[] = new int[MAXLEN];

    for (i = 0; i < MAXLEN; i++) {
      dis[i] = i * stride;
      scount[i] = 5;
      in[i] = 0;
    }
    scount[0] = 10;

    for (i = 0; i < tasks * stride; i++)
      out[i] = i;

    MPI.COMM_WORLD.Scatterv(out, 0, scount, dis, MPI.INT, in, 0,
	scount[myself], MPI.INT, 0);

    String[] messbuf = new String[1];

    if (myself == 0) {
      System.out.println("Original array on root...");
      for (i = 0; i < tasks * stride; i++)
	System.out.print(out[i] + " ");
      System.out.println();
      System.out.println();

      System.out.println("Result on proc 0...");
      System.out.println("Stride = 15 " + "Count = " + scount[0]);
      for (i = 0; i < MAXLEN; i++)
	System.out.print(in[i] + " ");
      System.out.println();
      System.out.println();

      // Reproduces output of original test case, but deterministically

      int nmess = tasks < 3 ? tasks : 3;
      for (int t = 1; t < nmess; t++) {
	MPI.COMM_WORLD.Recv(messbuf, 0, 1, MPI.OBJECT, t, 0);

	System.out.print(messbuf[0]);
      }
    }

    if (myself == 1) {
      StringBuffer mess = new StringBuffer();

      mess.append("Result on proc 1...\n");
      mess.append("Stride = 15 " + "Count = " + scount[1] + "\n");
      for (i = 0; i < MAXLEN; i++)
	mess.append(in[i] + " ");
      mess.append("\n");
      mess.append("\n");

      messbuf[0] = mess.toString();
      MPI.COMM_WORLD.Send(messbuf, 0, 1, MPI.OBJECT, 0, 0);
    }

    if (myself == 2) {
      StringBuffer mess = new StringBuffer();

      mess.append("Result on proc 2...\n");
      mess.append("Stride = 15 " + "Count = " + scount[2] + "\n");
      for (i = 0; i < MAXLEN; i++)
	mess.append(in[i] + " ");
      mess.append("\n");

      messbuf[0] = mess.toString();
      MPI.COMM_WORLD.Send(messbuf, 0, 1, MPI.OBJECT, 0, 0);
    }

    if (myself == 0)
      System.out.println("Scatterv TEST COMPLETE");
    MPI.Finalize();
  }
}

// Things to do
//
// Make output deterministic by gathering and printing from root.