-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster_test.java
More file actions
41 lines (32 loc) · 1.25 KB
/
master_test.java
File metadata and controls
41 lines (32 loc) · 1.25 KB
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
import mpi.*;
import java.nio.*;
public class master_test {
public static void main(String[] args) throws MPIException{
MPI.Init(args);
int size = MPI.COMM_WORLD.getSize();
int rank = MPI.COMM_WORLD.getRank();
String name = MPI.COMM_WORLD.getName();
if (size < 2) {
System.out.println("Too few processes!");
System.exit(1);
}
IntBuffer buffer = MPI.newIntBuffer(1);
int numItemsToTransfer = 1;
int sourceRank = 0;
int destinationRank = 1;
int messageTag = 0; // supplemental tag, often just not used
int bufferPosition = 0;
if (rank == 0) {
int valueToTransmit = 5;
buffer.put(bufferPosition, valueToTransmit);
MPI.COMM_WORLD.send(buffer, numItemsToTransfer, MPI.INT,
destinationRank, messageTag);
} else if (rank == 1) {
Status status = MPI.COMM_WORLD.recv(buffer, numItemsToTransfer,
MPI.INT, sourceRank, messageTag);
System.out.println("Process 1 received value " +
buffer.get(bufferPosition) + " from process 0");
}
MPI.Finalize();
}
}