Search in sources :

Example 1 with IntegerForLoop

use of edu.rit.pj.IntegerForLoop in project ffx by mjschnie.

the class SimplePDBMatcher method matchParallel.

public void matchParallel() {
    try {
        new ParallelTeam().execute(new ParallelRegion() {

            @Override
            public void run() throws Exception {
                execute(0, sourceFiles.length, new IntegerForLoop() {

                    @Override
                    public void run(int lb, int ub) {
                        PDBFileReader reader = new PDBFileReader();
                        StructurePairAligner aligner = new StructurePairAligner();
                        for (int i = lb; i <= ub; i++) {
                            File matchFile = matchFiles[i];
                            try {
                                Structure matchStructure = reader.getStructure(matchFiles[i]);
                                String matchName = matchFile.getName();
                                matchedSources[i] = loopOverSources(reader, aligner, matchStructure, matchName);
                            } catch (IOException ex) {
                                logger.warning(String.format(" Matching failed for file %s", matchFile.getName()));
                            }
                        }
                    }
                });
            }
        });
    } catch (Exception ex) {
        logger.severe(" Matching in parallel failed.");
    }
    for (int i = 0; i < matchFiles.length; i++) {
        logger.info(String.format(" Match file %s best source: %s at %11.7f A", matchFiles[i].getName(), matchedSources[i].file.getName(), matchedSources[i].rmsd));
    }
}
Also used : IntegerForLoop(edu.rit.pj.IntegerForLoop) PDBFileReader(org.biojava.bio.structure.io.PDBFileReader) ParallelTeam(edu.rit.pj.ParallelTeam) StructurePairAligner(org.biojava.bio.structure.align.StructurePairAligner) IOException(java.io.IOException) ParallelRegion(edu.rit.pj.ParallelRegion) Structure(org.biojava.bio.structure.Structure) File(java.io.File) IOException(java.io.IOException) StructureException(org.biojava.bio.structure.StructureException)

Example 2 with IntegerForLoop

use of edu.rit.pj.IntegerForLoop in project ffx by mjschnie.

the class Complex3DParallel method main.

/**
 * Test the Complex3DParallel FFT.
 *
 * @param args an array of {@link java.lang.String} objects.
 * @throws java.lang.Exception if any.
 * @since 1.0
 */
public static void main(String[] args) throws Exception {
    int dimNotFinal = 128;
    int ncpu = ParallelTeam.getDefaultThreadCount();
    int reps = 5;
    if (args != null) {
        try {
            dimNotFinal = Integer.parseInt(args[0]);
            if (dimNotFinal < 1) {
                dimNotFinal = 100;
            }
            ncpu = Integer.parseInt(args[1]);
            if (ncpu < 1) {
                ncpu = ParallelTeam.getDefaultThreadCount();
            }
            reps = Integer.parseInt(args[2]);
            if (reps < 1) {
                reps = 5;
            }
        } catch (Exception e) {
        }
    }
    final int dim = dimNotFinal;
    System.out.println(String.format("Initializing a %d cubed grid for %d CPUs.\n" + "The best timing out of %d repititions will be used.", dim, ncpu, reps));
    // One dimension of the serial array divided by the number of threads.
    Complex3D complexDoubleFFT3D = new Complex3D(dim, dim, dim);
    ParallelTeam parallelTeam = new ParallelTeam(ncpu);
    Complex3DParallel parallelComplexDoubleFFT3D = new Complex3DParallel(dim, dim, dim, parallelTeam);
    final int dimCubed = dim * dim * dim;
    final double[] data = new double[dimCubed * 2];
    final double[] work = new double[dimCubed * 2];
    // Parallel Array Initialization.
    try {
        parallelTeam.execute(new ParallelRegion() {

            @Override
            public void run() {
                try {
                    execute(0, dim - 1, new IntegerForLoop() {

                        @Override
                        public void run(final int lb, final int ub) {
                            Random randomNumberGenerator = new Random(1);
                            int index = dim * dim * lb * 2;
                            for (int i = lb; i <= ub; i++) {
                                for (int j = 0; j < dim; j++) {
                                    for (int k = 0; k < dim; k++) {
                                        double randomNumber = randomNumberGenerator.nextDouble();
                                        data[index] = randomNumber;
                                        index += 2;
                                    }
                                }
                            }
                        }
                    });
                } catch (Exception e) {
                    System.out.println(e.toString());
                    System.exit(-1);
                }
            }
        });
    } catch (Exception e) {
        System.out.println(e.toString());
        System.exit(-1);
    }
    double toSeconds = 0.000000001;
    long parTime = Long.MAX_VALUE;
    long seqTime = Long.MAX_VALUE;
    complexDoubleFFT3D.setRecip(work);
    parallelComplexDoubleFFT3D.setRecip(work);
    for (int i = 0; i < reps; i++) {
        System.out.println(String.format("Iteration %d", i + 1));
        long time = System.nanoTime();
        complexDoubleFFT3D.fft(data);
        complexDoubleFFT3D.ifft(data);
        time = (System.nanoTime() - time);
        System.out.println(String.format("Sequential: %8.3f", toSeconds * time));
        if (time < seqTime) {
            seqTime = time;
        }
        time = System.nanoTime();
        complexDoubleFFT3D.convolution(data);
        time = (System.nanoTime() - time);
        System.out.println(String.format("Sequential: %8.3f (Convolution)", toSeconds * time));
        if (time < seqTime) {
            seqTime = time;
        }
        time = System.nanoTime();
        parallelComplexDoubleFFT3D.fft(data);
        parallelComplexDoubleFFT3D.ifft(data);
        time = (System.nanoTime() - time);
        System.out.println(String.format("Parallel:   %8.3f", toSeconds * time));
        if (time < parTime) {
            parTime = time;
        }
        time = System.nanoTime();
        parallelComplexDoubleFFT3D.convolution(data);
        time = (System.nanoTime() - time);
        System.out.println(String.format("Parallel:   %8.3f (Convolution)\n", toSeconds * time));
        if (time < parTime) {
            parTime = time;
        }
    }
    System.out.println(String.format("Best Sequential Time:  %8.3f", toSeconds * seqTime));
    System.out.println(String.format("Best Parallel Time:    %8.3f", toSeconds * parTime));
    System.out.println(String.format("Speedup: %15.5f", (double) seqTime / parTime));
    parallelTeam.shutdown();
}
Also used : IntegerForLoop(edu.rit.pj.IntegerForLoop) ParallelTeam(edu.rit.pj.ParallelTeam) Random(java.util.Random) ParallelRegion(edu.rit.pj.ParallelRegion)

Example 3 with IntegerForLoop

use of edu.rit.pj.IntegerForLoop in project ffx by mjschnie.

the class Real3DParallel method main.

/**
 * Test the real 3D FFT.
 *
 * @param args an array of {@link java.lang.String} objects.
 * @throws java.lang.Exception if any.
 * @since 1.0
 */
public static void main(String[] args) throws Exception {
    int dimNotFinal = 128;
    int ncpu = ParallelTeam.getDefaultThreadCount();
    int reps = 5;
    if (args != null) {
        try {
            dimNotFinal = Integer.parseInt(args[0]);
            if (dimNotFinal < 1) {
                dimNotFinal = 100;
            }
            ncpu = Integer.parseInt(args[1]);
            if (ncpu < 1) {
                ncpu = ParallelTeam.getDefaultThreadCount();
            }
            reps = Integer.parseInt(args[2]);
            if (reps < 1) {
                reps = 5;
            }
        } catch (Exception e) {
        }
    }
    if (dimNotFinal % 2 != 0) {
        dimNotFinal++;
    }
    final int dim = dimNotFinal;
    System.out.println(String.format("Initializing a %d cubed grid for %d CPUs.\n" + "The best timing out of %d repititions will be used.", dim, ncpu, reps));
    Real3D real3D = new Real3D(dim, dim, dim);
    ParallelTeam parallelTeam = new ParallelTeam(ncpu);
    Real3DParallel real3DParallel = new Real3DParallel(dim, dim, dim, parallelTeam);
    final int dimCubed = (dim + 2) * dim * dim;
    final double[] data = new double[dimCubed];
    final double[] work = new double[dimCubed];
    // Parallel Array Initialization.
    try {
        parallelTeam.execute(new ParallelRegion() {

            @Override
            public void run() {
                try {
                    execute(0, dim - 1, new IntegerForLoop() {

                        @Override
                        public void run(int lb, int ub) {
                            Random randomNumberGenerator = new Random(1);
                            int index = dim * dim * lb;
                            for (int z = lb; z <= ub; z++) {
                                for (int y = 0; y < dim; y++) {
                                    for (int x = 0; x < dim; x++) {
                                        double randomNumber = randomNumberGenerator.nextDouble();
                                        data[index] = randomNumber;
                                        index++;
                                    }
                                }
                            }
                        }
                    });
                } catch (Exception e) {
                    System.out.println(e.toString());
                    System.exit(-1);
                }
            }
        });
    } catch (Exception e) {
        System.out.println(e.toString());
        System.exit(-1);
    }
    double toSeconds = 0.000000001;
    long parTime = Long.MAX_VALUE;
    long seqTime = Long.MAX_VALUE;
    real3D.setRecip(work);
    real3DParallel.setRecip(work);
    for (int i = 0; i < reps; i++) {
        System.out.println(String.format("Iteration %d", i + 1));
        long time = System.nanoTime();
        real3D.fft(data);
        real3D.ifft(data);
        time = (System.nanoTime() - time);
        System.out.println(String.format("Sequential: %8.3f", toSeconds * time));
        if (time < seqTime) {
            seqTime = time;
        }
        time = System.nanoTime();
        real3D.convolution(data);
        time = (System.nanoTime() - time);
        System.out.println(String.format("Sequential: %8.3f (Convolution)", toSeconds * time));
        if (time < seqTime) {
            seqTime = time;
        }
        time = System.nanoTime();
        real3DParallel.fft(data);
        real3DParallel.ifft(data);
        time = (System.nanoTime() - time);
        System.out.println(String.format("Parallel:   %8.3f", toSeconds * time));
        if (time < parTime) {
            parTime = time;
        }
        time = System.nanoTime();
        real3DParallel.convolution(data);
        time = (System.nanoTime() - time);
        System.out.println(String.format("Parallel:   %8.3f (Convolution)\n", toSeconds * time));
        if (time < parTime) {
            parTime = time;
        }
    }
    System.out.println(String.format("Best Sequential Time:  %8.3f", toSeconds * seqTime));
    System.out.println(String.format("Best Parallel Time:    %8.3f", toSeconds * parTime));
    System.out.println(String.format("Speedup: %15.5f", (double) seqTime / parTime));
}
Also used : IntegerForLoop(edu.rit.pj.IntegerForLoop) ParallelTeam(edu.rit.pj.ParallelTeam) Random(java.util.Random) ParallelRegion(edu.rit.pj.ParallelRegion)

Aggregations

IntegerForLoop (edu.rit.pj.IntegerForLoop)3 ParallelRegion (edu.rit.pj.ParallelRegion)3 ParallelTeam (edu.rit.pj.ParallelTeam)3 Random (java.util.Random)2 File (java.io.File)1 IOException (java.io.IOException)1 Structure (org.biojava.bio.structure.Structure)1 StructureException (org.biojava.bio.structure.StructureException)1 StructurePairAligner (org.biojava.bio.structure.align.StructurePairAligner)1 PDBFileReader (org.biojava.bio.structure.io.PDBFileReader)1