Skip to content

Commit 93acaa7

Browse files
committed
warn on Singlethread executor
1 parent 9fac1af commit 93acaa7

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

src/main/java/org/apache/sysds/runtime/util/CommonThreadPool.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -105,42 +105,42 @@ public static ExecutorService get() {
105105
* @return The executor with specified parallelism
106106
*/
107107
public synchronized static ExecutorService get(int k) {
108-
// if(k <= 1){
109-
// LOG.error("Invalid to create thread pool with <= one thread returning single thread executor", new RuntimeException());
108+
if(k <= 1){
109+
LOG.warn("Invalid to create thread pool with <= one thread returning single thread executor", new RuntimeException());
110110
return new SameThreadExecutorService();
111-
// }
112-
113-
// final Thread thisThread = Thread.currentThread();
114-
// final String threadName = thisThread.getName();
115-
// // Contains main, because we name our test threads TestRunner_main
116-
// final boolean mainThread = threadName.contains("main");
117-
// if(size == k && mainThread)
118-
// return shared; // use the default thread pool if main thread and max parallelism.
119-
// else if(mainThread || threadName.contains("PARFOR")) {
120-
// CommonThreadPool pool;
121-
// if(shared2 == null) // If there is no current shared pool allocate one.
122-
// shared2 = new ConcurrentHashMap<>();
123-
124-
// pool = shared2.get(thisThread.getId());
125-
// if(pool == null) { // If there is no pool for this thread allocate one.
126-
// pool = new CommonThreadPool(new ForkJoinPool(k));
127-
// shared2.put(thisThread.getId(), pool);
128-
// }
129-
130-
// return pool; // Return the shared pool for this parfor or main thread.
131-
// }
132-
// else {
133-
// // If we are neither a main thread or parfor thread, allocate a new thread pool
134-
// if(!incorrectPoolUse){
135-
// LOG.warn("An instruction allocated it's own thread pool indicating that some task is not properly reusing the threads.");
111+
}
112+
113+
final Thread thisThread = Thread.currentThread();
114+
final String threadName = thisThread.getName();
115+
// Contains main, because we name our test threads TestRunner_main
116+
final boolean mainThread = threadName.contains("main");
117+
if(size == k && mainThread)
118+
return shared; // use the default thread pool if main thread and max parallelism.
119+
else if(mainThread || threadName.contains("PARFOR")) {
120+
CommonThreadPool pool;
121+
if(shared2 == null) // If there is no current shared pool allocate one.
122+
shared2 = new ConcurrentHashMap<>();
123+
124+
pool = shared2.get(thisThread.getId());
125+
if(pool == null) { // If there is no pool for this thread allocate one.
126+
pool = new CommonThreadPool(new ForkJoinPool(k));
127+
shared2.put(thisThread.getId(), pool);
128+
}
129+
130+
return pool; // Return the shared pool for this parfor or main thread.
131+
}
132+
else {
133+
// If we are neither a main thread or parfor thread, allocate a new thread pool
134+
if(!incorrectPoolUse){
135+
LOG.warn("An instruction allocated it's own thread pool indicating that some task is not properly reusing the threads.");
136136

137-
// if(threadName.contains("test"))
138-
// LOG.error("Thread from test is not correctly using pools, please modify thread name to contain 'main'");
139-
// incorrectPoolUse = true;
140-
// return new CommonThreadPool(new ForkJoinPool(k));
141-
// }
142-
// return Executors.newFixedThreadPool(k);
143-
// }
137+
if(threadName.contains("test"))
138+
LOG.error("Thread from test is not correctly using pools, please modify thread name to contain 'main'");
139+
incorrectPoolUse = true;
140+
return new CommonThreadPool(new ForkJoinPool(k));
141+
}
142+
return Executors.newFixedThreadPool(k);
143+
}
144144
}
145145

146146
/**

0 commit comments

Comments
 (0)