File: BufferTestDyna2.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 (208 lines) | stat: -rwxr-xr-x 7,604 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package buffertest;

import mpjdev.*;
import mpjbuf.*;

public class BufferTestDyna2 {

  public static void main(String args[]) throws Exception {
    //the first call will always be init()
    MPJDev.init(args);

    if (MPJDev.WORLD.id() == 0) {
      /********* THINGS TO BE SENT ******************/
      int intArray[] = new int[100];
      for (int j = 0; j < intArray.length; j++) {
        intArray[j] = j + 1;
      }

      float floatArray[] = new float[100];
      for (int i = 0; i < floatArray.length; i++) {
        floatArray[i] = i + 11;
      }

      double doubleArray[] = new double[100];
      for (int i = 0; i < doubleArray.length; i++) {
        doubleArray[i] = i + 11.11;
      }

      long longArray[] = new long[100];
      for (int i = 0; i < longArray.length; i++) {
        longArray[i] = i + 11;
      }

      boolean booleanArray[] = new boolean[100];
      for (int i = 0; i < booleanArray.length; i++) {
        booleanArray[i] = true;
      }

      short shortArray[] = new short[100];
      for (int i = 0; i < shortArray.length; i++) {
        shortArray[i] = 1;
      }

      char charArray[] = new char[100];
      for (int i = 0; i < charArray.length; i++) {
        charArray[i] = 's';
      }

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

      /********* PACKING OF THE BUFFER *****************/ Buffer buffer = new
          Buffer( (8 * 8));
      buffer.putSectionHeader(Buffer.BYTE_DYNAMIC);
      buffer.write(byteArray, 0, 100); //writes the first section
      buffer.putSectionHeader(Buffer.CHAR_DYNAMIC);
      buffer.write(charArray, 0, 100); //writes teh second section
      buffer.putSectionHeader(Buffer.INT_DYNAMIC);
      buffer.write(intArray, 0, 100); // and so on ....
      buffer.putSectionHeader(Buffer.SHORT_DYNAMIC);
      buffer.write(shortArray, 0, 100);
      buffer.putSectionHeader(Buffer.BOOLEAN_DYNAMIC);
      buffer.write(booleanArray, 0, 100);
      buffer.putSectionHeader(Buffer.LONG_DYNAMIC);
      buffer.write(longArray, 0, 100);
      buffer.putSectionHeader(Buffer.DOUBLE_DYNAMIC);
      buffer.write(doubleArray, 0, 100);
      buffer.putSectionHeader(Buffer.FLOAT_DYNAMIC);
      buffer.write(floatArray, 0, 100);
      /********* PACKING OF THE BUFFER *****************/
      buffer.commit();
      MPJDev.WORLD.send(buffer, 1, 999); //Buffer, destinationRank, tag (make sure you have matchin recv also called)
      System.out.println("Send Completed \n\n");
    }

    else if (MPJDev.WORLD.id() == 1) {

      /********* THINGIES TO BE READ ******************/
      int intReadArray[] = new int[100];
      for (int j = 0; j < intReadArray.length; j++) {
        intReadArray[j] = 3;
      }

      float floatReadArray[] = new float[100];
      for (int i = 0; i < floatReadArray.length; i++) {
        floatReadArray[i] = i + 19;
      }

      double doubleReadArray[] = new double[100];
      for (int i = 0; i < doubleReadArray.length; i++) {
        doubleReadArray[i] = i + 99.11;
      }
      long longReadArray[] = new long[100];
      for (int i = 0; i < longReadArray.length; i++) {
        longReadArray[i] = i + 9;
      }

      boolean booleanReadArray[] = new boolean[100];
      for (int i = 0; i < booleanReadArray.length; i++) {
        booleanReadArray[i] = false;
      }

      short shortReadArray[] = new short[100];
      for (int i = 0; i < shortReadArray.length; i++) {
        shortReadArray[i] = 2;
      }

      char charReadArray[] = new char[100];
      for (int i = 0; i < charReadArray.length; i++) {
        charReadArray[i] = 'x';
      }

      byte byteReadArray[] = new byte[100];
      for (int i = 0; i < byteReadArray.length; i++) {
        byteReadArray[i] = 'x';
      }

      /********* THINGIES TO BE READ ******************/
      //Same rules as above apply here as well. For the size of the things.
      Buffer buffer = new Buffer( (8 * 8));
      MPJDev.WORLD.recv(buffer, 0, 999);
      buffer.commit();

      try {
        System.out.println("Read byte array");
        buffer.getSectionHeader(Buffer.BYTE_DYNAMIC);
        buffer.read(byteReadArray, 0, 100); //reads the first section
        System.out.println("Read char array");
        buffer.getSectionHeader(Buffer.CHAR_DYNAMIC);
        buffer.read(charReadArray, 0, 100); //reads the second section
        System.out.println("Read int array");
        buffer.getSectionHeader(Buffer.INT_DYNAMIC);
        buffer.read(intReadArray, 0, 100); // and so on ....
        System.out.println("Read short array");
        buffer.getSectionHeader(Buffer.SHORT_DYNAMIC);
        buffer.read(shortReadArray, 0, 100);
        System.out.println("Read boolean array");
        buffer.getSectionHeader(Buffer.BOOLEAN_DYNAMIC);
        buffer.read(booleanReadArray, 0, 100);
        System.out.println("Read long array");
        buffer.getSectionHeader(Buffer.LONG_DYNAMIC);
        buffer.read(longReadArray, 0, 100);
        System.out.println("Read double array");
        buffer.getSectionHeader(Buffer.DOUBLE_DYNAMIC);
        buffer.read(doubleReadArray, 0, 100);
        System.out.println("Read float array");
        buffer.getSectionHeader(Buffer.FLOAT_DYNAMIC);
        buffer.read(floatReadArray, 0, 100);
      }
      catch (Exception e) {
        e.printStackTrace();
        MPJDev.finish();
      }

      System.out.print(
          "\t********* DISPLAYING THE INT ARRAY READ *********\n\n");
      for (int j = 0; j < intReadArray.length; j++) {
        System.out.print("int[" + j + "]=" + intReadArray[j] + "\t");
      }

      System.out.print(
          "\t******** DISPLAYING THE FLOAT ARRAY READ ********\n\n");
      for (int j = 0; j < floatReadArray.length; j++) {
        System.out.print("float[" + j + "]=" + floatReadArray[j] + "\t");
      }

      System.out.print(
          "\t******* DISPLAYING THE DOUBLE ARRAY READ ********\n\n");
      for (int j = 0; j < doubleReadArray.length; j++) {
        System.out.print("double[" + j + "]=" + doubleReadArray[j] + "\t");
      }

      System.out.print("\t******** DISPLAYING THE LONG ARRAY READ ********\n\n");
      for (int j = 0; j < longReadArray.length; j++) {
        System.out.print("long[" + j + "]=" + longReadArray[j] + "\t");
      }

      System.out.print(
          "\t******** DISPLAYING THE SHORT ARRAY READ ********\n\n");
      for (int j = 0; j < shortReadArray.length; j++) {
        System.out.print("short[" + j + "]=" + shortReadArray[j] + "\t");
      }

      System.out.print(
          "\t******** DISPLAYING THE FLOAT ARRAY READ ********\n\n");
      for (int j = 0; j < charReadArray.length; j++) {
        System.out.print("char[" + j + "]=" + charReadArray[j] + "\t");
      }

      System.out.print("\t******** DISPLAYING THE BYTE ARRAY READ ********\n\n");
      for (int j = 0; j < byteReadArray.length; j++) {
        System.out.print("byte[" + j + "]=" + byteReadArray[j] + "\t");
      }

      System.out.print(
          "\t******** DISPLAYING THE BOOLEAN ARRAY READ ********\n\n");
      for (int j = 0; j < booleanReadArray.length; j++) {
        System.out.print("boolean[" + j + "]=" + booleanReadArray[j] + "\t");
      }
      System.out.println("Receive Completed \n\n");
    }

    //This should be the last call, in order to finish the communication
    MPJDev.finish();
  }
}