modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java
modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Threads soweit fertig
This commit is contained in:
parent
26634bb038
commit
9e1d58f4b1
@ -29,6 +29,7 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
return new HashSet<>(); }
|
return new HashSet<>(); }
|
||||||
else
|
else
|
||||||
*/
|
*/
|
||||||
|
noOfThread--;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,11 +59,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/**
|
/**
|
||||||
* Fuer die Threads
|
* Fuer die Threads
|
||||||
*/
|
*/
|
||||||
private static int noOfThread = 0;
|
protected static int noOfThread = 0;
|
||||||
private static int totalnoOfThread = 0;
|
private static int totalnoOfThread = 0;
|
||||||
int thNo;
|
int thNo;
|
||||||
protected boolean one = false;
|
protected boolean one = false;
|
||||||
Integer MaxNoOfThreads = 4;
|
Integer MaxNoOfThreads = 8;
|
||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
||||||
FileWriter logFile;
|
FileWriter logFile;
|
||||||
@ -200,6 +200,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
.filter(x -> x.size()>1)
|
.filter(x -> x.size()>1)
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField);
|
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField);
|
||||||
|
noOfThread--;
|
||||||
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
||||||
else return res;
|
else return res;
|
||||||
}
|
}
|
||||||
@ -891,7 +892,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//for(Set<UnifyPair> a : newSet) {
|
//for(Set<UnifyPair> a : newSet) {
|
||||||
i++;
|
i++;
|
||||||
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
|
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
|
||||||
writeLog("a1: " + rekTiefe + " "+ a.toString()+ "\n");
|
writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n");
|
||||||
//elems.add(a); PL 2019-01-20 Muss weg, weil das in jeweiligen Thread erfolgen muss. Fuer den sequentiellen Fall
|
//elems.add(a); PL 2019-01-20 Muss weg, weil das in jeweiligen Thread erfolgen muss. Fuer den sequentiellen Fall
|
||||||
//im else-Zweig
|
//im else-Zweig
|
||||||
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
|
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
|
||||||
@ -899,28 +900,17 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> res = new HashSet<>();
|
Set<Set<UnifyPair>> res = new HashSet<>();
|
||||||
Set<Set<Set<UnifyPair>>> add_res = new HashSet<>();
|
Set<Set<Set<UnifyPair>>> add_res = new HashSet<>();
|
||||||
if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) {
|
if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) {
|
||||||
/*
|
|
||||||
elems.add(a);
|
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log);
|
|
||||||
fork.fork();
|
|
||||||
res = fork.join();
|
|
||||||
*/
|
|
||||||
|
|
||||||
Set<TypeUnifyTask> forks = new HashSet<>();
|
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||||
|
|
||||||
//TypeUnify2Task fork1 = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log);
|
|
||||||
|
|
||||||
|
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
writeLog("a in " + variance + " "+ a);
|
writeLog("a in " + variance + " "+ a);
|
||||||
@ -939,23 +929,23 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
/* FORK ANFANG
|
/* FORK ANFANG */
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
res = forkOrig.join();
|
res = forkOrig.join();
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
||||||
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
||||||
noOfThread--;
|
//noOfThread--; an das Ende von compute verschoben
|
||||||
//add_res.add(fork_res);
|
//add_res.add(fork_res);
|
||||||
};
|
};
|
||||||
FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
for(TypeUnifyTask fork : forks) {
|
for(TypeUnifyTask fork : forks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||||
writeLog("Join " + new Integer(fork.thNo).toString());
|
writeLog("Join " + new Integer(fork.thNo).toString());
|
||||||
noOfThread--;
|
//noOfThread--; an das Ende von compute verschoben
|
||||||
add_res.add(fork_res);
|
add_res.add(fork_res);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -967,11 +957,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
writeLog("a in " + variance + " "+ a);
|
writeLog("a in " + variance + " "+ a);
|
||||||
@ -990,23 +980,23 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
/* FORK ANFANG
|
/* FORK ANFANG */
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
res = forkOrig.join();
|
res = forkOrig.join();
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
||||||
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
||||||
noOfThread--;
|
//noOfThread--; an das Ende von compute verschoben
|
||||||
//add_res.add(fork_res);
|
//add_res.add(fork_res);
|
||||||
};
|
};
|
||||||
FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
for(TypeUnifyTask fork : forks) {
|
for(TypeUnifyTask fork : forks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||||
writeLog("Join " + new Integer(fork.thNo).toString());
|
writeLog("Join " + new Integer(fork.thNo).toString());
|
||||||
noOfThread--;
|
//noOfThread--; an das Ende von compute verschoben
|
||||||
add_res.add(fork_res);
|
add_res.add(fork_res);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -1019,11 +1009,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
writeLog("a in " + variance + " "+ a);
|
writeLog("a in " + variance + " "+ a);
|
||||||
@ -1040,23 +1030,23 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
/* FORK ANFANG
|
/* FORK ANFANG */
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
res = forkOrig.join();
|
res = forkOrig.join();
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
||||||
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
||||||
noOfThread--;
|
//noOfThread--; an das Ende von compute verschoben
|
||||||
//add_res.add(fork_res); //vermutlich falsch
|
//add_res.add(fork_res); //vermutlich falsch
|
||||||
};
|
};
|
||||||
FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
for(TypeUnifyTask fork : forks) {
|
for(TypeUnifyTask fork : forks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||||
writeLog("Join " + new Integer(fork.thNo).toString());
|
writeLog("Join " + new Integer(fork.thNo).toString());
|
||||||
noOfThread--;
|
//noOfThread--; an das Ende von compute verschoben
|
||||||
add_res.add(fork_res);
|
add_res.add(fork_res);
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
|
@ -109,6 +109,18 @@ implements IFiniteClosure {
|
|||||||
strInheritanceGraph.get(key.getName()).add(inheritanceGraph.get(key));
|
strInheritanceGraph.get(key.getName()).add(inheritanceGraph.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testSmaller() {
|
||||||
|
UnifyType tq1, tq2, tq3;
|
||||||
|
tq1 = new ExtendsType(PlaceholderType.freshPlaceholder());
|
||||||
|
List<UnifyType> l1 = new ArrayList<>();
|
||||||
|
List<UnifyType> l2 = new ArrayList<>();
|
||||||
|
l1.add(tq1);
|
||||||
|
tq2 = new ReferenceType("java.util.Vector", new TypeParams(l1));
|
||||||
|
l2.add(tq2);
|
||||||
|
tq3 = new ReferenceType("java.util.Vector", new TypeParams(l2));
|
||||||
|
Set<UnifyType> smaller = smaller(tq3, new HashSet<>());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all types of the finite closure that are subtypes of the argument.
|
* Returns all types of the finite closure that are subtypes of the argument.
|
||||||
@ -641,8 +653,7 @@ implements IFiniteClosure {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
||||||
if ((left instanceof ExtendsType && right instanceof ReferenceType)
|
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||||
|| (right instanceof ExtendsType && left instanceof ReferenceType))
|
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
/*
|
/*
|
||||||
List<UnifyType> al = new ArrayList<>();
|
List<UnifyType> al = new ArrayList<>();
|
||||||
@ -693,6 +704,13 @@ implements IFiniteClosure {
|
|||||||
HashSet<UnifyPair> hs = new HashSet<>();
|
HashSet<UnifyPair> hs = new HashSet<>();
|
||||||
hs.add(up);
|
hs.add(up);
|
||||||
Set<UnifyPair> smallerRes = unifyTask.applyTypeUnificationRules(hs, this);
|
Set<UnifyPair> smallerRes = unifyTask.applyTypeUnificationRules(hs, this);
|
||||||
|
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||||
|
{try {
|
||||||
|
logFile.write("\nsmallerRes: " + smallerRes);//"smallerHash: " + greaterHash.toString());
|
||||||
|
logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("no LogFile");}}
|
||||||
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
||||||
long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count();
|
long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count();
|
||||||
if (smallerLen == 0) return -1;
|
if (smallerLen == 0) return -1;
|
||||||
@ -702,6 +720,13 @@ implements IFiniteClosure {
|
|||||||
hs = new HashSet<>();
|
hs = new HashSet<>();
|
||||||
hs.add(up);
|
hs.add(up);
|
||||||
Set<UnifyPair> greaterRes = unifyTask.applyTypeUnificationRules(hs, this);
|
Set<UnifyPair> greaterRes = unifyTask.applyTypeUnificationRules(hs, this);
|
||||||
|
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||||
|
{try {
|
||||||
|
logFile.write("\ngreaterRes: " + greaterRes);//"smallerHash: " + greaterHash.toString());
|
||||||
|
logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("no LogFile");}}
|
||||||
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
||||||
long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count();
|
long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count();
|
||||||
if (greaterLen == 0) return 1;
|
if (greaterLen == 0) return 1;
|
||||||
|
@ -229,7 +229,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) {
|
if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) {
|
||||||
hm = rsleuni.stream().reduce(new HashMap<UnifyType,UnifyPair>(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner);
|
hm = rsleuni.stream().reduce(new HashMap<UnifyType,UnifyPair>(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner);
|
||||||
Stream<UnifyPair> lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getLhsType()) == null));
|
Stream<UnifyPair> lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getLhsType()) == null));
|
||||||
si = lslewcstr.map(x -> fc.compare(x.getRhsType(), hm.get(x.getLhsType()).getRhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } );
|
si = lslewcstr.map(x -> fc.compare(x.getRhsType(), hm.get(x.getLhsType()).getRhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } );
|
||||||
}
|
}
|
||||||
//4. Fall
|
//4. Fall
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user