|
| 1 | +module ClusterQueryUtils |
| 2 | + |
| 3 | +using Distributed |
| 4 | +using DataStructures |
| 5 | + |
| 6 | +@deprecate gethostnames hostnames |
| 7 | +export hostnames |
| 8 | +export nodenames |
| 9 | +export procs_node |
| 10 | +export nprocs_node |
| 11 | + |
| 12 | +""" |
| 13 | + gethostnames(procs = workers()) |
| 14 | +
|
| 15 | +Return the hostname of each worker in `procs`. This is obtained by evaluating |
| 16 | +`Libc.gethostname()` on each worker asynchronously. |
| 17 | +
|
| 18 | +!!! warn |
| 19 | + `gethostnames` is deprecated in favor of `hostnames` |
| 20 | +""" |
| 21 | +gethostnames |
| 22 | + |
| 23 | +""" |
| 24 | + hostnames(procs = workers()) |
| 25 | +
|
| 26 | +Return the hostname of each worker in `procs`. This is obtained by evaluating |
| 27 | +`Libc.gethostname()` on each worker asynchronously. |
| 28 | +""" |
| 29 | +function hostnames(procs = workers()) |
| 30 | + Base.depwarn("hostnames will not be exported in a future release. "* |
| 31 | + "It may be imported from the module ClusterQueryUtils", :hostnames) |
| 32 | + |
| 33 | + hostnames = Vector{String}(undef, length(procs)) |
| 34 | + |
| 35 | + @sync for (ind,p) in enumerate(procs) |
| 36 | + @async hostnames[ind] = @fetchfrom p Libc.gethostname() |
| 37 | + end |
| 38 | + return hostnames |
| 39 | +end |
| 40 | + |
| 41 | + |
| 42 | +""" |
| 43 | + nodenames(procs = workers()) |
| 44 | +
|
| 45 | +Return the unique hostnames that the workers in `procs` lie on. |
| 46 | +On an HPC system these are usually the hostnames of the nodes involved. |
| 47 | +""" |
| 48 | +nodenames(procs = workers()) = nodenames(hostnames(procs)) |
| 49 | + |
| 50 | +function nodenames(hostnames::AbstractVector{String}) |
| 51 | + Base.depwarn("nodenames will not be exported in a future release. "* |
| 52 | + "It may be imported from the module ClusterQueryUtils", :nodenames) |
| 53 | + |
| 54 | + unique(hostnames) |
| 55 | +end |
| 56 | + |
| 57 | +""" |
| 58 | + procs_node(procs = workers()) |
| 59 | +
|
| 60 | +Return the worker ids on each host of the cluster. |
| 61 | +On an HPC system this would return the workers on each node. |
| 62 | +""" |
| 63 | +function procs_node(procs = workers()) |
| 64 | + hosts = hostnames(procs) |
| 65 | + nodes = nodenames(hosts) |
| 66 | + procs_node(procs, hosts, nodes) |
| 67 | +end |
| 68 | + |
| 69 | +function procs_node(procs, hosts, nodes) |
| 70 | + Base.depwarn("procs_node will not be exported in a future release. "* |
| 71 | + "It may be imported from the module ClusterQueryUtils", :procs_node) |
| 72 | + |
| 73 | + OrderedDict(node => procs[findall(isequal(node),hosts)] for node in nodes) |
| 74 | +end |
| 75 | + |
| 76 | +""" |
| 77 | + nprocs_node(procs = workers()) |
| 78 | +
|
| 79 | +Return the number of workers on each host. |
| 80 | +On an HPC system this would return the number of workers on each node. |
| 81 | +""" |
| 82 | +function nprocs_node(procs = workers()) |
| 83 | + nprocs_node(hostnames(procs)) |
| 84 | +end |
| 85 | + |
| 86 | +function nprocs_node(hostnames::AbstractVector{String}) |
| 87 | + nodes = nodenames(hostnames) |
| 88 | + nprocs_node(hostnames, nodes) |
| 89 | +end |
| 90 | + |
| 91 | +function nprocs_node(hostnames::AbstractVector, nodes::AbstractVector) |
| 92 | + Base.depwarn("nprocs_node will not be exported in a future release. "* |
| 93 | + "It may be imported from the module ClusterQueryUtils", :nprocs_node) |
| 94 | + |
| 95 | + OrderedDict(node => count(isequal(node), hostnames) for node in nodes) |
| 96 | +end |
| 97 | + |
| 98 | +function nprocs_node(d::AbstractDict) |
| 99 | + Base.depwarn("nprocs_node will not be exported in a future release. "* |
| 100 | + "It may be imported from the module ClusterQueryUtils", :nprocs_node) |
| 101 | + |
| 102 | + OrderedDict(node => length(procs) for (node, procs) in d) |
| 103 | +end |
| 104 | + |
| 105 | +end |
0 commit comments