Skip to content

Commit 5354660

Browse files
committed
mfc.sh: refactor running cases from within mfc.sh
1 parent 2b03dd1 commit 5354660

File tree

7 files changed

+35
-19
lines changed

7 files changed

+35
-19
lines changed

misc/run-phoenix-release-gpu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set -x
1717
. ./mfc.sh load -c p -m GPU
1818

1919
gpu_count=$(nvidia-smi -L | wc -l) # number of GPUs on node
20-
gpu_ids=$(seq -s ',' 0 $(($gpu_count-1))) # 0,1,2,...,gpu_count-1
20+
gpu_ids=$(seq -s ' ' 0 $(($gpu_count-1))) # 0,1,2,...,gpu_count-1
2121

2222
./mfc.sh test -a -b mpirun -j $(nproc) \
2323
--gpu -g $gpu_ids

toolchain/mfc/args.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ def add_common_arguments(p, mask = None):
6565
for target in DEPENDENCY_TARGETS:
6666
p.add_argument(f"--no-{target.name}", action="store_true", help=f"Do not build the {target.name} dependency. Use the system's instead.")
6767

68+
if "g" not in mask:
69+
p.add_argument("-g", "--gpus", nargs="+", type=int, default=[0], help="(GPU) List of GPU #s to use.")
70+
6871
# === BUILD ===
69-
add_common_arguments(build)
72+
add_common_arguments(build, "g")
7073

7174
# === CLEAN ===
72-
add_common_arguments(clean, "j")
75+
add_common_arguments(clean, "jg")
7376

7477
binaries = [ b.bin for b in BINARIES ]
7578

@@ -82,7 +85,6 @@ def add_common_arguments(p, mask = None):
8285
test.add_argument("-b", "--binary", choices=binaries, type=str, default=None, help="(Serial) Override MPI execution binary")
8386
test.add_argument("-r", "--relentless", action="store_true", default=False, help="Run all tests, even if multiple fail.")
8487
test.add_argument("-a", "--test-all", action="store_true", default=False, help="Run the Post Process Tests too.")
85-
test.add_argument("-g", "--gpus", type=str, default="0", help="(GPU) Comma separated list of GPU #s to use.")
8688
test.add_argument("-%", "--percent", type=int, default=100, help="Percentage of tests to run.")
8789
test.add_argument("-m", "--max-attempts", type=int, default=3, help="Maximum number of attempts to run a test.")
8890

@@ -120,7 +122,7 @@ def add_common_arguments(p, mask = None):
120122
add_common_arguments(bench, "t")
121123

122124
# === COUNT ===
123-
add_common_arguments(count)
125+
add_common_arguments(count, "g")
124126

125127
args: dict = vars(parser.parse_args())
126128

@@ -150,8 +152,4 @@ def append_defaults_to_data(name: str, parser):
150152
if args[e] is not None:
151153
args[e] = os.path.abspath(args[e])
152154

153-
# Turn GPU ID list into a comma separated string
154-
if "gpus" in args:
155-
args["gpus"] = [int(g) for g in args["gpus"].split(",")]
156-
157155
return args

toolchain/mfc/common.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ class MFCException(Exception):
2929
pass
3030

3131

32-
def system(command: typing.List[str], no_exception: bool = False, exception_text=None, on_error=lambda: None, cwd=None, stdout=None, stderr=None) -> int:
32+
def system(command: typing.List[str], no_exception: bool = False, exception_text=None, on_error=lambda: None, cwd=None, stdout=None, stderr=None, env: dict = None) -> int:
3333
cmd = [ str(x) for x in command if not isspace(str(x)) ]
3434

35+
if env is None:
36+
env = os.environ.copy()
37+
3538
if stdout != subprocess.DEVNULL:
3639
cons.print(no_indent=True)
3740

@@ -40,7 +43,7 @@ def system(command: typing.List[str], no_exception: bool = False, exception_text
4043
if stdout != subprocess.DEVNULL:
4144
cons.print(no_indent=True)
4245

43-
r = subprocess.run(cmd, cwd=cwd, stdout=stdout, stderr=stderr)
46+
r = subprocess.run(cmd, cwd=cwd, stdout=stdout, stderr=stderr, env=env)
4447

4548
if r.returncode != 0:
4649
on_error()

toolchain/mfc/count.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os, glob, typing, typing
22

3-
from .common import MFC_ROOTDIR
3+
from .state import ARG
4+
from .common import MFC_ROOTDIR, format_list_to_string
45
from .printer import cons
56

67
import rich.table
@@ -20,12 +21,13 @@ def handle_dir(dirpath: str) -> typing.Tuple[typing.List[typing.Tuple[str, int]]
2021
return (files, total)
2122

2223
def count():
23-
cons.print("[bold]Counting lines of code in [magenta]MFC[/magenta][/bold] (excluding whitespace lines)")
24-
cons.print()
24+
target_str_list = format_list_to_string(ARG('targets'), 'magenta')
25+
26+
cons.print(f"[bold]Counting lines of code in {target_str_list}[/bold] (excluding whitespace lines)")
2527
cons.indent()
2628

2729
total = 0
28-
for codedir in ['common', 'pre_process', 'simulation', 'post_process']:
30+
for codedir in ['common'] + ARG("targets"):
2931
dirfiles, dircount = handle_dir(os.path.join(MFC_ROOTDIR, 'src', codedir))
3032
table = rich.table.Table(show_header=True, box=rich.table.box.SIMPLE)
3133
table.add_column(f"File (in [magenta]{codedir}[/magenta])", justify="left")
@@ -38,7 +40,7 @@ def count():
3840

3941
cons.raw.print(table)
4042

41-
cons.print(f"[bold]Total MFC lines: [bold cyan]{total}[/bold cyan].[/bold]")
43+
cons.print(f"[bold]Total {target_str_list} lines: [bold cyan]{total}[/bold cyan].[/bold]")
4244
cons.print()
4345
cons.unindent()
4446

toolchain/mfc/run/engines.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def get_args(self) -> str:
7474

7575
def get_exec_cmd(self, target: MFCTarget) -> typing.List[str]:
7676
cmd = []
77-
7877
if ARG("mpi"):
7978
cmd += [self.mpibin.bin] + self.mpibin.gen_params() + ARG("flags")[:]
8079

@@ -148,7 +147,13 @@ def run(self, targets: typing.List[MFCTarget]) -> None:
148147

149148
if not ARG("dry_run"):
150149
start_time = time.monotonic()
151-
system(self.get_exec_cmd(target), cwd=self.input.case_dirpath)
150+
system(
151+
self.get_exec_cmd(target), cwd=self.input.case_dirpath,
152+
env={
153+
**os.environ.copy(),
154+
'CUDA_VISIBLE_DEVICES': ','.join([str(_) for _ in ARG('gpus')])
155+
}
156+
)
152157
end_time = time.monotonic()
153158
cons.print(no_indent=True)
154159

toolchain/mfc/run/run.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,12 @@ def run_target(target: MFCTarget):
6767

6868
def run() -> None:
6969
run_targets([ get_target(_) for _ in ARG("targets")])
70+
71+
72+
def run_targets_with(targets: typing.List[MFCTarget]):
73+
pass
74+
75+
76+
def run_target_with(target: MFCTarget):
77+
run_targets_with([target])
78+

toolchain/mfc/test/case.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
'sigV' : 0.1,
7979
'rhoRV' : 0.0,
8080

81-
8281
'Monopole' : 'F',
8382
'num_mono' : 1,
8483
'Mono(1)%loc(1)' : 0.5,

0 commit comments

Comments
 (0)