Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c14ac9f
OpenMP examples using Pyjama in Java: 00 and 01
rkurniawati Aug 5, 2021
98b2cc4
More patternlets
rkurniawati Aug 7, 2021
107c36e
Added Barrier and MasterWorker. Added a Makefile to pull Pyjama lib.
rkurniawati Aug 7, 2021
c929908
Added ParallelLoopEqualChunks
rkurniawati Aug 8, 2021
01a9e86
Added ParallelLoopChunksOf1
rkurniawati Aug 9, 2021
194d287
Added reduction example. Use shared clause instead of static for Spmd…
rkurniawati Aug 10, 2021
769fec9
Removed c source code
rkurniawati Aug 10, 2021
5d84e27
vscode config files
rkurniawati Aug 10, 2021
4a18b1f
Failed attempt for custom reduction
rkurniawati Aug 10, 2021
3b019e3
Using long in the factorial calc and multiplication operator in the r…
rkurniawati Aug 11, 2021
5062258
Use reduction with max function (example from Thomas Hines)
rkurniawati Aug 11, 2021
8815cf2
reduce array size - we run out of heap space with n = 100,000,000
rkurniawati Aug 11, 2021
7c0b881
Fixed Reduction2. Added an example to explore dynamic scheduling
rkurniawati Aug 11, 2021
e8f635c
make class not public to be consistent with other examples
rkurniawati Aug 11, 2021
4775440
Added example on omp section
rkurniawati Aug 11, 2021
3b0349a
Added example of private omp clause
rkurniawati Aug 11, 2021
433d5bd
remove c code
rkurniawati Aug 11, 2021
8842921
Added examples for the critical and atomic clause, with an explanatio…
rkurniawati Aug 11, 2021
2107580
Use ThreadLocalRandom instead of a shared Random
rkurniawati Aug 11, 2021
29e267b
fixed the commented code -- now it is equivalent to the for loop with…
rkurniawati Aug 12, 2021
4b2933b
Added a simpler example of dynamic scheduling
rkurniawati Aug 12, 2021
c8c290e
Removed pyjama patternlets from CSinParallel repo, getting ready to u…
rkurniawati Aug 15, 2021
d7a608b
Added the pyjama submodule
rkurniawati Aug 15, 2021
84bbee8
update submodules
rkurniawati Aug 15, 2021
f80109e
update pyjama submodule
rkurniawati Aug 16, 2021
ba51138
Initial version of Drug Design Exemplar in Java with Pyjama
rkurniawati Aug 29, 2021
d746c1f
Added omp directive, track timing
rkurniawati Aug 29, 2021
687738e
Added rules for DDPyjama
rkurniawati Aug 29, 2021
c50eb71
Minor changes
rkurniawati Aug 29, 2021
7a1ae18
fixed args issue
rkurniawati Aug 29, 2021
8d659e0
Use the latest version of the Pyjama submodule
rkurniawati Aug 29, 2021
4284121
Updated pyjama submodule to the latest version
rkurniawati Dec 1, 2021
055b5eb
added option to skip the canned ligands and print ligands
rkurniawati Dec 1, 2021
a699793
Add longish canned ligands to allow for more imbalance in the dynamic…
rkurniawati Dec 1, 2021
b28795c
shorten the additional ligands
rkurniawati Dec 1, 2021
323c1b3
Let generateLigands to mix canned and random ligands
rkurniawati Dec 6, 2021
0a57cab
Removed the additional longer ligands. Fixed comments.
rkurniawati Dec 6, 2021
7061576
Removed the additional longer ligands
rkurniawati Dec 6, 2021
e88a186
Fixed usage instruction
rkurniawati Dec 6, 2021
924242a
don't create zero length ligands
rkurniawati Mar 16, 2022
12c04fa
remove *.class files
rkurniawati Mar 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "Patternlets/MPI/notebook"]
path = Patternlets/MPI/notebook
url = https://github.com/rkurniawati/mpiC.git
[submodule "Patternlets/pyjama"]
path = Patternlets/pyjama
url = https://github.com/rkurniawati/pyjama-patternlets.git
157 changes: 157 additions & 0 deletions Exemplars/DrugDesign/DDPyjama.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import java.util.Random;

public class DDPyjama {
static Random rand = new Random(42);

static String[] cannedLigands =
{"razvex", "qudgy", "afrs", "sst", "pgfht", "rt",
"id", "how", "aaddh", "df", "os", "hid",
"sad", "fl", "rd", "edp", "dfgt", "spa"};

// Ligand Score pair
static class LSPair {
String ligand;
int score;

public LSPair(String ligand, int score) {
this.ligand = ligand;
this.score = score;
}

@Override
public String toString() {
return "["+ligand+","+score+"]";
}
}

// returns arbitrary string of lower-case letters of length at most max_ligand
static String makeLigand(int maxLigandLength) {

int len = rand.nextInt(maxLigandLength+1);
if (len == 0) len++; // don't create a 0-character ligand

StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++)
sb.append((char) ('a' + rand.nextInt(26)));
return sb.toString();
}

private static String[] generateLigands(int numLigands, int maxLigandLength, boolean useCanned) {
// If we use canned ligands, use as many of them as we can, then fill the rest with randomly generated ligands.
// Otherwise, create a set of ligands whose length randomly varies from 1 to args.maxLigand

String[] result = new String[numLigands];

if (useCanned) {
for(int i = 0; i < Math.min(numLigands, cannedLigands.length); i++) {
result[i] = cannedLigands[i];
}
}

for(int i = useCanned ? cannedLigands.length : 0; i < numLigands; i++) {
result[i] = makeLigand(maxLigandLength);
}
return result;
}

public static void main(String[] args) {

if (args.length != 4) {
System.out.println("Usage DDPyjama numThreads numLigands maxLigandLength protein useCanned printLigands");

// the example string below is one of Dijkstra's famous quotes
System.out.println(" Example: java -cp .:Pyjama.jar DDPyjama 4 10 8 \"Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it\" false true\n");
}

int numThreads = 4;
if (args.length >= 1) {
numThreads = Integer.parseInt(args[0]);
}

int numLigands = 12;
if (args.length >= 2) {
numLigands = Integer.parseInt(args[1]);
}

int maxLigandLength = 6;
if (args.length >= 3) {
maxLigandLength = Integer.parseInt(args[2]);
}

String protein = "the cat in the hat wore the hat to the cat hat party";

if (args.length >= 4) {
protein = args[3];
}

System.out.println("Number of threads: " + numThreads);
System.out.println("Number of ligands: "+numLigands);
System.out.println("Max ligand length: "+ maxLigandLength);
System.out.println("Protein: "+ protein);
System.out.println();

// Things to do:
// 1. Generate the requested numLigands w/ maxLigandLength
// 2. Calculate the matching score for each ligand vs the given protein
// Score is calculated based on the number of character in the ligand that
// appears in the same order in the protein.
// 3. Find the ligand(s) with the highest score

long start = System.currentTimeMillis();
String[] ligands = generateLigands(numLigands, maxLigandLength, args.length >= 5 && args[4].equals("true"));

// print the ligands if desired
if (args.length >= 6 && args[5].equals("true")) {
System.out.println("Here are the ligands");
for(String l : ligands) {
System.out.println(l);
}
}

// map each ligand to (ligand, score)
// also keep track of the maxScore
LSPair[] ligandsWScore = new LSPair[numLigands];
int maxScore = 0;

//#omp parallel for num_threads(numThreads) shared(numLigands, ligands, ligandsWScore, protein) reduction(max:maxScore) schedule(dynamic)
for(int i = 0; i < numLigands; i++) {
String ligand = ligands[i];
int score = calcScore(ligand, protein);
ligandsWScore[i] = new LSPair(ligand, score);
maxScore = Math.max(maxScore, score);
}

// find the ligands whose score is maxScore
// this is a reduce operation
StringBuilder sb = new StringBuilder();
for(int i = 0; i < numLigands; i++) {
if (ligandsWScore[i].score == maxScore) {
if (sb.length() > 0) sb.append(", ");
sb.append(ligandsWScore[i].ligand);
}
}

long end = System.currentTimeMillis();
System.out.println("The maximum score is " + maxScore);
System.out.println("Achieved by ligand(s) "+ sb.toString());
System.out.println("Calculation time " + (end-start) + " ms");
}

/**
* Match a ligand (str1) and the protein. Count the number of characters in str1
* that appear in the same seq in str2 (there can be any number of intervening chars)
* @param str1 first string
* @param str2 second string
* @return number of matches
*/
private static int calcScore(String str1, String str2) {
// no match if either is empty string
if (str1.length() == 0 || str2.length() == 0) return 0;

if (str1.charAt(0) == str2.charAt(0)) {
return 1 + calcScore(str1.substring(1), str2.substring(1));
}
return Math.max(
calcScore(str1, str2.substring(1)), calcScore(str1.substring(1), str2));
}
}
14 changes: 13 additions & 1 deletion Exemplars/DrugDesign/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ dd_threads: dd_threads.cpp
dd_mpi: dd_mpi.cpp
mpiCC -std=c++11 -o dd_mpi dd_mpi.cpp

Pyjama.jar:
wget https://www.csc.tntech.edu/pdcincs/resources/modules/tools/updated/Pyjama.zip
unzip -o Pyjama.zip
cp Pyjama/Pyjama*.jar Pyjama.jar
rm -r -f Pyjama.zip Pyjama

DDPyjama.class: DDPyjama.java Pyjama.jar
java -jar Pyjama.jar DDPyjama.java

DDPyjama: DDPyjama.class
java -cp .:Pyjama.jar DDPyjama $(ARGS)

clean:
rm -f dd_serial dd_omp_static dd_omp_dynamic dd_threads dd_mpi
rm -f dd_serial dd_omp_static dd_omp_dynamic dd_threads dd_mpi Pyjama.jar DDPyjama*class

2 changes: 1 addition & 1 deletion Patternlets/MPI/notebook
Submodule notebook updated 1 files
+674 −0 LICENSE
2 changes: 1 addition & 1 deletion Patternlets/java-OpenMPI/notebook
Submodule notebook updated 1 files
+674 −0 LICENSE
1 change: 1 addition & 0 deletions Patternlets/pyjama
Submodule pyjama added at f2d452