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
|
import mpjdev.*;
import mpjbuf.*;
import java.util.Arrays;
public class AnyTag {
public static void main(String args[]) throws Exception {
int DATA_SIZE = 100;
Comm.init(args);
for (int h = 0; h < 1000; h++) {
System.out.println("\n\n\n************************<TEST==" + h +
">**************************\n\n\n");
Comm.out.println("\n\n\n************************<TEST==" + h +
">**************************\n\n\n");
int intArray[] = new int[DATA_SIZE];
for (int i = 0; i < DATA_SIZE; i++) {
intArray[i] = i + 1;
}
if (Comm.WORLD.id() == 0) {
System.out.println("Writing intBuffer");
Buffer intBuffer = new Buffer( (DATA_SIZE * 4) + 8);
intBuffer.putSectionHeader(Buffer.INT);
intBuffer.write(intArray, 0, DATA_SIZE);
intBuffer.commit();
for (int k = 1; k < Comm.WORLD.size(); k++) {
Comm.WORLD.send(intBuffer, k, h);
}
System.out.println("Send Completed \n\n");
}
else {
int intReadArray[] = new int[DATA_SIZE];
for (int i = 0; i < intReadArray.length; i++) {
intReadArray[i] = -1;
}
Buffer intBuffer = new Buffer( (DATA_SIZE * 4) + 8);
System.out.println("Receving ints ");
Comm.WORLD.recv(intBuffer, Comm.WORLD.ANY_SOURCE, Comm.WORLD.ANY_TAG);
intBuffer.commit();
intBuffer.getSectionHeader(Buffer.INT);
System.out.println("Read Int");
intBuffer.read(intReadArray, 0, DATA_SIZE);
if (Arrays.equals(intArray, intReadArray)) {
System.out.println("Passed");
}
else {
System.out.println("Failed");
}
}
//This should be the last call, in order to finish the communication
} //end big for loop.
//Comm.WORLD.barrier();
try {
Thread.currentThread().sleep(100000);
}
catch (Exception e) {}
Comm.finish();
} //end constr
} //end class
|