File: gen_coll_cvar.py

package info (click to toggle)
mpich 4.3.0%2Breally4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 419,120 kB
  • sloc: ansic: 1,215,557; cpp: 74,755; javascript: 40,763; f90: 20,649; sh: 18,463; xml: 14,418; python: 14,397; perl: 13,772; makefile: 9,279; fortran: 8,063; java: 4,553; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (130 lines) | stat: -rw-r--r-- 5,009 bytes parent folder | download | duplicates (2)
1
2
3
4
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
##
## Copyright (C) by Argonne National Laboratory
##     See COPYRIGHT in top-level directory
##

import os
import re

script_dir = os.path.dirname(__file__)

# RE class allows convenience of using regex capture in a condition
class RE:
    m = None
    def match(pat, str, flags=0):
        RE.m = re.match(pat, str, flags)
        return RE.m
    def search(pat, str, flags=0):
        RE.m = re.search(pat, str, flags)
        return RE.m

def main():
    (tests, algos, algo_params) = load_config("coll_cvars.txt")
    testlist_cvar = "coll/testlist.collalgo"
    print("  --> [%s]" % testlist_cvar)
    with open(testlist_cvar, "w") as Out:
        for (key, testlist) in tests.items():
            if RE.match(r'(\w+)-(persistent)', key):
                algo_key = "%s-intra-nonblocking" % RE.m.group(1)
                dump_tests(Out, algo_key, testlist, algos, algo_params)
            elif RE.match(r'(\w+)-(\w+)-(\w+)', key):
                (name, intra, blocking) = RE.m.group(1,2,3)
                dump_tests(Out, key, testlist, algos, algo_params)
                if blocking == "blocking":
                    algo_key = "%s-%s-nonblocking" % (name, intra)
                    dump_tests(Out, algo_key, testlist, algos, algo_params, "nb")

def dump_tests(Out, key, testlist, algos, algo_params, special=None):
    if key not in algos:
        return
    if RE.match(r'(\w+)-(\w+)-(\w+)', key):
        (name, intra, blocking) = RE.m.group(1,2,3)
        NAME = name.upper()
        INTRA = intra.upper()
        if blocking == "nonblocking" and not special:
            NAME = 'I' + NAME
        for test in testlist:
            for algo in algos[key]:
                segs = [test]
                if special == "nb":
                    segs.append("env=MPIR_CVAR_%s_DEVICE_COLLECTIVE=0" % NAME)
                    segs.append("env=MPIR_CVAR_%s_%s_ALGORITHM=nb" % (NAME, INTRA))
                    segs.append("env=MPIR_CVAR_I%s_DEVICE_COLLECTIVE=0" % NAME)
                    segs.append("env=MPIR_CVAR_I%s_%s_ALGORITHM=%s" % (NAME, INTRA, algo))
                elif RE.match(r'composition:(\w+)', algo):
                    segs.append("env=MPIR_CVAR_%s_COMPOSITION=%s" % (NAME, RE.m.group(1)))
                elif RE.match(r'(\w+):(\w+)', algo):
                    DEVICE = RE.m.group(1).upper()
                    segs.append("env=MPIR_CVAR_%s_%s_%s_ALGORITHM=%s" % (NAME, DEVICE, INTRA, RE.m.group(2)))
                else:
                    segs.append("env=MPIR_CVAR_%s_DEVICE_COLLECTIVE=0" % NAME)
                    segs.append("env=MPIR_CVAR_%s_%s_ALGORITHM=%s" % (NAME, INTRA, algo))
                algo_key = key + "-" + algo
                if algo_key in algo_params:
                    count = count_algo_params(algo_params[algo_key], test)
                    for i in range(count):
                        s = get_algo_params(algo_params[algo_key], i)
                        print(' '.join(segs) + s, file=Out)
                else:
                    print(' '.join(segs), file=Out)

def count_algo_params(params, test):
    count = 1
    for t in params:
        if RE.match(r'(MPIR_CVAR_\w+)=(.*)', t):
            tlist = RE.m.group(2).split(',')
            count *= len(tlist)
    return count

def get_algo_params(params, i):
    s = ''
    for t in params:
        if RE.match(r'(MPIR_CVAR_\w+)=(.*)', t):
            name = RE.m.group(1)
            tlist = RE.m.group(2).split(',')
            count = len(tlist)
            idx = i % count
            i //= count
            s += ' env=%s=%s' % (name, tlist[idx])
    return s

def load_config(config_file):
    tests = {}
    algos = {}
    algo_params = {}
    
    sets = None
    name = ""
    key = ""
    algo_key = ""
    with open(script_dir + "/" + config_file, "r") as In:
        for line in In:
            # INDENT Level 0
            if re.match(r'tests:', line):
                sets = tests
            elif re.match(r'algorithms:', line):
                sets = algos
            # INDENT Level 1 (4 spaces)
            elif RE.match(r'^    (\w+):', line):
                name = RE.m.group(1)
            elif RE.match(r'^\s+((intra|inter)-(non)?blocking|persistent):', line):
                key = name + "-" + RE.m.group(1)
                sets[key] = []
            # tests
            elif RE.match(r'^\s+(\w+\s+\d+.*)', line):
                # test
                sets[key].append(RE.m.group(1))
            # algorithm
            elif RE.match(r'^\s+((\w+:)?\w+)', line):
                sets[key].append(RE.m.group(1))
                algo_key = "%s-%s" % (key, RE.m.group(1))
            # algo params
            elif RE.match(r'^\s+\.(MPIR_CVAR_\w+=.+|[a-z-]+)', line):
                if algo_key not in algo_params:
                    algo_params[algo_key] = []
                algo_params[algo_key].append(RE.m.group(1))
    return (tests, algos, algo_params)

# ---------------------------------------------------------
if __name__ == "__main__":
    main()