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

# slurm\_step\_ctx\_create(3)

Slurm task spawn functions

## NAME

slurm\_step\_ctx\_create, slurm\_step\_ctx\_create\_no\_alloc, slurm\_step\_ctx\_daemon\_per\_node\_hack, slurm\_step\_ctx\_get, slurm\_step\_ctx\_params\_t\_init, slurm\_jobinfo\_ctx\_get, slurm\_spawn\_kill, slurm\_step\_ctx\_destroy - Slurm task spawn functions

## SYNTAX

\#include \<slurm/slurm.h\>

slurm\_step\_ctx **slurm\_step\_ctx\_create** (\
\
 	slurm\_step\_ctx\_params\_t \**step\_req*\
 );

slurm\_step\_ctx **slurm\_step\_ctx\_create\_no\_alloc** (\
\
 	slurm\_step\_ctx\_params\_t \**step\_req*\
 );

int **slurm\_step\_ctx\_daemon\_per\_node\_hack** (\
\
 	slurm\_step\_ctx\_t \**ctx*\
 );

int **slurm\_step\_ctx\_get** (\
\
 	slurm\_step\_ctx\_t \**ctx*,\
\
 	int *ctx\_key*,\
\
 	...\
 );

int **slurm\_jobinfo\_ctx\_get** (\
\
 	switch\_jobinfo\_t *jobinfo*,\
\
 	int *data\_type*,\
\
 	void \**data*\
 );

void **slurm\_step\_ctx\_params\_t\_init** (\
\
 	slurm\_step\_ctx\_params\_t \**step\_req*\
 );

int **slurm\_spawn** {\
\
 	slurm\_step\_ctx *ctx*,\
\
 	int \**fd\_array*\
 );

int **slurm\_spawn\_kill** {\
\
         slurm\_step\_ctx *ctx*,\
\
 	uint16\_t *signal*\
 );

int **slurm\_step\_ctx\_destroy** {\
\
 	slurm\_step\_ctx *ctx*\
 );

## ARGUMENTS

- *step\_req*

  Specifies the pointer to the structure with job step request specification. See slurm.h for full details on the data structure's contents.

- *ctx*

  Job step context. Created by **slurm\_step\_ctx\_create**, or **slurm\_step\_ctx\_create\_no\_alloc** used in subsequent function calls, and destroyed by **slurm\_step\_ctx\_destroy**.

- *ctx\_key*

  Identifies the fields in *ctx* to be collected by **slurm\_step\_ctx\_get**.

- *data*

  Storage location for requested data. See *data\_type* below.

- *data\_type*

  Switch-specific data requested. The interpretation of this field depends upon the switch plugin in use.

- *fd\_array*

  Array of socket file descriptors to be connected to the initiated tasks. Tasks will be connected to these file descriptors in order of their task id. This socket will carry standard input, output and error for the task. *jobinfo* Switch-specific job information as returned by **slurm\_step\_ctx\_get**.

- *signal*

  Signal to be sent to the spawned tasks.

## DESCRIPTION

**slurm\_jobinfo\_ctx\_get** Get values from a *jobinfo* field as returned by **slurm\_step\_ctx\_get**. The operation of this function is highly dependent upon the switch plugin in use.

**slurm\_step\_ctx\_create** Create a job step context. To avoid memory leaks call **slurm\_step\_ctx\_destroy** when the use of this context is finished. NOTE: this function creates a slurm job step. Call **slurm\_spawn** in a timely fashion to avoid having job step credentials time out. If **slurm\_spawn** is not used, explicitly cancel the job step.

**slurm\_step\_ctx\_create\_no\_alloc** Same as above, only no allocation is made. To avoid memory leaks call **slurm\_step\_ctx\_destroy** when the use of this context is finished.

**slurm\_step\_ctx\_daemon\_per\_node\_hack** Hack the step context to run a single process per node, regardless of the settings selected at slurm\_step\_ctx\_create time.

**slurm\_step\_ctx\_get** Get values from a job step context. *ctx\_key* identifies the fields to be gathered from the job step context. Subsequent arguments to this function are dependent upon the value of *ctx\_key*. See the **CONTEXT KEYS** section for details.

**slurm\_step\_ctx\_params\_t\_init** This initializes parameters in the structure that you will pass to slurm\_step\_ctx\_create().

**slurm\_spawn** Spawn tasks based upon a job step context and establish communications with the tasks using the socket file descriptors specified. Note that this function can only be called once for each job step context. Establish a new job step context for each set of tasks to be spawned.

**slurm\_spawn\_kill** Signal the tasks spawned for this context by **slurm\_spawn**.

**slurm\_step\_ctx\_destroy** Destroy a job step context created by **slurm\_step\_ctx\_create**.

## CONEXT KEYS

- **SLURM\_STEP\_CTX\_ARGS**

  Set the argument count and values for the executable. Accepts two additional arguments, the first of type int and the second of type char \*\*.

- **SLURM\_STEP\_CTX\_CHDIR**

  Have the remote process change directory to the specified location before beginning execution. Accepts one argument of type char \* identifying the directory's pathname. By default the remote process will execute in the same directory pathname from which it is spawned. NOTE: This assumes that same directory pathname exists on the other nodes.

- **SLURM\_STEP\_CTX\_ENV**

  Sets the environment variable count and values for the executable. Accepts two additional arguments, the first of type int and the second of type char \*\*. By default the current environment variables are copied to started task's environment.

- **SLURM\_STEP\_CTX\_RESP**

  Get the job step response message. Accepts one additional argument of type job\_step\_create\_response\_msg\_t \*\*.

- **SLURM\_STEP\_CTX\_STEPID**

  Get the step id of the created job step. Accepts one additional argument of type uint32\_t \*.

- **SLURM\_STEP\_CTX\_TASKS**

  Get the number of tasks per node for a given job. Accepts one additional argument of type uint32\_t \*\*. This argument will be set to point to an array with the task counts of each node in an element of the array. See **SLURM\_STEP\_CTX\_TID** below to determine the task ID numbers associated with each of those tasks.

- **SLURM\_STEP\_CTX\_TID**

  Get the task ID numbers associated with the tasks allocated to a specific node. Accepts two additional arguments, the first of type int and the second of type uint32\_t \*\*. The first argument identifies the node number of interest (zero origin). The second argument will be set to point to an array with the task ID numbers of each task allocated to the node (also zero origin). See **SLURM\_STEP\_CTX\_TASKS** above to determine how many tasks are associated with each node.

## RETURN VALUE

For  **slurm\_step\_ctx\_create** a context is return upon success. On error NULL is returned and the Slurm error code is set appropriately.

For all other functions zero is returned upon success. On error, -1 is returned, and the Slurm error code is set appropriately.

## ERRORS

**EINVAL** Invalid argument

**SLURM\_PROTOCOL\_VERSION\_ERROR** Protocol version has changed, re-link your code.

**ESLURM\_INVALID\_JOB\_ID** the requested job id does not exist.

**ESLURM\_ALREADY\_DONE** the specified job has already completed and can not be modified.

**ESLURM\_ACCESS\_DENIED** the requesting user lacks authorization for the requested action (e.g. trying to delete or modify another user's job).

**ESLURM\_DISABLED** the ability to create a job step is currently disabled. This is indicative of the job being suspended. Retry the call as desired.

**ESLURM\_INTERCONNECT\_FAILURE** failed to configure the node interconnect.

**ESLURM\_BAD\_DIST** task distribution specification is invalid.

**SLURM\_PROTOCOL\_SOCKET\_IMPL\_TIMEOUT** Timeout in communicating with Slurm controller.

## EXAMPLE

SEE [**slurm\_step\_launch**(3)](/slurm_step_launch/3.md) man page for an example of slurm\_step\_ctx\_create and slurm\_step\_launch in use together.

## NOTE

These functions are included in the libslurm library, which must be linked to your process for use (e.g. "cc -lslurm myprog.c").

## COPYING

Copyright (C) 2004-2007 The Regents of the University of California. Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). CODE-OCEC-09-009. All rights reserved.

This file is part of Slurm, a resource management program. For details, see \<https://slurm.schedmd.com/\>.

Slurm is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Slurm is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

## SEE ALSO

[**slurm\_allocate\_resources**(3)](/slurm_allocate_resources/3.md), [**slurm\_job\_step\_create**(3)](/slurm_job_step_create/3.md), [**slurm\_kill\_job**(3)](/slurm_kill_job/3.md), [**slurm\_get\_errno**(3)](/slurm_get_errno/3.md), [**slurm\_perror**(3)](/slurm_perror/3.md), [**slurm\_strerror**(3)](/slurm_strerror/3.md), [**srun**(1)](/srun/1.md)
