generate_automake_test_programs.py 6.17 KB
Newer Older
1 2 3 4
#!/usr/bin/env python
from __future__ import print_function
from itertools import product

Pavel Kus's avatar
Pavel Kus committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
def create_test(m, g, t, p, d, s, l, language) :
    for kernel in ["all_kernels", "default_kernel"] if s == "2stage" else ["nokernel"]:
        endifs = 0
        extra_flags = []

        if (t == "eigenvalues" and kernel == "all_kernels"):
           continue

        if (g == 1):
            print("if WITH_GPU_VERSION")
            endifs += 1

        if (l == "all_layouts"):
            print("if WITH_MPI")
            endifs += 1

        if (s in ["scalapack_all", "scalapack_part"]):
            print("if WITH_SCALAPACK_TESTS")
            endifs += 1

        if kernel == "default_kernel":
            extra_flags.append("-DTEST_KERNEL=ELPA_2STAGE_{0}_DEFAULT".format(d.upper()))
        elif kernel == "all_kernels":
            extra_flags.append("-DTEST_ALL_KERNELS")

        if layout_flag[l]:
            extra_flags.append(layout_flag[l])

        if (p == "single"):
            if (d == "real"):
                print("if WANT_SINGLE_PRECISION_REAL")
            elif (d == "complex"):
                print("if WANT_SINGLE_PRECISION_COMPLEX")
            else:
                raise Exception("Oh no!")
            endifs += 1

        name = "test_{0}_{1}_{2}_{3}{4}{5}{6}{7}{8}".format(
                    d, p, t, s,
                    "" if kernel == "nokernel" else "_" + kernel,
                    "" if language == "fortran" else "_fromC",
                    "_gpu" if g else "",
                    "_analytic" if m == "analytic" else "",
                    "_all_layouts" if l == "all_layouts" else "")
        print("noinst_PROGRAMS += " + name)
        print("check_SCRIPTS += " + name + ".sh")
        if(language == "fortran"):
            print(name + "_SOURCES = test/Fortran/test.F90")
            print(name + "_LDADD = $(test_program_ldadd)")
            print(name + "_FCFLAGS = $(test_program_fcflags) \\")
        elif(language == "c"):
            print(name + "_SOURCES = test/C/test.c")
            print(name + "_LDADD = $(test_program_ldadd) $(FCLIBS)")
            print(name + "_CFLAGS = $(test_program_cflags) \\")
        else:
            raise Exception("Oh no, unknown language!")
        print("  -DTEST_CASE=\\\"{0}\\\" \\".format(name))
        print("  " + " \\\n  ".join([
            domain_flag[d],
            prec_flag[p],
            test_type_flag[t],
            solver_flag[s],
            gpu_flag[g],
            matrix_flag[m]] + extra_flags))

        print("endif\n" * endifs)

# generate Fortran tests
73 74 75 76 77 78 79 80 81 82 83
domain_flag = {
        "real"   : "-DTEST_REAL",
        "complex": "-DTEST_COMPLEX",
}
prec_flag = {
        "double" : "-DTEST_DOUBLE",
        "single" : "-DTEST_SINGLE",
}
solver_flag = {
        "1stage" : "-DTEST_SOLVER_1STAGE",
        "2stage" : "-DTEST_SOLVER_2STAGE",
Pavel Kus's avatar
Pavel Kus committed
84
        "scalapack_all" : "-DTEST_SCALAPACK_ALL",
85
        "scalapack_part" : "-DTEST_SCALAPACK_PART",
86 87 88 89 90
}
gpu_flag = {
        0 : "-DTEST_GPU=0",
        1 : "-DTEST_GPU=1",
}
Pavel Kus's avatar
Pavel Kus committed
91 92 93 94
matrix_flag = {
        "random" : "-DTEST_MATRIX_RANDOM",
        "analytic" : "-DTEST_MATRIX_ANALYTIC",
}
95

96
test_type_flag = {
97 98 99
        "eigenvectors" : "-DTEST_EIGENVECTORS",
        "eigenvalues"  : "-DTEST_EIGENVALUES",
        "solve_tridiagonal"  : "-DTEST_SOLVE_TRIDIAGONAL",
100
        "cholesky"  : "-DTEST_CHOLESKY",
101
        "hermitian_multiply"  : "-DTEST_HERMITIAN_MULTIPLY",
102
        "qr"  : "-DTEST_QR_DECOMPOSITION",
Pavel Kus's avatar
Pavel Kus committed
103
        "generalized"  : "-DTEST_GENERALIZED_EIGENPROBLEM",
104 105
}

106 107 108 109 110 111
layout_flag = {
        "all_layouts" : "-DTEST_ALL_LAYOUTS",
        "square" : ""
}
for m, g, t, p, d, s, l in product(
                             sorted(matrix_flag.keys()),
Pavel Kus's avatar
Pavel Kus committed
112
                             sorted(gpu_flag.keys()),
113 114 115
                             sorted(test_type_flag.keys()),
                             sorted(prec_flag.keys()),
                             sorted(domain_flag.keys()),
116 117
                             sorted(solver_flag.keys()),
                             sorted(layout_flag.keys())):
Pavel Kus's avatar
Pavel Kus committed
118
    if(m == "analytic" and (g == 1 or t != "eigenvectors")):
Pavel Kus's avatar
Pavel Kus committed
119 120
        continue

121
    if(s in ["scalapack_all", "scalapack_part"]  and (g == 1 or t != "eigenvectors" or m != "analytic")):
Pavel Kus's avatar
Pavel Kus committed
122 123
        continue

124
    if (t == "solve_tridiagonal" and (s == "2stage" or d == "complex")):
125 126
        continue

127 128 129
    if (t == "cholesky" and (s == "2stage")):
        continue

130 131 132
    if (t == "hermitian_multiply" and (s == "2stage")):
        continue

133 134 135
    if (t == "qr" and (s == "1stage" or d == "complex")):
        continue

136
    #TODO: this does not work at the moment
137
    if(t == "generalized" and l == "all_layouts"):
138 139
        continue

140 141 142 143
    #might be considered to tackle combinatorial explosion
    #if(t == "generalized" and s == "2stage"):
    #    continue

Pavel Kus's avatar
Pavel Kus committed
144
    create_test(m, g, t, p, d, s, l, "fortran")
145 146


Pavel Kus's avatar
Pavel Kus committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
# generate C tests
domain_flag = {
        "real"   : "-DTEST_REAL",
        "complex": "-DTEST_COMPLEX",
}
prec_flag = {
        "double" : "-DTEST_DOUBLE",
        "single" : "-DTEST_SINGLE",
}
solver_flag = {
        "1stage" : "-DTEST_SOLVER_1STAGE",
        "2stage" : "-DTEST_SOLVER_2STAGE",
#        "scalapack_all" : "-DTEST_SCALAPACK_ALL",
#        "scalapack_part" : "-DTEST_SCALAPACK_PART",
}
gpu_flag = {
        0 : "-DTEST_GPU=0",
#        1 : "-DTEST_GPU=1",
}
matrix_flag = {
        "random" : "-DTEST_MATRIX_RANDOM",
#        "analytic" : "-DTEST_MATRIX_ANALYTIC",
}
170

Pavel Kus's avatar
Pavel Kus committed
171 172 173 174 175 176 177 178
test_type_flag = {
        "eigenvectors" : "-DTEST_EIGENVECTORS",
#        "eigenvalues"  : "-DTEST_EIGENVALUES",
#        "solve_tridiagonal"  : "-DTEST_SOLVE_TRIDIAGONAL",
#        "cholesky"  : "-DTEST_CHOLESKY",
#        "hermitian_multiply"  : "-DTEST_HERMITIAN_MULTIPLY",
#        "qr"  : "-DTEST_QR_DECOMPOSITION",
}
179

Pavel Kus's avatar
Pavel Kus committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193
layout_flag = {
#        "all_layouts" : "-DTEST_ALL_LAYOUTS",
        "square" : ""
}
for m, g, t, p, d, s, l in product(
                             sorted(matrix_flag.keys()),
                             sorted(gpu_flag.keys()),
                             sorted(test_type_flag.keys()),
                             sorted(prec_flag.keys()),
                             sorted(domain_flag.keys()),
                             sorted(solver_flag.keys()),
                             sorted(layout_flag.keys())):

    create_test(m, g, t, p, d, s, l, "c")
194

195

196

197 198