use of edu.rit.pj.ParallelTeam 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));
}
}
use of edu.rit.pj.ParallelTeam in project ffx by mjschnie.
the class CrystalReciprocalSpaceTest method test1N7SPermanent.
/**
* Test of permanent method, of class CrystalReciprocalSpace.
*/
@Test
public void test1N7SPermanent() {
String filename = "ffx/xray/structures/1N7S.pdb";
int index = filename.lastIndexOf(".");
String name = filename.substring(0, index);
// load the structure
ClassLoader cl = this.getClass().getClassLoader();
File structure = new File(cl.getResource(filename).getPath());
PotentialsUtils potutil = new PotentialsUtils();
MolecularAssembly mola = potutil.open(structure);
CompositeConfiguration properties = mola.getProperties();
Crystal crystal = new Crystal(39.767, 51.750, 132.938, 90.00, 90.00, 90.00, "P212121");
Resolution resolution = new Resolution(1.45);
ReflectionList reflectionList = new ReflectionList(crystal, resolution);
DiffractionRefinementData refinementData = new DiffractionRefinementData(properties, reflectionList);
mola.finalize(true, mola.getForceField());
ForceFieldEnergy energy = mola.getPotentialEnergy();
List<Atom> atomList = mola.getAtomList();
Atom[] atomArray = atomList.toArray(new Atom[atomList.size()]);
// set up FFT and run it
ParallelTeam parallelTeam = new ParallelTeam();
CrystalReciprocalSpace crs = new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam);
crs.computeAtomicDensity(refinementData.fc);
// tests
ComplexNumber b = new ComplexNumber(-828.584, -922.704);
HKL hkl = reflectionList.getHKL(1, 1, 4);
ComplexNumber a = refinementData.getFc(hkl.index());
System.out.println("1 1 4: " + a.toString() + " | " + b.toString() + " | " + a.divides(b).toString());
assertEquals("1 1 4 reflection should be correct", -753.4722104328416, a.re(), 0.0001);
assertEquals("1 1 4 reflection should be correct", -1012.1341308707799, a.im(), 0.0001);
b.re(-70.4582);
b.im(-486.142);
hkl = reflectionList.getHKL(2, 1, 10);
a = refinementData.getFc(hkl.index());
System.out.println("2 1 10: " + a.toString() + " | " + b.toString() + " | " + a.divides(b).toString());
assertEquals("2 1 10 reflection should be correct", -69.39660884054359, a.re(), 0.0001);
assertEquals("2 1 10 reflection should be correct", -412.0147625765328, a.im(), 0.0001);
}
use of edu.rit.pj.ParallelTeam in project ffx by mjschnie.
the class Real3DCuda method main.
/**
* <p>
* main</p>
*
* @param args an array of {@link java.lang.String} objects.
* @throws java.lang.Exception if any.
*/
public static void main(String[] args) throws Exception {
int dimNotFinal = 64;
int reps = 10;
if (args != null) {
try {
dimNotFinal = Integer.parseInt(args[0]);
if (dimNotFinal < 1) {
dimNotFinal = 64;
}
reps = Integer.parseInt(args[1]);
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.\n" + "The best timing out of %d repititions will be used.", dim, reps));
final int dimCubed = dim * dim * dim;
final int dimCubed2 = (dim + 2) * dim * dim;
/**
* Create an array to save the initial input and result.
*/
final double[] orig = new double[dimCubed2];
final double[] answer = new double[dimCubed2];
final double[] data = new double[dimCubed2];
final double[] recip = new double[dimCubed];
final float[] origf = new float[dimCubed2];
final float[] dataf = new float[dimCubed2];
final float[] recipf = new float[dimCubed];
Random randomNumberGenerator = new Random(1);
int index = 0;
int index2 = 0;
/**
* Row-major order.
*/
for (int x = 0; x < dim; x++) {
for (int y = 0; y < dim; y++) {
for (int z = 0; z < dim; z++) {
float randomNumber = randomNumberGenerator.nextFloat();
orig[index] = randomNumber;
origf[index] = randomNumber;
index++;
recip[index2] = 1.0;
recipf[index2] = 1.0f;
index2++;
}
// Padding
index += 2;
}
}
Real3D real3D = new Real3D(dim, dim, dim);
Real3DParallel real3DParallel = new Real3DParallel(dim, dim, dim, new ParallelTeam(), IntegerSchedule.fixed());
Real3DCuda real3DCUDA = new Real3DCuda(dim, dim, dim, dataf, recipf);
Thread cudaThread = new Thread(real3DCUDA);
cudaThread.setPriority(Thread.MAX_PRIORITY);
cudaThread.start();
double toSeconds = 0.000000001;
long parTime = Long.MAX_VALUE;
long seqTime = Long.MAX_VALUE;
long clTime = Long.MAX_VALUE;
real3D.setRecip(recip);
for (int i = 0; i < reps; i++) {
System.arraycopy(orig, 0, data, 0, dimCubed2);
long time = System.nanoTime();
real3D.convolution(data);
time = (System.nanoTime() - time);
System.out.println(String.format("%2d Sequential: %8.3f", i + 1, toSeconds * time));
if (time < seqTime) {
seqTime = time;
}
}
System.arraycopy(data, 0, answer, 0, dimCubed2);
real3DParallel.setRecip(recip);
for (int i = 0; i < reps; i++) {
System.arraycopy(orig, 0, data, 0, dimCubed2);
long time = System.nanoTime();
real3DParallel.convolution(data);
time = (System.nanoTime() - time);
System.out.println(String.format("%2d Parallel: %8.3f", i + 1, toSeconds * time));
if (time < parTime) {
parTime = time;
}
}
double maxError = Double.MIN_VALUE;
double rmse = 0.0;
index = 0;
for (int x = 0; x < dim; x++) {
for (int y = 0; y < dim; y++) {
for (int z = 0; z < dim; z++) {
double error = Math.abs((orig[index] - data[index] / dimCubed));
if (error > maxError) {
maxError = error;
}
rmse += error * error;
index++;
}
index += 2;
}
}
rmse /= dimCubed;
rmse = Math.sqrt(rmse);
logger.info(String.format("Parallel RMSE: %12.10f, Max: %12.10f", rmse, maxError));
for (int i = 0; i < reps; i++) {
System.arraycopy(origf, 0, dataf, 0, dimCubed2);
long time = System.nanoTime();
real3DCUDA.convolution(dataf);
time = (System.nanoTime() - time);
System.out.println(String.format("%2d CUDA: %8.3f", i + 1, toSeconds * time));
if (time < clTime) {
clTime = time;
}
}
real3DCUDA.free();
real3DCUDA = null;
maxError = Double.MIN_VALUE;
double avg = 0.0;
rmse = 0.0;
index = 0;
for (int x = 0; x < dim; x++) {
for (int y = 0; y < dim; y++) {
for (int z = 0; z < dim; z++) {
if (Float.isNaN(dataf[index])) {
logger.info(String.format("Not a number %d %d %d", x, y, z));
System.exit(-1);
}
double error = Math.abs(origf[index] - dataf[index]);
avg += error;
if (error > maxError) {
maxError = error;
}
rmse += error * error;
index++;
}
index += 2;
}
}
rmse /= dimCubed;
avg /= dimCubed;
rmse = Math.sqrt(rmse);
logger.info(String.format("CUDA RMSE: %12.10f, Max: %12.10f, Avg: %12.10f", rmse, maxError, avg));
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("Best CUDA Time: %8.3f", toSeconds * clTime));
System.out.println(String.format("Parallel Speedup: %15.5f", (double) seqTime / parTime));
System.out.println(String.format("CUDA Speedup: %15.5f", (double) seqTime / clTime));
}
use of edu.rit.pj.ParallelTeam in project ffx by mjschnie.
the class RotamerOptimization method computeEnergy.
/**
* Uses existing backbone, self, 2-Body, and 3-body energies from
* rotamerEnergies() to calculate an approximate energy for a rotamer
* permutation.
*
* @param residues Current window of optimization.
* @param rotamers Set of rotamers to calculate an approximate energy for.
* @param print Verbosity flag
* @return Approximate permutation energy (backbone + selfs + pairs +
* trimers).
*/
private double computeEnergy(Residue[] residues, int[] rotamers, boolean print) {
double selfSum = 0.0;
double pairSum = 0.0;
double threeBodySum = 0.0;
try {
if (parallelTeam == null) {
parallelTeam = new ParallelTeam();
}
if (energyRegion == null) {
energyRegion = new EnergyRegion(parallelTeam.getThreadCount());
}
energyRegion.init(residues, rotamers);
parallelTeam.execute(energyRegion);
selfSum = energyRegion.getSelf();
pairSum = energyRegion.getTwoBody();
threeBodySum = energyRegion.getThreeBody();
} catch (Exception e) {
// logger.log(Level.WARNING, " Exception in EnergyRegion.", e);
throw new IllegalArgumentException(e);
}
double approximateEnergy = backboneEnergy + selfSum + pairSum + threeBodySum;
if (print) {
logger.info(format(" Backbone: %s", formatEnergy(backboneEnergy)));
logger.info(format(" Self Energy: %s", formatEnergy(selfSum)));
logger.info(format(" Pair Energy: %s", formatEnergy(pairSum)));
if (!threeBodyTerm) {
logger.info(format(" Total Energy up to 2-Body: %s", formatEnergy(approximateEnergy)));
} else {
logger.info(format(" 3-Body Energy: %s", formatEnergy(threeBodySum)));
logger.info(format(" Total Energy up to 3-Body: %s", formatEnergy(approximateEnergy)));
}
}
return approximateEnergy;
}
use of edu.rit.pj.ParallelTeam in project ffx by mjschnie.
the class RotamerOptimization method goldsteinPairElimination.
/**
* Attempt to eliminate rotamer pair (ResI-RotA, ResJ-RotC) using
* (ResI-RotB, ResJ-RotD).
*
* @param residues
* @param i Index of the first residue.
* @param riA Index of the first residue's rotamer to eliminate.
* @param riB Index of the first residue's rotamer to use for elimination.
* @param j Index of the 2nd residue.
* @param rjC Index of the 2nd residue's rotamer to eliminate.
* @param rjD Index of the 2nd residue's rotamer to use for elimination.
* @return Return true if eliminated.
*/
private boolean goldsteinPairElimination(Residue[] residues, int i, int riA, int riB, int j, int rjC, int rjD) {
ArrayList<Residue> missedResidues = null;
// Initialize the Goldstein energy.
double goldsteinEnergy = getSelf(i, riA) + getSelf(j, rjC) + get2Body(i, riA, j, rjC) - getSelf(i, riB) - getSelf(j, rjD) - get2Body(i, riB, j, rjD);
try {
if (parallelTeam == null) {
parallelTeam = new ParallelTeam();
}
if (goldsteinPairRegion == null) {
goldsteinPairRegion = new GoldsteinPairRegion(parallelTeam.getThreadCount());
}
goldsteinPairRegion.init(residues, i, riA, riB, j, rjC, rjD);
parallelTeam.execute(goldsteinPairRegion);
goldsteinEnergy += goldsteinPairRegion.getSumOverK();
missedResidues = goldsteinPairRegion.getMissedResidues();
} catch (Exception e) {
logger.log(Level.WARNING, " Exception in GoldsteinPairRegion.", e);
}
// goldsteinEnergy += goldsteinPairSumOverK(residues, 0, nres-1, i, riA, riB, j, rjC, rjD);
if (missedResidues != null && !missedResidues.isEmpty()) {
logIfMaster(format(" Skipping energy comparison due to a missed residue: i %d riA %d riB %d j %d rjC %d rjD %d", i, riA, riB, j, rjC, rjD), Level.FINE);
return false;
}
if (goldsteinEnergy > ensembleBuffer) {
if (missedResidues.isEmpty()) {
if (eliminateRotamerPair(residues, i, riA, j, rjC, print)) {
logIfMaster(format(" Pair elimination of [(%8s,%2d),(%8s,%2d)] by [(%8s,%2d),(%8s,%2d)]: %12.4f > %6.4f", residues[i].toFormattedString(false, true), riA, residues[j].toFormattedString(false, true), rjC, residues[i].toFormattedString(false, true), riB, residues[j].toFormattedString(false, true), rjD, goldsteinEnergy, ensembleBuffer));
return true;
}
} else {
logIfMaster(format(" No Pair elimination of [(%8s,%2d),(%8s,%2d)] by [(%8s,%2d),(%8s,%2d)]: %12.4f > %6.4f", residues[i].toFormattedString(false, true), riA, residues[j].toFormattedString(false, true), rjC, residues[i].toFormattedString(false, true), riB, residues[j].toFormattedString(false, true), rjD, goldsteinEnergy, ensembleBuffer));
StringBuffer sb = new StringBuffer();
for (int m = 0; m < missedResidues.size(); m++) {
Residue residueM = missedResidues.get(m);
sb.append(residueM);
}
logIfMaster(format(" due to %s.", sb));
}
}
return false;
}
Aggregations