fork download
  1. import mpi.*;
  2. import java.util.Random;
  3.  
  4. public class PoissonGenerator {
  5. public static void main(String[] args) throws Exception {
  6. MPI.Init(args);
  7. int myid = MPI.COMM_WORLD.Rank();
  8. int numprocs = MPI.COMM_WORLD.Size();
  9. int totalNumbers = 1000000;
  10. int numbersPerProc = totalNumbers / numprocs;
  11. double lambda = 10.0;
  12.  
  13. Random rand = new Random();
  14. double[] localNumbers = new double[numbersPerProc];
  15.  
  16. for (int i = 0; i < numbersPerProc; i++) {
  17. int k = rand.nextInt(21);
  18. double probability = Math.exp(-lambda) * Math.pow(lambda, k) / factorial(k);
  19. localNumbers[i] = probability;
  20. }
  21.  
  22. MPI.Finalize();
  23. }
  24.  
  25. private static double factorial(int n) {
  26. double result = 1.0;
  27. for (int i = 2; i <= n; i++)
  28. result *= i;
  29. return result;
  30. }
  31. }
Success #stdin #stdout #stderr 0.27s 40680KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "import mpi."
Execution halted