---
name: "Slurm::Stepctx"
section: "3pm"
platform: "linux"
package: "libslurm-perl"
version: "20.11.7+really20.11.4-2+deb11u1"
release: "Debian 11 (Bullseye)"
platforms: ["linux"]
url: "https://new.carta.tech/Slurm::Stepctx"
---

# Slurm::Stepctx(3pm)

Step launching functions in libslurm

## NAME

Slurm::Stepctx - Step launching functions in libslurm

## SYNOPSIS

```
 use Slurm;
 $slurm = Slurm::new();
 $params = {job_id => 1234, ...};
 $ctx = $slurm->step_ctx_create($params);
 $rc = $ctx->launch({...}, {task_start => sub {...},
                         task_finish => sub {...} });
```

## DESCRIPTION

The Slurm::Stepctx class is a wrapper of the job step context and step launching functions in libslurm. This package is loaded and bootstraped with package Slurm.

## METHODS

### STEP CONTEXT CREATION FUNCTIONS

Please see "SLURM TASK SPAWNING FUNCTIONS" in Slurm for step context creation functions.

### STEP CONTEXT MANIPULATION FUNCTIONS

*$rc = $ctx-\>get($ctx\_key, ...);*

Get parameters from a job step context.

- •

  INPUT `$ctx_key:` type of the parameter to get. Supported key and the corresponding result data are:

  - •

    `$rc` = `$ctx`-\>get(SLURM\_STEP\_CTX\_STEPID, `$stepid`);

    Get the created job step id. `$stepid` will be set to the step id number.

  - •

    `$rc` = `$ctx`-\>get(SLURM\_STEP\_CTX\_TASKS, `$tasks`);

    Get array of task count on each node. `$tasks` will be set to an array reference.

  - •

    `$rc` = `$ctx`-\>get(SLURM\_STEP\_CTX\_TID, `$nodeid`, `$tids`);

    Get array of task IDs for specified node. `$nodeid` specifies index of the node. `$tids` will be set to an array reference.

  - •

    `$rc` = `$ctx`-\>get(SLURM\_STEP\_CTX\_RESP, `$resp`);

    TODO: this is not exported. Get job step create response message.

  - •

    `$rc` = `$ctx`-\>get(SLURM\_STEP\_CTX\_CRED, `$cred`);

    Get credential of the created job step. `$cred` will be an opaque object blessed to "Slurm::slurm\_cred\_t".

  - •

    `$rc` = `$ctx`-\>get(SLURM\_STEP\_CTX\_SWITCH\_JOB, `$switch_info`);

    Get switch plugin specific info of the step. `$switch_info` will be an opaque object blessed to "Slurm::dynamic\_plugin\_data\_t".

  - •

    `$rc` = `$ctx`-\>get(SLURM\_STEP\_CTX\_NUM\_HOSTS, `$num`);

    Get number of nodes allocated to the job step.

  - •

    `$rc` = `$ctx`-\>get(SLURM\_STEP\_CTX\_HOST, `$nodeid`, `$nodename`);

    Get node name allocated to the job step. `$nodeid` specifies index of the node.

  - •

    `$rc` = `$ctx`-\>get(SLURM\_STEP\_CTX\_JOBID, `$jobid`);

    Get job ID of the job step.

  - •

    `$rc` = `$ctx`-\>get(SLURM\_STEP\_CTX\_USER\_MANAGED\_SOCKETS, `$numtasks`, `$sockets`);

    Get user managed I/O sockets. TODO: describe the parameters.

- •

  RET: error code.

*$rc = $ctx-\>daemon\_per\_node\_hack($node\_list, $node\_cnt, $curr\_task\_num);*

Hack the step context to run a single process per node, regardless of the settings selected at **Slurm::Stepctx::create()** time.

- •

  RET: error code.

### STEP TASK LAUNCHING FUNCTIONS

*$rc = $ctx-\>launch($params, $callbacks);*

Launch a parallel job step.

- •

  IN `$params:` parameters of task launching, with structure of `"slurm_step_launch_params_t"`.

- •

  IN `$callbacks:` callback functions, with structure of `"slurm_step_launch_callbacks_t"`. NOTE: the callback functions will be called in a thread different from the thread calling the `"launch()"` function.

- •

  RET: error code.

*$rc = $ctx-\>****launch\_wait\_start()****;*

Block until all tasks have started.

- •

  RET: error code.

*$ctx-\>****launch\_wait\_finish()****;*

Block until all tasks have finished (or failed to start altogether).

*$ctx-\>****launch\_abort()****;*

Abort an in-progress launch, or terminate the fully launched job step. Can be called from a signal handler.

*$ctx-\>launch\_fwd\_signal($signo);*

Forward a signal to all those nodes with running tasks.

- •

  IN `$signo:` signal number.

## SEE ALSO

Slurm

## AUTHOR

This library is created by Hongjia Cao, \<hjcao(AT)nudt.edu.cn\> and Danny Auble, \<da(AT)llnl.gov\>. It is distributed with Slurm.

## COPYRIGHT AND LICENSE

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.
