package edu.mit.streamjit.impl.compiler2;

import edu.mit.streamjit.api.Worker;
import edu.mit.streamjit.impl.common.BlobHostStreamCompiler;
import edu.mit.streamjit.impl.common.Configuration;
import java.nio.file.Path;
import java.util.Set;

/**
 *
 * @author Jeffrey Bosboom <jeffreybosboom@gmail.com>
 * @since 11/12/2013 (from CompilerStreamCompiler since 8/13/2013)
 */
public final class Compiler2StreamCompiler extends BlobHostStreamCompiler {
	private int maxNumCores = 1;
	private int multiplier = 1;
	private Path dumpFile;
	public Compiler2StreamCompiler() {
		super(new Compiler2BlobFactory());
	}

	public Compiler2StreamCompiler maxNumCores(int maxNumCores) {
		this.maxNumCores = maxNumCores;
		return this;
	}

	public Compiler2StreamCompiler multiplier(int multiplier) {
		this.multiplier = multiplier;
		return this;
	}

	public Compiler2StreamCompiler dumpFile(Path path) {
		this.dumpFile = path;
		return this;
	}

	@Override
	protected final int getMaxNumCores() {
		return maxNumCores;
	}

	@Override
	protected final Configuration getConfiguration(Set<Worker<?, ?>> workers) {
		Configuration.Builder builder = Configuration.builder(super.getConfiguration(workers));
		Configuration.IntParameter multiplierParam = (Configuration.IntParameter)builder.removeParameter("multiplier");
		builder.addParameter(new Configuration.IntParameter("multiplier", multiplierParam.getRange(), this.multiplier));
		if (dumpFile != null)
			builder.putExtraData("dumpFile", dumpFile);
		return builder.build();
	}

	@Override
	public String toString() {
		return String.format("Compiler2StreamCompiler (%d cores %d mult)", maxNumCores, multiplier);
	}
}

@@ -213,16 +213,38 @@
 e.Path;%0A
+import java.util.Map;%0A
 import j
@@ -1116,16 +1116,88 @@
 kers) %7B%0A
+%09%09Configuration defaultConfiguration = super.getConfiguration(workers);%0A
 %09%09Config
@@ -1244,24 +1244,22 @@
 builder(
-super.ge
+defaul
 tConfigu
@@ -1264,25 +1264,16 @@
 guration
-(workers)
 );%0A%09%09Con
@@ -1496,16 +1496,484 @@
 lier));%0A
+%0A%09%09//For testing, try full data-parallelization across all cores.%0A%09%09int perCore = multiplier/maxNumCores;%0A%09%09for (Map.Entry%3CString, Configuration.Parameter%3E e : defaultConfiguration.getParametersMap().entrySet())%0A%09%09%09if (e.getKey().matches(%22node(%5C%5Cd+)core(%5C%5Cd+)iter%22)) %7B%0A%09%09%09%09Configuration.IntParameter p = (Configuration.IntParameter)builder.removeParameter(e.getKey());%0A%09%09%09%09builder.addParameter(new Configuration.IntParameter(e.getKey(), p.getRange(), perCore));%0A%09%09%09%7D%0A%0A
 %09%09if (du

configure for full data parallelization