| 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 |
package dr.inference.parallel; |
| 27 |
|
| 28 |
import mpi.MPI; |
| 29 |
import mpi.Status; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class MPIServices { |
| 36 |
|
| 37 |
public static void requestTermination(int slave) { |
| 38 |
int[] msg = new int[]{ServiceRequest.terminateProcess.getId()}; |
| 39 |
MPI.COMM_WORLD.Send(msg, |
| 40 |
0, 1, MPI.INT, slave, ServiceRequest.MSG_REQUEST_TYPE); |
| 41 |
} |
| 42 |
|
| 43 |
public static void requestLikelihood(int slave) { |
| 44 |
int[] msg = new int[]{ServiceRequest.calculateLikeliood.getId()}; |
| 45 |
MPI.COMM_WORLD.Send(msg, 0, 1, MPI.INT, slave, ServiceRequest.MSG_REQUEST_TYPE); |
| 46 |
} |
| 47 |
|
| 48 |
public static ServiceRequest getRequest(int master) { |
| 49 |
int[] msg = new int[1]; |
| 50 |
Status status = MPI.COMM_WORLD.Recv(msg, 0, 1, MPI.INT, |
| 51 |
master, ServiceRequest.MSG_REQUEST_TYPE); |
| 52 |
|
| 53 |
return ServiceRequest.getByID(msg[0]); |
| 54 |
} |
| 55 |
|
| 56 |
public static void sendDouble(double value, int dest) { |
| 57 |
double[] msg = new double[]{value}; |
| 58 |
|
| 59 |
MPI.COMM_WORLD.Send(msg, 0, 1, MPI.DOUBLE, dest, ServiceRequest.MSG_REQUEST_TYPE); |
| 60 |
} |
| 61 |
|
| 62 |
public static void sendDoubleArray(double[] values, int dest) { |
| 63 |
MPI.COMM_WORLD.Send(values, 0, values.length, MPI.DOUBLE, |
| 64 |
dest, ServiceRequest.MSG_REQUEST_TYPE); |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
public static void sendDoubleArray(Double[] value, int dest) { |
| 69 |
double[] v = new double[value.length]; |
| 70 |
for (int i = 0; i < v.length; i++) { |
| 71 |
v[i] = value[i]; |
| 72 |
} |
| 73 |
sendDoubleArray(v, dest); |
| 74 |
} |
| 75 |
|
| 76 |
public static void sendIntArray(int[] values, int dest) { |
| 77 |
MPI.COMM_WORLD.Send(values, 0, values.length, MPI.INT, |
| 78 |
dest, ServiceRequest.MSG_REQUEST_TYPE); |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
public static void sendInt(int value, int dest) { |
| 83 |
int[] msg = new int[]{value}; |
| 84 |
MPI.COMM_WORLD.Send(msg, 0, 1, MPI.INT, dest, ServiceRequest.MSG_REQUEST_TYPE); |
| 85 |
} |
| 86 |
|
| 87 |
public static int receiveInt(int source) { |
| 88 |
int[] msg = new int[1]; |
| 89 |
Status status = MPI.COMM_WORLD.Recv(msg, 0, 1, MPI.INT, |
| 90 |
source, ServiceRequest.MSG_REQUEST_TYPE); |
| 91 |
return msg[0]; |
| 92 |
} |
| 93 |
|
| 94 |
public static double receiveDouble(int source) { |
| 95 |
double[] msg = new double[1]; |
| 96 |
Status status = MPI.COMM_WORLD.Recv(msg, 0, 1, MPI.DOUBLE, |
| 97 |
source, ServiceRequest.MSG_REQUEST_TYPE); |
| 98 |
return msg[0]; |
| 99 |
} |
| 100 |
|
| 101 |
public static double[] receiveDoubleArray(int source, int length) { |
| 102 |
double[] msg = new double[length]; |
| 103 |
Status status = MPI.COMM_WORLD.Recv(msg, 0, length, MPI.DOUBLE, |
| 104 |
source, ServiceRequest.MSG_REQUEST_TYPE); |
| 105 |
return msg; |
| 106 |
} |
| 107 |
|
| 108 |
public static int[] receiveIntArray(int source, int length) { |
| 109 |
int[] msg = new int[length]; |
| 110 |
Status status = MPI.COMM_WORLD.Recv(msg, 0, length, MPI.INT, |
| 111 |
source, ServiceRequest.MSG_REQUEST_TYPE); |
| 112 |
return msg; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
} |