Slurm(3pm) | User Contributed Perl Documentation | Slurm(3pm) |
Slurm - Perl API for libslurm
use Slurm; my $slurm = Slurm::new(); $nodes = $slurm->load_node(); unless($nodes) { die "failed to load node info: " . $slurm->strerror(); }
The Slurm class provides Perl interface of the Slurm API functions in "<slurm/slurm.h>", with some extra frequently used functions exported by libslurm.
To use the API, first create a Slurm object:
$slurm = Slurm::new($conf);
Then call the desired functions:
$resp = $slurm->load_jobs();
In the following "METHODS" section, if a parameter is omitted, it will be listed as "param=val" , where "val" is the default value of the parameter.
Typically, C structures are converted to (maybe blessed) Perl hash references, with field names as hash keys. Arrays in C are converted to arrays in Perl. For example, there is a structure "job_info_msg_t":
typedef struct job_info_msg { time_t last_update; /* time of latest info */ uint32_t record_count; /* number of records */ job_info_t *job_array; /* the job records */ } job_info_msg_t;
This will be converted to a hash reference with the following structure:
{ last_update => 1285847672, job_array => [ {account => 'test', alloc_node => 'ln0', alloc_sid => 1234, ...}, {account => 'debug', alloc_node => 'ln2', alloc_sid => 5678, ...}, ... ] }
Note the missing of the "record_count" field in the hash. It can be derived from the number of elements in array "job_array".
To pass parameters to the API functions, use the corresponding hash references, for example:
$rc = $slurm->update_node({node_names => 'node[0-7]', node_state => NODE_STATE_DRAIN});
Please see "<slurm/slurm.h>" for the definition of the structures.
The enumerations and macro definitions are available in the Slurm package. If ':constant' is given when using the Slurm package, the constants will be exported to the calling package.
Please see Slurm::Constant for the available constants.
$slurm = Slurm::new($conf_file=undef);
Create a Slurm object. For now the object is just a hash reference with no members.
$errno = $slurm->get_errno();
Get the error number associated with last operation.
$str = $slurm->strerror($errno=0)
Get the string describing the specified error number.
$str = $slurm->preempt_mode_string($mode_num);
Get the string describing the specified preemt mode number.
$num = $slurm->preempt_mode_num($mode_str);
Get the preempt mode number of the specified preempt mode string.
$str = $slurm->job_reason_string($num);
Get the string representation of the specified job state reason number.
$str = $slurm->job_state_string($num);
Get the string representation of the specified job state number.
$str = $slurm->job_state_string_compact($num);
Get the compact string representation of the specified job state number.
$num = $slurm->job_state_num($str);
Get the job state number of the specified (compact) job state string.
$str = $slurm->reservation_flags_string($flags);
Get the string representation of the specified reservation flags.
$str = $slurm->node_state_string($num);
Get the string representation of the specified node state number.
$str = $slurm->node_state_string_compact($num);
Get the compact string representation of the specified node state number.
$str = $slurm->private_data_string($num);
Get the string representation of the specified private data type.
$str = $slurm->accounting_enforce_string($num);
Get the string representation of the specified accounting enforce type.
$resp = $slurm->allocate_resources($job_desc);
Allocate resources for a job request. If the requested resources are not immediately available, the slurmctld will send the job_alloc_resp_msg to the specified node and port.
$resp = $slurm->allocate_resources_blocking($job_desc, $timeout=0, $pending_callbacks=undef);
Allocate resources for a job request. This call will block until the allocation is granted, or the specified timeout limit is reached.
$resp = $slurm->allocatiion_lookup($job_id);
Retrieve info for an existing resource allocation.
$str = $slurm->read_hostfile($filename, $n);
Read a specified Slurm hostfile. The file must contain a list of Slurm NodeNames, one per line.
$msg_thr = $slurm->allocation_msg_thr_create($port, $callbacks);
Startup a message handler talking with the controller dealing with messages from the controller during an allocation.
$slurm->allocation_msg_thr_destroy($msg_thr);
Shutdown the message handler talking with the controller dealing with messages from the controller during an allocation.
$resp = $slurm->submit_batch_job($job_desc_msg);
Issue RPC to submit a job for later execution.
$rc = $slurm->job_will_run($job_desc_msg);
Determine if a job would execute immediately if submitted now.
$resp = $slurm->sbcast_lookup($job_id);
Retrieve info for an existing resource allocation including a credential needed for sbcast.
$rc = $slurm->kill_job($job_id, $signal, $batch_flag=0);
Send the specified signal to all steps of an existing job.
$rc = $slurm->kill_job_step($job_id, $step_id, $signal);
Send the specified signal to an existing job step.
$rc = $slurm->signal_job($job_id, $signal);
Send the specified signal to all steps of an existing job.
$rc = $slurm->signal_job_step($job_id, $step_id, $signal);
Send the specified signal to an existing job step.
$rc = $slurm->complete_job($job_id, $job_rc=0);
Note the completion of a job and all of its steps.
$rc = $slurm->terminate_job_step($job_id, $step_id);
Terminates a job step by sending a REQUEST_TERMINATE_TASKS rpc to all slurmd of a job step, and then calls slurm_complete_job_step() after verifying that all nodes in the job step no longer have running tasks from the job step. (May take over 35 seconds to return.)
$ctx = $slurm->step_ctx_create($params);
Create a job step and its context.
$ctx = $slurm->step_ctx_create_no_alloc($params);
Create a job step and its context without getting an allocation.
($major, $minor, $micro) = $slurm->api_version();
Get the Slurm API's version number.
$resp = $slurm->load_ctl_conf($update_time=0);
Issue RPC to get Slurm control configuration information if changed.
$slurm->print_ctl_conf($out, $conf);
Output the contents of Slurm control configuration message as loaded using "load_ctl_conf()".
$list = $slurm->ctl_conf_2_key_pairs($conf);
Put the Slurm configuration data into a List of opaque data type "config_key_pair_t".
$resp = $slurm->load_slurmd_status();
Issue RPC to get the status of slurmd daemon on this machine.
$slurm->print_slurmd_status($out, $slurmd_status);
Output the contents of slurmd status message as loaded using "load_slurmd_status()".
$slurm->print_key_pairs($out, $key_pairs, $title);
Output the contents of key_pairs which is a list of opaque data type "config_key_pair_t".
$rc = $slurm->update_step($step_msg);
Update the time limit of a job step.
$num = $slurm->job_cpus_allocated_on_node_id($job_res, $node_id);
Get the number of cpus allocated to a job on a node by node id.
$num = $slurm->job_cpus_allocated_on_node($job_res, $node_name);
Get the number of cpus allocated to a job on a node by node name.
$time = $slurm->get_end_time($job_id);
Get the expected end time for a given slurm job.
$secs = $slurm->get_rem_time($job_id);
Get the expected time remaining for a given job.
$rc = $slurm->job_node_ready($job_id);
Report if nodes are ready for job to execute now.
$resp = $slurm->load_job($job_id, $show_flags=0);
Issue RPC to get job information for one job ID.
$resp = $slurm->load_jobs($update_time=0, $show_flags=0);
Issue RPC to get all Slurm job information if changed.
$rc = $slurm->notify_job($job_id, $message);
Send message to the job's stdout, usable only by user root.
$job_id = $slurm->pid2jobid($job_pid);
Issue RPC to get the Slurm job ID of a given process ID on this machine.
$slurm->print_job_info($out, $job_info, $one_liner=0);
Output information about a specific Slurm job based upon message as loaded using "load_jobs()".
$slurm->print_job_info_msg($out, $job_info_msg, $one_liner=0);
Output information about all Slurm jobs based upon message as loaded using "load_jobs()".
$str = $slurm->sprint_job_info($job_info, $one_liner=0);
Output information about a specific Slurm job based upon message as loaded using "load_jobs()".
$rc = $slurm->update_job($job_info);
Issue RPC to a job's configuration per request only usable by user root or (for some parameters) the job's owner.
$resp = $slurm->get_job_steps($update_time=0, $job_id=NO_VAL, $step_id=NO_VAL, $show_flags=0);
Issue RPC to get specific slurm job step configuration information if changed since update_time.
$slurm->print_job_step_info_msg($out, $step_info_msg, $one_liner);
Output information about all Slurm job steps based upon message as loaded using "get_job_steps()".
$slurm->print_job_step_info($out, $step_info, $one_liner);
Output information about a specific Slurm job step based upon message as loaded using "get_job_steps()".
$str = $slurm->sprint_job_step_info($step_info, $one_liner);
Output information about a specific Slurm job step based upon message as loaded using "get_job_steps()".
$layout = $slurm->job_step_layout_get($job_id, $step_id);
Get the layout structure for a particular job step.
$resp = $slurm->job_step_stat($job_id, $step_id, $nodelist=undef);
Get status of a current step.
$resp = $slurm->job_step_get_pids($job_id, $step_id, $nodelist);
Get the complete list of pids for a given job step.
$resp = $slurm->load_node($update_time=0, $show_flags=0);
Issue RPC to get all node configuration information if changed.
$slurm->print_node_info_msg($out, $node_info_msg, $one_liner=0);
Output information about all Slurm nodes based upon message as loaded using "load_node()".
$slurm->print_node_table($out, $node_info, $one_liner=0);
Output information about a specific Slurm node based upon message as loaded using "load_node()".
$str = $slurm->sprint_node_table($node_info, $one_liner=0);
Output information about a specific Slurm node based upon message as loaded using "load_node".
$rc = $slurm->update_node($node_info);
Issue RPC to modify a node's configuration per request, only usable by user root.
$resp = $slurm->load_topo();
Issue RPC to get all switch topology configuration information.
$slurm->print_topo_info_msg($out, $topo_info_msg, $one_liner=0);
Output information about all switch topology configuration information based upon message as loaded using "load_topo()".
$slurm->print_topo_record($out, $topo_info, $one_liner);
Output information about a specific Slurm topology record based upon message as loaded using "load_topo()".
$rc = $slurm->get_select_nodeinfo($nodeinfo, $data_type, $state, $data);
Get data from a select node credential.
$resp = $slurm->load_partitions($update_time=0, $show_flags=0);
Issue RPC to get all Slurm partition configuration information if changed.
$slurm->print_partition_info_msg($out, $part_info_msg, $one_liner=0);
Output information about all Slurm partitions based upon message as loaded using "load_partitions()".
$slurm->print_partition_info($out, $part_info, $one_liner=0);
Output information about a specific Slurm partition based upon message as loaded using "load_partitions()".
$str = $slurm->sprint_partition_info($part_info, $one_liner=0);
Output information about a specific Slurm partition based upon message as loaded using "load_reservations()".
$rc = $slurm->create_partition($part_info);
Create a new partition, only usable by user root.
$rc = $slurm->update_partition($part_info);
Issue RPC to update a partition's configuration per request, only usable by user root.
$rc = $slurm->delete_partition($part_info)
Issue RPC to delete a partition, only usable by user root.
$name = $slurm->create_reservation($resv_info);
Create a new reservation, only usable by user root.
$rc = $slurm->update_reservation($resv_info);
Modify an existing reservation, only usable by user root.
$rc = $slurm->delete_reservation($resv_info);
Issue RPC to delete a reservation, only usable by user root.
$resp = $slurm->load_reservations($update_time=0);
Issue RPC to get all Slurm reservation configuration information if changed.
$slurm->print_reservation_info_msg($out, $resv_info_msg, $one_liner=0);
Output information about all Slurm reservations based upon message as loaded using "load_reservation()".
$slurm->print_reservation_info($out, $resv_info, $one_liner=0);
Output information about a specific Slurm reservation based upon message as loaded using "load_reservation()".
$str = $slurm->sprint_reservation_info($resv_info, $one_liner=0);
Output information about a specific Slurm reservation based upon message as loaded using "load_reservations()".
$rc = $slurm->ping($primary);
Issue RPC to ping Slurm controller (slurmctld).
$rc = $slurm->reconfigure()
Issue RPC to have Slurm controller (slurmctld) reload its configuration file.
$rc = $slurm->shutdown($options);
Issue RPC to have Slurm controller (slurmctld) cease operations, both the primary and backup controller are shutdown.
$rc = $slurm->takeover();
Issue RPC to have Slurm backup controller take over the primary controller. REQUEST_CONTROL is sent by the backup to the primary controller to take control.
$rc = $slurm->set_debug_level($debug_level)
Issue RPC to set slurm controller debug level.
$rc = $slurm->set_schedlog_level($schedlog_level);
Issue RPC to set slurm scheduler log level.
$rc = $slurm->suspend($job_id);
Suspend execution of a job.
$rc = $slurm->resume($job_id);
Resume execution of a previously suspended job.
$rc = $slurm->requeue($job_id);
Re-queue a batch job, if already running then terminate it first.
$rc = $slurm->set_trigger($trigger_info);
Set an event trigger.
$rc = $slurm->clear_trigger($trigger_info);
Clear an existing event trigger.
$resp = $slurm->get_triggers();
Get all event trigger information.
The following are functions to test job/node state, based on the macros defined in src/common/slurm_protocol_defs.h. The functions take a parameter of a hash reference of a job/node, and return a boolean value. For job, $job->{job_state} is tested. For node, $node->{node_state} is tested.
$cond = IS_JOB_PENDING($job);
$cond = IS_JOB_RUNNING($job);
$cond = IS_JOB_SUSPENDED($job);
$cond = IS_JOB_COMPLETE($job);
$cond = IS_JOB_CANCELLED($job);
$cond = IS_JOB_FAILED($job);
$cond = IS_JOB_TIMEOUT($job);
$cond = IS_JOB_NODE_FAILED($job);
$cond = IS_JOB_COMPLETING($job);
$cond = IS_JOB_CONFIGURING($job);
$cond = IS_JOB_STARTED($job);
$cond = IS_JOB_FINISHED($job);
$cond = IS_JOB_COMPLETED($job);
$cond = IS_JOB_RESIZING($job);
$cond = IS_NODE_UNKNOWN($node);
$cond = IS_NODE_DOWN($node);
$cond = IS_NODE_IDLE($node);
$cond = IS_NODE_ALLOCATED($node);
$cond = IS_NODE_ERROR($node);
$cond = IS_NODE_MIXED($node);
$cond = IS_NODE_FUTURE($node);
$cond = IS_NODE_DRAIN($node);
$cond = IS_NODE_DRAINING($node);
$cond = IS_NODE_DRAINED($node);
$cond = IS_NODE_COMPLETING($node);
$cond = IS_NODE_NO_RESPOND($node);
$cond = IS_NODE_POWERED_DOWN($node);
$cond = IS_NODE_POWER_UP($node);
$cond = IS_NODE_FAIL($node);
$cond = IS_NODE_MAINT($node);
The job/node state testing functions are exported by default.
If ':constant' if specified, all constants are exported.
Slurm::Constant, Slurm::Hostlist, Slurm::Bitstr
<slurm/slurm.h> for various hash reference structures.
Home page of Slurm: <http://slurm.schedmd.com>.
This library is created by Hongjia Cao, <hjcao(AT)nudt.edu.cn> and Danny Auble, <da(AT)llnl.gov>. It is distributed with Slurm.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.
2023-12-25 | perl v5.36.0 |