import mpi.*;
import java.util.Random;
public class PoissonGenerator {
public static void main(String[] args) throws Exception {
MPI.Init(args);
int myid = MPI.COMM_WORLD.Rank();
int numprocs = MPI.COMM_WORLD.Size();
int totalNumbers = 1000000;
int numbersPerProc = totalNumbers / numprocs;
double lambda = 10.0;
Random
rand = new Random
(); double[] localNumbers = new double[numbersPerProc];
for (int i = 0; i < numbersPerProc; i++) {
int k
= rand.
nextInt(21); double probability
= Math.
exp(-lambda
) * Math.
pow(lambda
, k
) / factorial
(k
); localNumbers[i] = probability;
}
MPI.Finalize();
}
private static double factorial(int n) {
double result = 1.0;
for (int i = 2; i <= n; i++)
result *= i;
return result;
}
}
aW1wb3J0IG1waS4qOwppbXBvcnQgamF2YS51dGlsLlJhbmRvbTsKCnB1YmxpYyBjbGFzcyBQb2lzc29uR2VuZXJhdG9yIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBFeGNlcHRpb24gewogICAgICAgIE1QSS5Jbml0KGFyZ3MpOwogICAgICAgIGludCBteWlkID0gTVBJLkNPTU1fV09STEQuUmFuaygpOwogICAgICAgIGludCBudW1wcm9jcyA9IE1QSS5DT01NX1dPUkxELlNpemUoKTsKICAgICAgICBpbnQgdG90YWxOdW1iZXJzID0gMTAwMDAwMDsKICAgICAgICBpbnQgbnVtYmVyc1BlclByb2MgPSB0b3RhbE51bWJlcnMgLyBudW1wcm9jczsKICAgICAgICBkb3VibGUgbGFtYmRhID0gMTAuMDsKCiAgICAgICAgUmFuZG9tIHJhbmQgPSBuZXcgUmFuZG9tKCk7CiAgICAgICAgZG91YmxlW10gbG9jYWxOdW1iZXJzID0gbmV3IGRvdWJsZVtudW1iZXJzUGVyUHJvY107CgogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbnVtYmVyc1BlclByb2M7IGkrKykgewogICAgICAgICAgICBpbnQgayA9IHJhbmQubmV4dEludCgyMSk7CiAgICAgICAgICAgIGRvdWJsZSBwcm9iYWJpbGl0eSA9IE1hdGguZXhwKC1sYW1iZGEpICogTWF0aC5wb3cobGFtYmRhLCBrKSAvIGZhY3RvcmlhbChrKTsKICAgICAgICAgICAgbG9jYWxOdW1iZXJzW2ldID0gcHJvYmFiaWxpdHk7CiAgICAgICAgfQoKICAgICAgICBNUEkuRmluYWxpemUoKTsKICAgIH0KCiAgICBwcml2YXRlIHN0YXRpYyBkb3VibGUgZmFjdG9yaWFsKGludCBuKSB7CiAgICAgICAgZG91YmxlIHJlc3VsdCA9IDEuMDsKICAgICAgICBmb3IgKGludCBpID0gMjsgaSA8PSBuOyBpKyspCiAgICAgICAgICAgIHJlc3VsdCAqPSBpOwogICAgICAgIHJldHVybiByZXN1bHQ7CiAgICB9Cn0=