Skip to content

Commit

Permalink
sort the struct entries by type to reduce padding
Browse files Browse the repository at this point in the history
  • Loading branch information
zingale committed Mar 25, 2024
1 parent 437ebcb commit 40b05b9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Source/driver/parse_castro_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ def write_headers_and_source(params, out_directory, struct_name):
pf.close()

# now write a single file that contains all of the parameter structs
# to minimize padding, we want to sort on type

try:
sf = open(f"{out_directory}/{struct_name}_type.H", "w", encoding="UTF-8")
except OSError:
Expand All @@ -264,20 +266,25 @@ def write_headers_and_source(params, out_directory, struct_name):
params_nm = [q for q in params if q.namespace == nm]
# sort by repr since None may be present
ifdefs = sorted({q.ifdef for q in params_nm}, key=repr)

sf.write(f"struct {nm}_t {{\n")
print("namespace = ", nm)
for ifdef in ifdefs:
params_if = [q for q in params_nm if q.ifdef == ifdef]
types = set(q.dtype for q in params_if)

if ifdef is None:
for p in [q for q in params_nm if q.ifdef is None]:
sf.write(p.get_struct_entry())
for tt in types:
params_type = [q for q in params_if if q.dtype == tt]
for p in params_type:
sf.write(p.get_struct_entry())
else:
sf.write(f"#ifdef {ifdef}\n")
for p in [q for q in params_nm if q.ifdef == ifdef]:
sf.write(p.get_struct_entry())
for tt in types:
params_type = [q for q in params_if if q.dtype == tt]
for p in params_type:
sf.write(p.get_struct_entry())
sf.write("#endif\n")


sf.write("};\n\n")

# now the parent struct
Expand Down

0 comments on commit 40b05b9

Please sign in to comment.