File: NonBlockingTest2.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 (67 lines) | stat: -rwxr-xr-x 1,767 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
package nbcomms;

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

public class NonBlockingTest2 {

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

    MPJDev.init(args);
    int id = MPJDev.WORLD.id();
    int DATA_SIZE = 100;    
    mpjdev.Request [] sreqs = new mpjdev.Request[8];
    mpjdev.Request [] rreqs = new mpjdev.Request[8];    
    int intArray[] = new int[DATA_SIZE];

    for (int i = 0; i < DATA_SIZE; i++) {
      intArray[i] = i + 1;
    }
    
    for (int h = 1; h < 5; h++) {
	    
      if (id == 0) {	      
        Buffer intBuffer = new Buffer( (DATA_SIZE * 4) + 8);
        intBuffer.putSectionHeader(Buffer.INT);
        intBuffer.write(intArray, 0, DATA_SIZE);
        intBuffer.commit();      
        sreqs[0] = MPJDev.WORLD.isend(intBuffer, 1, (1 + (h * 10)));
	for(int r=0 ; r<1 ; r++) {
	    sreqs[r].iwait();		
	}
	
      }
      else if (id == 1) {

        int intReadArray[] = new int[DATA_SIZE];
        for (int i = 0; i < intReadArray.length; i++) {
          intReadArray[i] = 3;
        }
        Buffer intBuffer = new Buffer( (DATA_SIZE * 4) + 8);       
        rreqs[0] = MPJDev.WORLD.irecv(intBuffer, 0, (1 + (h * 10)));        

	for(int r=0 ; r<1 ; r++) {
	    rreqs[r].iwait();		
	}

        intBuffer.commit();	
	intBuffer.getSectionHeader(Buffer.INT);
	intBuffer.read(intReadArray, 0, DATA_SIZE);

        if (Arrays.equals(intArray, intReadArray) ) {
          System.out.println(" <<<<PASSED>>>> ");
        } else {
          System.out.println(" <<<<FAILED>>>> ");        
          System.exit(0);
        }
	
      }

    } //end tests for loop ...

    Thread.currentThread().sleep(500);
    MPJDev.finish();

  }
}