From dc803bd6b86b346cece1bb07b8a7a7df9027c32a Mon Sep 17 00:00:00 2001 From: NoName11234 <47484268+NoName11234@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:49:39 +0200 Subject: [PATCH 1/2] changed parameters of forkjoinpools --- .../de/dhbwstuttgart/typeinference/unify/TypeUnify.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index a011aa9..f988235 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -30,7 +30,7 @@ public class TypeUnify { */ public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); - ForkJoinPool pool = new ForkJoinPool(); + ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); pool.invoke(unifyTask); Set> res = unifyTask.join(); try { @@ -56,7 +56,7 @@ public class TypeUnify { */ public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); - ForkJoinPool pool = new ForkJoinPool(); + ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); pool.invoke(unifyTask); return ret; } @@ -75,7 +75,7 @@ public class TypeUnify { public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks, statistics); - ForkJoinPool pool = new ForkJoinPool(); + ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); pool.invoke(unifyTask); Set> res = unifyTask.join(); try { From dd62d8d6b9da4e3985f1056146f6855cfdbbdc71 Mon Sep 17 00:00:00 2001 From: NoName11234 <47484268+NoName11234@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:50:14 +0200 Subject: [PATCH 2/2] removed thread counter variables from typeunifytask --- .../typeinference/unify/TypeUnifyTask.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index ff9e6cd..c24632d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -74,11 +74,9 @@ public class TypeUnifyTask extends RecursiveTask>> { * Fuer die Threads */ UnifyResultModel urm; - protected static int noOfThread = 0; private static int totalnoOfThread = 0; int thNo; protected boolean one = false; - Integer MaxNoOfThreads = 128; public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; Writer logFile; @@ -179,8 +177,7 @@ public class TypeUnifyTask extends RecursiveTask>> { this.parallel = parallel; this.logFile = logFile; this.log = log; - - noOfThread++; + totalnoOfThread++; //writeLog("thNo1 " + thNo); thNo = totalnoOfThread; @@ -269,7 +266,6 @@ public class TypeUnifyTask extends RecursiveTask>> { .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, new HashSet<>()); - noOfThread--; try { logFile.close(); } @@ -924,7 +920,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /* Wenn parallel gearbeitet wird, wird je nach Varianz ein neuer Thread * gestartet, der parallel weiterarbeitet. */ - if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { + if(parallel && (variance == 1)) { Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); @@ -984,7 +980,6 @@ public class TypeUnifyTask extends RecursiveTask>> { /* FORK ANFANG */ synchronized (this) { writeLog("wait "+ forkOrig.thNo); - noOfThread--; res = forkOrig.join(); synchronized (usedTasks) { if (this.myIsCancelled()) { @@ -1004,7 +999,6 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.forEach(x -> writeLog("wait: " + x.thNo)); for(TypeUnify2Task fork : forks) { synchronized (this) { - noOfThread--; Set> fork_res = fork.join(); synchronized (usedTasks) { if (this.myIsCancelled()) { @@ -1026,7 +1020,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } //noOfThread++; } else { - if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) { + if(parallel && (variance == -1)) { Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); @@ -1085,7 +1079,6 @@ public class TypeUnifyTask extends RecursiveTask>> { /* FORK ANFANG */ synchronized (this) { writeLog("wait "+ forkOrig.thNo); - noOfThread--; res = forkOrig.join(); synchronized (usedTasks) { if (this.myIsCancelled()) { @@ -1105,7 +1098,6 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.forEach(x -> writeLog("wait: " + x.thNo)); for(TypeUnify2Task fork : forks) { synchronized (this) { - noOfThread--; Set> fork_res = fork.join(); synchronized (usedTasks) { if (this.myIsCancelled()) { @@ -1127,7 +1119,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } //noOfThread++; } else { - if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { + if(parallel && (variance == 2)) { writeLog("var2einstieg"); Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); @@ -1171,7 +1163,6 @@ public class TypeUnifyTask extends RecursiveTask>> { /* FORK ANFANG */ synchronized (this) { writeLog("wait "+ forkOrig.thNo); - noOfThread--; res = forkOrig.join(); synchronized (usedTasks) { if (this.myIsCancelled()) { @@ -1190,7 +1181,6 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.forEach(x -> writeLog("wait: " + x.thNo)); for(TypeUnify2Task fork : forks) { synchronized (this) { - noOfThread--; Set> fork_res = fork.join(); synchronized (usedTasks) { if (this.myIsCancelled()) { @@ -2612,7 +2602,6 @@ public class TypeUnifyTask extends RecursiveTask>> { if (log && finalresult) { try { logFile.write("Thread no.:" + thNo + "\n"); - logFile.write("noOfThread:" + noOfThread + "\n"); logFile.write("parallel:" + parallel + "\n"); logFile.write(str+"\n\n"); logFile.flush();