File: CommTest.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 (86 lines) | stat: -rwxr-xr-x 2,494 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
package commtest;

import mpjdev.*;
import mpjbuf.*;
import java.util.Arrays;

public class CommTest {

  public static void main(String args[]) throws Exception {
    int DATA_SIZE = 100;
    MPJDev.init(args);
    /* Creating the new communicator */
    byte byteArray[] = new byte[DATA_SIZE];

    for (int i = 0; i < DATA_SIZE; i++) {
      byteArray[i] = 's';
    }
    
    int[] newIds = {2, 3, 4};
    Comm newComm = MPJDev.WORLD.create(newIds);
    
    int[] newIds1 = {5, 6, 7};
    Comm newComm1 = MPJDev.WORLD.create(newIds1);

    int[] newIds2 = {0, 1};
    Comm newComm2 = MPJDev.WORLD.create(newIds2);    
   
    int[] newIds3 = {0, 2, 4, 6};
    Comm newComm3 = MPJDev.WORLD.create(newIds3);
    System.out.println("<"+MPJDev.WORLD.id()+">==<"+newComm3.id());

    if (MPJDev.WORLD.id() == 0 && newComm3.id() == 0) {
      Buffer byteBuffer = new Buffer(DATA_SIZE + 8); 
      byteBuffer.putSectionHeader(Buffer.BYTE);
      byteBuffer.write(byteArray, 0, DATA_SIZE); 
      byteBuffer.commit(); 
      System.out.println("Sending bytes");
      newComm3.send(byteBuffer, 1, 90);
    }
    else if ( ( (MPJDev.WORLD.id() == 2) || (MPJDev.WORLD.id() == 4) ||
		(MPJDev.WORLD.id() == 6) ) && newComm3.id() == 1) {
      
      byte byteReadArray[] = new byte[DATA_SIZE];
      
      for (int i = 0; i < DATA_SIZE; i++) {
        byteReadArray[i] = 'x';
      }

      Buffer byteBuffer = new Buffer( (DATA_SIZE) + 8);
      System.out.println("Receving bytes");
      newComm3.recv(byteBuffer, 0, 90);
      byteBuffer.commit();

      try {
        byteBuffer.getSectionHeader(Buffer.BYTE);
        byteBuffer.read(byteReadArray, 0, DATA_SIZE);
      }
      catch (Exception e) {
        e.printStackTrace();
      }

      if (Arrays.equals(byteArray, byteReadArray)) {
        System.out.println("\n#################" +
                           "\n <<<<PASSED>>>> " +
                           "\n################");
      }
      else {
        System.out.println("\n#################" +
                           "\n <<<<FAILED>>>> " +
                           "\n################");
        System.exit(0);
      }

    } //end while(true)

    //System.out.println("Calling the barrier");
    //MPJDev.WORLD.nbarrier();
    //System.out.println("Barrier ends");
    try {
      Thread.currentThread().sleep(10000);
    }
    catch (Exception e) {}
    MPJDev.finish();

  }
}