Commit 5e271fd9 authored by Andreas Marek's avatar Andreas Marek

First attempt at going Python-3 only

Only minimal changes done so far (mostly print() stuff)
parent c204c68e
#!/usr/bin/env python #!/usr/bin/python3
from __future__ import print_function
from itertools import product from itertools import product
def set_number_of_cores(mpi_tasks, o): def set_number_of_cores(mpi_tasks, o):
cores = 1 cores = 1
cores = 1 * mpi_tasks cores = 1 * mpi_tasks
......
#!/usr/bin/python #!/usr/bin/python3
import sys
simple_tokens = [ simple_tokens = [
"PRECISION", "PRECISION",
...@@ -113,62 +112,63 @@ blas_prefixes = {("real","single") : "S", ("real","double") : "D", ("complex","s ...@@ -113,62 +112,63 @@ blas_prefixes = {("real","single") : "S", ("real","double") : "D", ("complex","s
def print_variant(number, precision, explicit): def print_variant(number, precision, explicit):
for token in simple_tokens: for token in simple_tokens:
print "#define ", token, token.replace("PRECISION", precision).replace("UPCASENUMBER", number.upper()).replace("NUMBER", number) print("#define ", token, token.replace("PRECISION", precision).replace("UPCASENUMBER", number.upper()).replace("NUMBER", number))
print "#define ", token + "_STR", "'" + token.replace("PRECISION", precision).replace("UPCASENUMBER", number.upper()).replace("NUMBER", number) + "'" print("#define ", token + "_STR", "'" + token.replace("PRECISION", precision).replace("UPCASENUMBER", number.upper()).replace("NUMBER", number) + "'")
if("NUMBER" in token): if("NUMBER" in token):
print "#define ", token.replace("NUMBER", number), token.replace("PRECISION", precision).replace("NUMBER", number) print("#define ", token.replace("NUMBER", number), token.replace("PRECISION", precision).replace("NUMBER", number))
for token in blas_tokens: for token in blas_tokens:
print "#define ", token, token.replace("PRECISION_", blas_prefixes[(number, precision)]) print("#define ", token, token.replace("PRECISION_", blas_prefixes[(number, precision)]))
for token in explicit: for token in explicit:
print "#define ", token[0], token[explicit_order[precision]] print("#define ", token[0], token[explicit_order[precision]])
def print_undefs(number, explicit): def print_undefs(number, explicit):
for token in simple_tokens: for token in simple_tokens:
print "#undef ", token print("#undef ", token)
print "#undef ", token + "_STR" print("#undef ", token + "_STR")
if("NUMBER" in token): if("NUMBER" in token):
print "#undef ", token.replace("NUMBER", number) print("#undef ", token.replace("NUMBER", number))
for token in blas_tokens: for token in blas_tokens:
print "#undef ", token print("#undef ", token)
for token in explicit: for token in explicit:
print "#undef ", token[0] print("#undef ", token[0])
print "#ifdef REALCASE" print("#ifdef REALCASE")
print "#undef MATH_DATATYPE" print("#undef MATH_DATATYPE")
print "#define MATH_DATATYPE real" print("#define MATH_DATATYPE real")
print_undefs("real", explicit_tokens_real) print_undefs("real", explicit_tokens_real)
#print_undefs("complex", explicit_tokens_complex) # print_undefs("complex", explicit_tokens_complex)
print "#ifdef DOUBLE_PRECISION" print("#ifdef DOUBLE_PRECISION")
print_variant("real", "double", explicit_tokens_real) print_variant("real", "double", explicit_tokens_real)
print "#endif" print("#endif")
print "#ifdef SINGLE_PRECISION" print("#ifdef SINGLE_PRECISION")
print_variant("real", "single", explicit_tokens_real) print_variant("real", "single", explicit_tokens_real)
print "#endif" print("#endif")
print "#endif" print("#endif")
print "#ifdef COMPLEXCASE" print("#ifdef COMPLEXCASE")
print "#undef MATH_DATATYPE" print("#undef MATH_DATATYPE")
print "#define MATH_DATATYPE complex" print("#define MATH_DATATYPE complex")
#print_undefs("real", explicit_tokens_real) # print_undefs("real", explicit_tokens_real)
print_undefs("complex", explicit_tokens_complex) print_undefs("complex", explicit_tokens_complex)
print "#ifdef DOUBLE_PRECISION" print("#ifdef DOUBLE_PRECISION")
print_variant("complex", "double", explicit_tokens_complex) print_variant("complex", "double", explicit_tokens_complex)
print "#endif" print("#endif")
print "#ifdef SINGLE_PRECISION" print("#ifdef SINGLE_PRECISION")
print_variant("complex", "single", explicit_tokens_complex) print_variant("complex", "single", explicit_tokens_complex)
print "#endif" print("#endif")
print "#endif" print("#endif")
#print "#elif MACROS_TYPE == COMPLEX_DOUBLE" # print("#elif MACROS_TYPE == COMPLEX_DOUBLE")
#print "#undef NUMBER" # print("#undef NUMBER")
#print_undefs("complex", explicit_tokens_complex) # print_undefs("complex", explicit_tokens_complex)
#print "#define NUMBER complex" # print("#define NUMBER complex")
#print_variant("complex", "double", explicit_tokens_complex) # print_variant("complex", "double", explicit_tokens_complex)
#print "#elif MACROS_TYPE == COMPLEX_SINGLE" # print("#elif MACROS_TYPE == COMPLEX_SINGLE")
#print "#undef NUMBER" # print("#undef NUMBER")
#print_undefs("complex", explicit_tokens_complex) # print_undefs("complex", explicit_tokens_complex)
#print "#define NUMBER complex" # print("#define NUMBER complex")
#print_variant("complex", "single", explicit_tokens_complex) # print_variant("complex", "single", explicit_tokens_complex)
#print "#endif" # print("#endif")
#!/usr/bin/env python #!/usr/bin/python3
from __future__ import print_function
from itertools import product from itertools import product
language_flag = { language_flag = {
......
#!/usr/bin/python #!/usr/bin/python3
from __future__ import print_function from __future__ import print_function
import os import os
import sys import sys
import subprocess import subprocess
def cpp_arg(arg): def cpp_arg(arg):
return arg.startswith("-I") or \ return \
arg.startswith("-D") or \ arg.startswith("-I") or \
arg.startswith("-U") arg.startswith("-D") or \
arg.startswith("-U")
def check_call(args, **kwargs): def check_call(args, **kwargs):
...@@ -15,6 +17,7 @@ def check_call(args, **kwargs): ...@@ -15,6 +17,7 @@ def check_call(args, **kwargs):
print(" ".join(args)) print(" ".join(args))
return subprocess.check_call(args, **kwargs) return subprocess.check_call(args, **kwargs)
def check_call_redirect(args, filename=None, **kwargs): def check_call_redirect(args, filename=None, **kwargs):
if os.getenv("V") == "1": if os.getenv("V") == "1":
print(" ".join(args), ">", filename) print(" ".join(args), ">", filename)
...@@ -25,11 +28,12 @@ def check_call_redirect(args, filename=None, **kwargs): ...@@ -25,11 +28,12 @@ def check_call_redirect(args, filename=None, **kwargs):
os.remove(filename) os.remove(filename)
raise SystemExit(e.returncode) raise SystemExit(e.returncode)
args = sys.argv[1:] args = sys.argv[1:]
cpp_args = filter(cpp_arg, args) cpp_args = list(filter(cpp_arg, args))
files = list(filter(lambda q: q.endswith(".F90"), args))
args = list(filter(lambda q: not q.endswith(".F90"), args))
files = filter(lambda q : q.endswith(".F90"), args)
args = filter(lambda q : not q.endswith(".F90"), args)
if len(files) > 1: if len(files) > 1:
raise Exception("Specify exactly one .F90 file") raise Exception("Specify exactly one .F90 file")
elif len(files) == 0: elif len(files) == 0:
...@@ -54,7 +58,7 @@ except ValueError: ...@@ -54,7 +58,7 @@ except ValueError:
tmp_filename = tmp_filename[-250:] tmp_filename = tmp_filename[-250:]
# preprocess # preprocess
check_call_redirect(["cpp","-P", "-traditional", "-Wall", "-Werror"] + cpp_args + [file], filename=tmp_filename) check_call_redirect(["cpp", "-P", "-traditional", "-Wall", "-Werror"] + cpp_args + [file], filename=tmp_filename)
# compile # compile
check_call(args + [tmp_filename]) check_call(args + [tmp_filename])
......
#!/usr/bin/env python #!/usr/bin/python3
import numpy as np import numpy as np
from pyelpa import DistributedMatrix from pyelpa import DistributedMatrix
import sys import sys
......
#!/usr/bin/env python #!/usr/bin/env python3
import sys import sys
import os import os
......
...@@ -27,25 +27,25 @@ class Trace: ...@@ -27,25 +27,25 @@ class Trace:
header = f.readline() header = f.readline()
val = [int(x) for x in header.split()] val = [int(x) for x in header.split()]
val.append(f.readline()[:-1]) val.append(f.readline()[:-1])
print val print(val)
return val return val
def __load_matrix(self, directory, filenames): def __load_matrix(self, directory, filenames):
mat = [] mat = []
for (mpi_rank, filename) in filenames: for (mpi_rank, filename) in filenames:
#print filename, mpi_rank, prow, pcol, p_cols #print(filename, mpi_rank, prow, pcol, p_cols)
(na, nblk, lda, localCols, my_prow, my_pcol, p_rows, p_cols, iteration, name) = self.__get_header(directory + '/' + filename) (na, nblk, lda, localCols, my_prow, my_pcol, p_rows, p_cols, iteration, name) = self.__get_header(directory + '/' + filename)
if(mat == []): if(mat == []):
mat = np.zeros((na, na)) mat = np.zeros((na, na))
(self._na, self._nblk, self._p_rows, self._p_cols) = (na, nblk, p_rows, p_cols) (self._na, self._nblk, self._p_rows, self._p_cols) = (na, nblk, p_rows, p_cols)
prow = mpi_rank % p_rows prow = mpi_rank % p_rows
pcol = mpi_rank / p_rows pcol = mpi_rank / p_rows
#print (na, nblk, lda, localCols, my_prow, my_pcol, my_nprows, my_npcols) #print(na, nblk, lda, localCols, my_prow, my_pcol, my_nprows, my_npcols)
assert(my_prow == prow) assert(my_prow == prow)
assert(my_pcol == pcol) assert(my_pcol == pcol)
loc_mat = np.loadtxt(fname = directory + '/' + filename, skiprows = 2) loc_mat = np.loadtxt(fname = directory + '/' + filename, skiprows = 2)
#print "lda, localCols ", lda, localCols #print("lda, localCols ", lda, localCols)
for row_blk in range((lda-1)/nblk + 1): for row_blk in range((lda-1)/nblk + 1):
loc_row_beg = row_blk * nblk loc_row_beg = row_blk * nblk
if(loc_row_beg >= lda): if(loc_row_beg >= lda):
...@@ -54,7 +54,7 @@ class Trace: ...@@ -54,7 +54,7 @@ class Trace:
loc_row_end = min(loc_row_beg + nblk, lda) loc_row_end = min(loc_row_beg + nblk, lda)
glob_row_beg = (row_blk * p_rows + prow) * nblk glob_row_beg = (row_blk * p_rows + prow) * nblk
#print "glob_row_beg = row_blk * nblk * p_rows ", glob_row_beg, row_blk, nblk, p_rows #print("glob_row_beg = row_blk * nblk * p_rows ", glob_row_beg, row_blk, nblk, p_rows)
assert(glob_row_beg < na) assert(glob_row_beg < na)
glob_row_end = min(glob_row_beg + nblk, na) glob_row_end = min(glob_row_beg + nblk, na)
...@@ -71,8 +71,8 @@ class Trace: ...@@ -71,8 +71,8 @@ class Trace:
glob_col_end = min(glob_col_beg + nblk, na) glob_col_end = min(glob_col_beg + nblk, na)
#print "local", (loc_row_beg, loc_row_end), (loc_col_beg, loc_col_end) #print("local", (loc_row_beg, loc_row_end), (loc_col_beg, loc_col_end))
#print "global", (glob_row_beg, glob_row_end), (glob_col_beg, glob_col_end) #print("global", (glob_row_beg, glob_row_end), (glob_col_beg, glob_col_end))
mat[glob_row_beg:glob_row_end, glob_col_beg:glob_col_end] = loc_mat[loc_row_beg:loc_row_end, loc_col_beg:loc_col_end] mat[glob_row_beg:glob_row_end, glob_col_beg:glob_col_end] = loc_mat[loc_row_beg:loc_row_end, loc_col_beg:loc_col_end]
return ((name, iteration), mat) return ((name, iteration), mat)
...@@ -271,7 +271,7 @@ class Snapshot(View): ...@@ -271,7 +271,7 @@ class Snapshot(View):
self.set_limits(np.percentile(mat,1), np.percentile(mat,99)) self.set_limits(np.percentile(mat,1), np.percentile(mat,99))
def write(self): def write(self):
print self._matrix, ", ", it._index print(self._matrix, ", ", it._index)
def _get_matrix(self): def _get_matrix(self):
return self._trace._matrices[self._iterator.current()][self._matrix] return self._trace._matrices[self._iterator.current()][self._matrix]
......
#!/usr/bin/env python #!/usr/bin/env python3
from itertools import product from itertools import product
from scaling import * from scaling import *
......
#! /usr/bin/env python #! /usr/bin/env python3
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import re import re
......
#! /usr/bin/env python #! /usr/bin/env python3
import os import os
import subprocess import subprocess
...@@ -8,10 +8,10 @@ with open("results_raw.txt", "w") as logfile: ...@@ -8,10 +8,10 @@ with open("results_raw.txt", "w") as logfile:
path = subprocess.check_output('pwd')[:-1].decode() + "/" path = subprocess.check_output('pwd')[:-1].decode() + "/"
for subdir, dirs, files in os.walk(rootdir): for subdir, dirs, files in os.walk(rootdir):
# for file in files: # for file in files:
# print os.path.join(subdir, file) # print(os.path.join(subdir, file))
# print subdir, dirs, files # print(subdir, dirs, files )
if(len(files) != 0): if(len(files) != 0):
#print subdir, dirs, files #print(subdir, dirs, files)
print("cd " + path + subdir) print("cd " + path + subdir)
logfile.write(subdir + "\n") logfile.write(subdir + "\n")
os.chdir(path + subdir) os.chdir(path + subdir)
......
#! /usr/bin/env python #! /usr/bin/env python3
from collections import namedtuple from collections import namedtuple
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
...@@ -89,5 +89,3 @@ with open("results_sorted.txt", "w") as sortedfile: ...@@ -89,5 +89,3 @@ with open("results_sorted.txt", "w") as sortedfile:
sortedfile.write("*"*num_stars + "\n") sortedfile.write("*"*num_stars + "\n")
lines_to_write = [] lines_to_write = []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment