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
-----Original Message-----
From: Danny Marc Rotscher [mailto:[email protected]]
Sent: 30 January 2017 13:53
To: slurm-dev <[email protected]>
Subject: [slurm-dev] spank plugin <- job information
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