Skip to content
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

Added cluster_info #752

Merged
merged 21 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/ood_core/job/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def submit(script, after: [], afterok: [], afternotok: [], afterany: [])
raise NotImplementedError, "subclass did not define #submit"
end

# Retrieve the number of active and total cpus, nodes, and gpu nodes
# @abstract Subclass is expected to implement {#cluster_stats}
# @raise [NotImplementedError] if subclass did not define {#cluster_stats}
# @return [Hash] Quantified statistics about the cluster's active/total cpus, nodes, and gpu nodes
def cluster_stats
raise NotImplementedError, "subclass did not define #cluster_stats"
end

# Retrieve info for all jobs from the resource manager
# @abstract Subclass is expected to implement {#info_all}
# @raise [NotImplementedError] if subclass did not define {#info_all}
Expand Down
24 changes: 24 additions & 0 deletions lib/ood_core/job/adapters/slurm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ def initialize(cluster: nil, bin: nil, conf: nil, bin_overrides: {}, submit_host
@strict_host_checking = strict_host_checking
end

# Get a hash describing the number of nodes_active, nodes_total, processors_total, and processors_active
# @return [Hash] details about the cluster's active and total nodes, processors, and gpu nodes
def get_cluster_stats()
sinfo_out = call("sinfo", ["-a", "-h", "-o %A/%D/%C"]).strip.split('/')
gres_length = call("sinfo", ["-o %G"]).lines.map(&:strip).map(&:length).max
sinfo_out2 = call("sinfo", ["-N", "-h", "-a", "--Format='nodehost,gres:3#{gres_length},statelong'"])
gpu_nodes_total = sinfo_out2.lines.uniq.grep(/gpu:/).count
gpu_nodes_free = sinfo_out2.lines.uniq.grep(/gpu:/).grep(/idle/).count
{
"nodes_active": sinfo_out[0].to_i,
"nodes_total": sinfo_out[2].to_i,
"processors_total": sinfo_out[6].to_i,
"processors_active": sinfo_out[3].to_i,
"gpu_nodes_total": gpu_nodes_total,
"gpu_nodes_active": gpu_nodes_total - gpu_nodes_free
}
end
lukew3 marked this conversation as resolved.
Show resolved Hide resolved

# Get a list of hashes detailing each of the jobs on the batch server
# @example Status info for all jobs
# my_batch.get_jobs
Expand Down Expand Up @@ -454,6 +472,12 @@ def submit(script, after: [], afterok: [], afternotok: [], afterany: [])
raise JobAdapterError, e.message
end

# Retrieve info about active and total cpus, gpus, and nodes
# @return [Hash] information about cluster usage
def cluster_stats()
@slurm.get_cluster_stats()
end

# Retrieve info for all jobs from the resource manager
# @raise [JobAdapterError] if something goes wrong getting job info
# @return [Array<Info>] information describing submitted jobs
Expand Down