-
Notifications
You must be signed in to change notification settings - Fork 16
check process binding #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
071e5f5
check process binding
01b2607
print warnings on screen
74c7869
collect per-process warnings and only print summary
5f8b58a
assign job resources in assign_tasks_per_compute_unit function and si…
1f3a043
move into separate function
9956f96
update comment
0b114ab
add fallback when numanode is not unsupported
ff97572
also check number of nodes
07f31f0
update comments
a298989
check if hwloc is available on the system
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Check process binding from standard input in format similar to the example below, which was obtained as follows: | ||
|
|
||
| $ mpirun -np 3 --map-by slot:PE=2 bash -c \ | ||
| 'echo "$HOSTNAME $(hwloc-calc -p --hierarchical package.numanode.core.pu $(hwloc-bind --get))"' | ||
| host1 Package:0.NUMANode:3.Core:51.PU:15 Package:0.NUMANode:4.Core:8.PU:16 | ||
| host1 Package:0.NUMANode:1.Core:17.PU:5 Package:0.NUMANode:3.Core:48.PU:12 | ||
| host2 Package:0.NUMANode:3.Core:49.PU:13 Package:0.NUMANode:3.Core:50.PU:14 | ||
|
|
||
| Alternatively, if numanode is not supported (hwloc < 2.9.0): | ||
|
|
||
| $ mpirun -np 3 --map-by slot:PE=2 bash -c \ | ||
| 'echo "$HOSTNAME $(hwloc-calc -p --hierarchical package.core.pu $(hwloc-bind --get))"' | ||
| host1 Package:0.Core:51.PU:15 Package:0.Core:8.PU:16 | ||
| host1 Package:0.Core:17.PU:5 Package:0.Core:48.PU:12 | ||
| host2 Package:0.Core:49.PU:13 Package:0.Core:50.PU:14 | ||
| """ | ||
|
|
||
| import argparse | ||
| from collections import Counter, defaultdict | ||
| import sys | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Check process binding.") | ||
| parser.add_argument("--nodes", type=int, required=True, help="Expected number of nodes") | ||
| parser.add_argument("--procs", type=int, required=True, help="Expected number of processes") | ||
| parser.add_argument("--cpus-per-proc", type=int, required=True, help="Expected number of CPUs per process") | ||
| args = parser.parse_args() | ||
|
|
||
| procs = [p for p in (line.split() for line in sys.stdin) if p] | ||
| nodes = {x[0] for x in procs} | ||
| cpus_per_task = [x[1:] for x in procs] | ||
|
|
||
| num_procs = len(procs) | ||
| if num_procs != args.procs: | ||
| print(f"PROCESS BINDING ERROR: wrong number of processes: expected {args.procs}, found {num_procs}", | ||
| file=sys.stderr) | ||
|
|
||
| num_nodes = len(nodes) | ||
| if num_nodes != args.nodes: | ||
| print(f"PROCESS BINDING ERROR: wrong number of nodes: expected {args.nodes}, found {num_nodes}", | ||
| file=sys.stderr) | ||
|
|
||
| error_cpus = [] | ||
| warning_packages = [] | ||
| warning_numanodes = [] | ||
| warning_ht = [] | ||
|
|
||
| for cpus in cpus_per_task: | ||
| num_cpus = len(cpus) | ||
| if num_cpus != args.cpus_per_proc: | ||
| error_cpus.append(num_cpus) | ||
|
|
||
| packages = set() | ||
| numanodes = set() | ||
| cores_occupation = defaultdict(int) | ||
|
|
||
| for cpu in cpus: | ||
| cpu_parts = dict(item.split(':') for item in cpu.split('.')) | ||
| packages.add(cpu_parts['Package']) | ||
| if cpu_parts.get('NUMANode'): | ||
| numanodes.add(cpu_parts['NUMANode']) | ||
| cores_occupation[(cpu_parts['Package'], cpu_parts['Core'])] += 1 | ||
|
|
||
| num_packages = len(packages) | ||
| if num_packages > 1: | ||
| warning_packages.append(num_packages) | ||
|
|
||
| num_numanodes = len(numanodes) | ||
| if num_numanodes > 1: | ||
| warning_numanodes.append(num_numanodes) | ||
|
|
||
| for _, occupation in cores_occupation.items(): | ||
| if occupation > 1: | ||
| warning_ht.append(occupation) | ||
|
|
||
| if error_cpus: | ||
| print(f"PROCESS BINDING ERROR: wrong number of cpus per process: expected {args.cpus_per_proc}," | ||
| f" found {Counter(error_cpus)}", file=sys.stderr) | ||
|
|
||
| if warning_packages: | ||
| print(f"PROCESS BINDING WARNING: processes spanning multiple packages: {Counter(warning_packages)}", | ||
| file=sys.stderr) | ||
|
|
||
| if warning_numanodes: | ||
| print(f"PROCESS BINDING WARNING: processes spanning multiple numanodes: {Counter(warning_numanodes)}", | ||
| file=sys.stderr) | ||
|
|
||
| if warning_ht: | ||
| print("PROCESS BINDING WARNING: processes with cores shared by processing units, indicating hyperthreading:" | ||
| f" {Counter(warning_ht)},", file=sys.stderr) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
| # get process binding with hwloc | ||
|
|
||
| hwlocbind=$(hwloc-bind --get) | ||
| binding=$(hwloc-calc -p -H package.numanode.core.pu "$hwlocbind" 2>/dev/null) | ||
|
|
||
| if [[ -z $binding ]]; then | ||
| # skip numanode as a fallback: not supported until hwloc v2.9.0 | ||
| binding=$(hwloc-calc -p -H package.core.pu "$hwlocbind") | ||
| fi | ||
|
|
||
| echo "$HOSTNAME $binding" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.