forked from JavaTX/JavaCompilerCore
option for parallelization
This commit is contained in:
parent
863bfa40d3
commit
8780d5d47a
@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference.unify;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
@ -10,6 +11,7 @@ import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
@ -47,6 +49,8 @@ public class TypeUnify {
|
||||
*/
|
||||
protected IRuleSet rules = new RuleSet();
|
||||
|
||||
protected boolean parallel = true;
|
||||
|
||||
/**
|
||||
* Computes all principal type unifiers for a set of constraints.
|
||||
* @param eq The set of constraints
|
||||
@ -110,7 +114,7 @@ public class TypeUnify {
|
||||
|
||||
// Sub cartesian products of the second level (pattern matched) sets
|
||||
// "the big (x)"
|
||||
// TODO Optimierungsmöglichkeit: Parallelisierung der Schleife möglich
|
||||
// TODO Optimierungsmöglichkeit: Parallelisierung der Schleife möglich (scheint sich nicht zu lohnen)
|
||||
for(Set<Set<Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
|
||||
List<Set<Set<UnifyPair>>> secondLevelSetList = new ArrayList<>(secondLevelSet);
|
||||
Set<List<Set<UnifyPair>>> cartResult = setOps.cartesianProduct(secondLevelSetList);
|
||||
@ -133,7 +137,7 @@ public class TypeUnify {
|
||||
//System.out.println(result);
|
||||
|
||||
// Flatten the cartesian product
|
||||
// TODO parallelisierung möglich
|
||||
// TODO parallelisierung möglich (scheint sich nicht zu lohnen)
|
||||
Set<Set<UnifyPair>> eqPrimeSetFlat = new HashSet<>();
|
||||
for(Set<Set<UnifyPair>> setToFlatten : eqPrimeSet) {
|
||||
Set<UnifyPair> buffer = new HashSet<>();
|
||||
@ -148,15 +152,33 @@ public class TypeUnify {
|
||||
Set<Set<UnifyPair>> restartSet = new HashSet<>();
|
||||
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
||||
|
||||
for(Set<UnifyPair> eqPrime : eqPrimeSetFlat) {
|
||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||
|
||||
if(parallel) {
|
||||
Set<Set<UnifyPair>> restartSetSync = Collections.synchronizedSet(restartSet);
|
||||
Set<Set<UnifyPair>> eqPrimePrimeSetSync = Collections.synchronizedSet(eqPrimePrimeSet);
|
||||
|
||||
if (eqPrime.equals(eq))
|
||||
eqPrimePrimeSet.add(eqPrime);
|
||||
else if(eqPrimePrime.isPresent())
|
||||
restartSet.add(eqPrimePrime.get());
|
||||
else
|
||||
restartSet.add(eqPrime);
|
||||
eqPrimeSetFlat.parallelStream().forEach(eqPrime -> {
|
||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||
|
||||
if (eqPrime.equals(eq))
|
||||
eqPrimePrimeSetSync.add(eqPrime);
|
||||
else if(eqPrimePrime.isPresent())
|
||||
restartSetSync.add(eqPrimePrime.get());
|
||||
else
|
||||
restartSetSync.add(eqPrime);
|
||||
});
|
||||
}
|
||||
else {
|
||||
for(Set<UnifyPair> eqPrime : eqPrimeSetFlat) {
|
||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||
|
||||
if (eqPrime.equals(eq))
|
||||
eqPrimePrimeSet.add(eqPrime);
|
||||
else if(eqPrimePrime.isPresent())
|
||||
restartSet.add(eqPrimePrime.get());
|
||||
else
|
||||
restartSet.add(eqPrime);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -164,10 +186,16 @@ public class TypeUnify {
|
||||
* b) Build the union over everything
|
||||
*/
|
||||
// TODO parallelisierung möglich (lohnt sich vermutlich)
|
||||
for(Set<UnifyPair> eqss : restartSet)
|
||||
eqPrimePrimeSet.addAll(this.unify(eqss, fc));
|
||||
/*restartSet.parallelStream().forEach(
|
||||
x -> eqPrimePrimeSet.addAll(unify(x, fc)));*/
|
||||
|
||||
if(parallel) {
|
||||
Set<Set<UnifyPair>> eqPrimePrimeSetSync = Collections.synchronizedSet(eqPrimePrimeSet);
|
||||
restartSet.parallelStream().forEach( x -> eqPrimePrimeSetSync.addAll(unify(x, fc)));
|
||||
}
|
||||
else {
|
||||
for(Set<UnifyPair> eqss : restartSet)
|
||||
eqPrimePrimeSet.addAll(this.unify(eqss, fc));
|
||||
}
|
||||
|
||||
/*
|
||||
* Step 7: Filter empty sets;
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user