[slurm-dev] spank plugin <- job information

40 views
Skip to first unread message

Danny Marc Rotscher

unread,
Jan 30, 2017, 8:53:11 AM1/30/17
to slurm-dev
Hello everybody,

does anybody of you know, how I can get job information in a spank plugin?
Especially I want to know if a job is exclusive or not.

Kind regards,
Danny

Sam Gallop (NBI)

unread,
Jan 30, 2017, 9:59:00 AM1/30/17
to slurm-dev
Hi,

This is how I gather job information via a SPANK plugin (see below). It's pretty crude but it dumps some job and step information into a file in /tmp. As for determining whether a job is exclusive or not. I've not seen a variable containing that information. I believe you would have to determine whether all the CPUs on the host have been assigned to the job. For example, I submitted an exclusive job requesting 1 CPU. Part of the output of the below plugin tells me I have 3 CPUs on my node (yes, it’s a very small node) and my job has all 3 CPUs allocated ...

<snip>
SLURM_CPUS_ON_NODE=3
SLURM_JOB_CPUS_PER_NODE=3
<snip>

I am therefore exclusive.

# cat userenv.c
/*
* To compile:
* gcc -shared -o userenv.so userenv.c
*
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <libgen.h>
#include <signal.h>
#include <sys/resource.h>

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

SPANK_PLUGIN(userenv, 1);

static int _userenv_opt_process (int val,
const char *optarg,
int remote);
void get_env(spank_t sp, char *function);

struct spank_option spank_options[] =
{
{
"userenv",
"",
"helper function",
0,
0,
(spank_opt_cb_f) _userenv_opt_process
},
SPANK_OPTIONS_TABLE_END
};

int slurm_spank_task_init(spank_t sp, int ac, char **av)
{
FILE *f;
char filename[256];
char function[50];
int i, argc;
char **argv;
char **env;
uint32_t s_id;

sprintf(function, "slurm_spank_task_init");

if (spank_get_item(sp, S_JOB_ID, &s_id) != ESPANK_SUCCESS) {
slurm_info("userenv: Failed to get id");
return (0);
}

sprintf(filename, "/tmp/%s_%d_%d", function, spank_context(), s_id);
f = fopen(filename, "w");

if (spank_get_item(sp, S_JOB_ARGV, &argc, &argv) == ESPANK_SUCCESS) {
for (i = 0; i < argc; i++) {
fprintf(f, "%s (ARGV): %s\n", function, argv[i]);
}
}

if (spank_get_item(sp, S_JOB_ENV, &env) == ESPANK_SUCCESS) {
while (*env != NULL) {
fprintf(f, "%s (ENV): %s\n", function, *env);
++env;
}
}

fclose(f);
}

static int _userenv_opt_process(int val, const char *optarg, int remote)
{
slurm_info("userenv: userenv plugin has been registered");
return (0);
}


---
Sam Gallop


Have you tried looking through our Documentation Portal
Our documentation isn’t all text, check out our Video Tutorials
Have you tried looking through CiS Service Desk
Keep up to date with availability at CiS Service Status
More information on our HPC, Linux, Storage at HPC Support Site

To speak to us about technical issues feel free to call the Computing infrastructure for Science team on group phone extension 2003.
If your request is urgent, please contact the NBIP Computing Helpdesk at computing...@nbi.ac.uk or call phone extension 1234.

Sam Gallop (NBI)

unread,
Jan 30, 2017, 10:12:14 AM1/30/17
to slurm-dev
Reply all
Reply to author
Forward
0 new messages