sizelist <- seq(2048, 24576, 2048);
#schedlist <- c("greedy", "prio", "dm", "random", "no-prio", "ws");
schedlist <- c("prio", "dm", "random");

print(schedlist);

print(sizelist);

gflops <- function (x, size)
{
	2*size*size*size/(3000000*x);
}

parse <- function (size, sched)
{
	ret <- scan(paste("timings-sched/sched", sched, size, sep="."));
	return(ret);
}

handle_size <- function (size, sched)
{
	gflops <- gflops(parse(size, sched), size);

#	return(data.frame(gflops=gflops, size=array(size, c(length(gflops))), sched=array(sched, c(length(gflops)))));
	return(gflops);
}


handle_sched <- function(sched)
{
	gflopstab <- NULL;
	sizetab <- NULL;

	for (size in sizelist) {
		list <- handle_size(size, sched);
		gflopstab <- c(gflopstab, list);
		sizetab <- c(sizetab, array(size, c(length(list))));
	}

	return(
		data.frame(gflops=gflopstab, size=sizetab, sched=array(sched, c(length(gflopstab)) ))
	);
}

handle_sched_mean <- function(sched)
{
	meantab <- NULL;
	sizetab <- NULL;

	for (size in sizelist) {
		list <- mean(handle_size(size, sched));
		meantab <- c(meantab, list);
		sizetab <- c(sizetab, array(size, c(length(list))));
	}

	return(
		data.frame(gflops=meantab, size=sizetab, sched=array(sched, c(length(meantab)) ))
#		meantab
	);
}

trace_sched <- function(sched, color, style)
{
	#points(handle_sched(sched)$size, handle_sched(sched)$gflops, col=color);
	lines(handle_sched_mean(sched)$size, handle_sched_mean(sched)$gflops, col=color, legend.text=TRUE, type = "o", pch = style, lwd=2);
}

display_sched <- function()
{
	xlist <- range(sizelist);
	ylist <- range(c(0,100));

	plot.new();
	plot.window(xlist, ylist);

	trace_sched("dm", "blue", 0);
	trace_sched("random", "red", 1);
	trace_sched("prio", "green3", 4);

	axis(1, at=sizelist)
	axis(2, at=seq(0, 100, 10), tck=1)
#	axis(4, at=seq(0, 100, 10))
	box(bty="u")

	labels <- c("model tasks", "model workers", "priority")
	legend("bottomright", inset=.05, title="Scheduling policy", labels, lwd=2, lty=c(1, 1, 1, 1, 1, 1), pch=c(0, 1, 2, 4),col=c("blue", "red", "green3"), bty="y", bg="white", cex=1.6)

	mtext("matrix size", side=1, line=2, cex=1.6)
	mtext("GFlops", side=2, line=2, las=0, cex=1.6)

	title("LU decomposition");

}

display_sched()

# boxplot(result, col=c("yellow", "red", "green"), xlab=sizelist);



# plot(c(sizelist,sizelist,sizelist), c(result_greedy, result_prio, result_dm));
# plot(sizelist, result_dm);

# plot.new()
# plot.window(range(c(sizelist,0) ), c(0, 6))

