Example #1
0
def repeat_execute(fun, dir):
    res = []
    for i in range(repeat):
        res.append(fun(dir))
    #f = open(os.path.basename(dir) + "/time.dat", "b")
    lines = util.file_as_lines(os.path.basename(dir) + "/time.dat")
    print lines
    lines += [str(s) + "\n" for s in res]
    print lines
    #f.write("".join([str(s)+"\n" for s in res]))
    util.lines_to_file(os.path.basename(dir) + "/time.dat", lines)
Example #2
0
def repeat_execute(fun, dir):
	res = []
	for i in range(repeat):
		res.append(fun(dir))
	#f = open(os.path.basename(dir) + "/time.dat", "b")
	lines = util.file_as_lines(os.path.basename(dir) + "/time.dat")
	print lines
	lines += [str(s)+"\n" for s in res];
	print lines
	#f.write("".join([str(s)+"\n" for s in res]))
	util.lines_to_file(os.path.basename(dir) + "/time.dat", lines)
Example #3
0
def compare(dir):
    sources = os.listdir(dir)
    for s in sources:
        fname, ext = os.path.splitext(s)
        if ext == ".out" and (not fname == "a"):
            bench_file = s
            bench_name = fname
            c_bench_file = dir.split("/")[-2] + ".out"
            break
    else:
        return
    color_printer.print_bold("[WORKING] running %s..." % (bench_name))
    total_res = []
    for i in range(repeat):
        print "iteration %d..." % (i + 1)
        res = []
        # run c standard version:
        #res.append(run_c(polybench_c_path + dir + c_bench_file))
        # run x10 standard version:
        res.append(run_x10(dir + bench_file))
        for opt in polyopt_options:
            color_printer.print_bold(
                "[WORKING] running subversion compiled using %s..." % (opt))
            target_path = dir + re.match("--polyopt-([a-zA-Z0-9\-_]+)",
                                         opt).group(1).replace("-", "_")
            # run c version firstly
            #res.append(run_c(polybench_c_path + target_path + "/" + c_bench_file))

            # run_x10
            target_bench = target_path + "/" + bench_file
            if not os.path.exists(target_bench):
                color_printer.print_warning(
                    "cannot check program %s, this program haven't been compiled by x10c++!"
                    % (target_bench))
                continue
            res.append(run_x10(target_bench))
        total_res.append(res)
    res_d = {}
    for res in total_res:
        for dir, time in res:
            if dir in res_d:
                res_d[dir].append(time)
            else:
                res_d[dir] = [time]
    #print res_d
    for dir, times in res_d.iteritems():
        try:
            lines = util.file_as_lines(os.path.dirname(dir) + "/time.dat")
        except IOError:
            lines = []
        lines += [str(s) + "\n" for s in times]
        util.lines_to_file(os.path.dirname(dir) + "/time.dat", lines)
Example #4
0
def compare(dir):
	sources = os.listdir(dir)
	for s in sources:
		fname, ext = os.path.splitext(s)
		if ext == ".out" and (not fname == "a"):
			bench_file = s
			bench_name = fname
			c_bench_file = dir.split("/")[-2] + ".out"
			break
	else:
		return
	color_printer.print_bold("[WORKING] running %s..."%(bench_name))
	total_res = []
	for i in range(repeat):
		print "iteration %d..."%(i+1)
		res = []
		# run c standard version:
		#res.append(run_c(polybench_c_path + dir + c_bench_file))
		# run x10 standard version:
		res.append(run_x10(dir + bench_file))
		for opt in polyopt_options:
			color_printer.print_bold("[WORKING] running subversion compiled using %s..."%(opt))
			target_path = dir + re.match("--polyopt-([a-zA-Z0-9\-_]+)", opt).group(1).replace("-", "_")
			# run c version firstly
			#res.append(run_c(polybench_c_path + target_path + "/" + c_bench_file))

			# run_x10 
			target_bench = target_path + "/" + bench_file
			if not os.path.exists(target_bench):
				color_printer.print_warning("cannot check program %s, this program haven't been compiled by x10c++!"%(target_bench))
				continue
			res.append(run_x10(target_bench))
		total_res.append(res)
	res_d = {}
	for res in total_res:
		for dir, time in res:
			if dir in res_d:
				res_d[dir].append(time)
			else:
				res_d[dir] = [time]
	#print res_d
	for dir, times in res_d.iteritems():
		try:
			lines = util.file_as_lines(os.path.dirname(dir) + "/time.dat")
		except IOError:
			lines = []
		lines += [str(s)+"\n" for s in times];
		util.lines_to_file(os.path.dirname(dir) + "/time.dat", lines)
Example #5
0
def replace_rail(filename):
	lines = util.file_as_lines(filename)
	if any(["import x10.array.Array_2;" in l for l in lines]):
		color_printer.print_warning("already replaced Rail in %s, skip..."%(filename))
		return
	else:
		lines = ["import x10.array.Array_2;\n",
				"import x10.array.Array_3;\n"] + lines
		lines = util.find_and_replace(')(', ',', lines)
	i = 0
	balance = -1
	arg_lst = []
	allocate_index = 0
	while i < len(lines):
		l = lines[i]
		m = re.search('new Rail\[Rail\[Rail\[('+c_expression+')\]\]\]\(('+c_expression+')\)', l)
		if m:
			allocate_index = i
			while True:
				i += 1
				m2 = re.search('new Rail\[Rail\[('+c_expression+')\]\]\(('+c_expression+')\)', lines[i]) 
				if m2 and m2.group(1) == m.group(1):
					arg_lst.append(m2.group(2))
				m2 = re.search('new Rail\[('+c_expression+')\]\(('+c_expression+')\)', lines[i]) 
				if m2 and m2.group(1) == m.group(1):
					arg_lst.append(m2.group(2))
				if "{" in lines[i]:
					balance = balance + 1 if not balance == -1 else 1
				if "}" in lines[i]:
					balance -= 1
				if balance == 0:
					break
			lines[allocate_index] = util.replace_span(l, m.span(),
					'new Array_3[' + m.group(1) + '](' + m.group(2) + "".join([","+arg for arg in arg_lst]) + ")")
			arg_lst = []
			balance = -1
			lines = lines[:allocate_index+1]+lines[i+1:]
			i = allocate_index
		m = re.search('new Rail\[Rail\[('+c_expression+')\]\]\(('+c_expression+')\)', l) 
		if m:
			allocate_index = i
			while True:
				i += 1
				m2 = re.search('new Rail\[('+c_expression+')\]\(('+c_expression+')\)', lines[i]) 
				if m2 and m2.group(1) == m.group(1):
					arg_lst = [m2.group(2)]
				if "{" in lines[i]:
					balance = balance + 1 if not balance == -1 else 1
				if "}" in lines[i]:
					balance -= 1
				if balance == 0:
					break
			lines[allocate_index] = util.replace_span(l, m.span(),
					"new Array_2[%s](%s,%s)"%(m.group(1), m.group(2), arg_lst[0]))
			arg_lst = []
			balance = -1
			lines = lines[:allocate_index+1]+lines[i+1:]
			i = allocate_index
		i += 1
	lines = util.find_and_replace_re('Rail\[Rail\[Rail\[('+c_expression+')\]\]\]', lambda m: "Array_3["+m.group(1)+"]", lines)
	lines = util.find_and_replace_re('Rail\[Rail\[('+c_expression+')\]\]', lambda m: "Array_2["+m.group(1)+"]", lines)
	util.lines_to_file(filename, lines)