Reputation: 174
I have some java code, but searching for more (Pi, Integration, Brute Force MD5hash in Java, some other nice paralelism problem...). Thank you.
Upvotes: -1
Views: 2077
Reputation: 771
If you are still intersting about examples i ve found a pi example in java (mpj) with the package p2pmpi.jar. It s really hard to find parralel source code in java the only solid examples is from mpj express unfortunately.
import p2pmpi.mpi.*;
public class Main {
public static void main(String[] args) {
int rank, size, i;
double pi125dt = 3.141592653589793238462643;
double h, sum, x;
MPI.Init(args);
size = MPI.COMM_WORLD.Size();
rank = MPI.COMM_WORLD.Rank();
int[] n = new int[1];
double[] mypi = new double[1];
double[] pi = new double[1];
if (rank == 0)
n[0] = 1000000; // number of intervals
MPI.COMM_WORLD.Bcast(n, 0, 1, MPI.INT, 0);
h = 1.0 / (double) n[0];
sum = 0.0;
for (i = rank + 1; i <= n[0]; i += size) {
x = h * ((double) i - 0.5);
sum += (4.0 / (1.0 + x * x));
}
mypi[0] = h * sum;
MPI.COMM_WORLD.Reduce(mypi, 0, pi, 0, 1, MPI.DOUBLE, MPI.SUM, 0);
if (rank == 0) {
System.out.println("Po is approximately " + pi[0]);
System.out.println("Error is :" + (pi[0] - pi125dt));
}
MPI.Finalize();
}
}
Upvotes: 1
Reputation: 131
there are some generic example application provided with MPJ Express for testing and learning purposes. You can access them in MPJ_HOME\test\mpi directory. you may or may not get exactly the same applications you specified.
Upvotes: 2