Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #22 from sagemintblue/hazen_allow_zero_threads
Browse files Browse the repository at this point in the history
Adds support for construction of a TopicModel instance with zero numThreads
  • Loading branch information
jakemannix committed Apr 25, 2012
2 parents 417d98b + 4f74872 commit af7212f
Showing 1 changed file with 9 additions and 0 deletions.
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.mahout.clustering.lda.cvb;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -153,6 +154,12 @@ private static Vector viewRowSums(Matrix m) {
}

private void initializeThreadPool() {
// avoid initializing thread pool if client has specified less than one thread
if (numThreads < 1) {
log.info("Skipping thread pool initialization");
return;
}
log.info("Initializing thread pool with {} threads", numThreads);
ThreadPoolExecutor threadPool = new ThreadPoolExecutor(numThreads, numThreads, 0, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(numThreads * 10));
threadPool.allowCoreThreadTimeOut(false);
Expand Down Expand Up @@ -323,6 +330,8 @@ public Vector infer(Vector original, Vector docTopicPrior, double minRelPerplexi
}

public void update(Matrix docTopicCounts) {
Preconditions.checkState(updaters.length > 0,
"Unable to update model; No threads requested during TopicModel instantiation");
for(int x = 0; x < numTopics; x++) {
updaters[x % updaters.length].update(x, docTopicCounts.viewRow(x));
}
Expand Down

0 comments on commit af7212f

Please sign in to comment.