Skip to content

Commit c449a67

Browse files
authored
Support for Slurm 22.05 (#238)
* Organize Slurm C-API in a seperate Cython package This removes the single-file slurm.pxd and instead uses cythons capability to create cython-packages, by simple creating a file "__init__.pxd" in a folder, so that package can also be "cimported" anywhere. Nothing really changes in the pyslurm.pyx itself, importing the C-API stays the same. But now it is possible to organize the C-API a bit better, for example putting any extra functions which are not part of the slurm headers directly but found in the libslurm.so into a different file. This also directly adds the appropriate header definitions for Slurm major release 22.05 Header definitions are put into "header.pxi" Extra libslurm.so are put into "extra.pxi" Additional helpers are in "helpers.pxi" * Add a script to automatically generate new header bindings This adds a script pyslurm_bindgen.py to automatically translate Slurms header files into a single .pxd file with the help of autopxd2 Additionally, it translates any simple C-macros (#define) in the headers and makes it available in the .pxd file with its appropriate data type. It is mostly useful to upgrade to a new major slurm release. This makes the jinja2 approach obsolete and it can be deleted. * Make changes to support Slurm 22.05 remove any "const_char_ptr" obsolote references Do not use xmalloc from the (very outdated) header files anymore Instead, in slurm/libslurm_extra we are essentially defining the macros ourselves as functions, and simply wrap around slurms xcalloc, which is available in libslurm.so Actual required changes: - removes some constants which are not in the headers anymore - keep_alive_time was renamed to keepalive_time in the headers - slurmdb_stats_t stats was removed from slurmdb_job_rec_t in 22.05 See SchedMD/slurm@2f5254c - Update all version references to 22.05 * Add small guide how to update to a new major release
1 parent 8febf21 commit c449a67

19 files changed

+682
-4730
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This PySlurm branch has been tested with:
1616

1717
* Cython (latest stable)
1818
* Python 3.6, 3.7, 3.8, and 3.9
19-
* Slurm 21.08
19+
* Slurm 22.05
2020

2121
## Installation
2222

UPGRADE_C_API.rst

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
Contents
2+
--------
3+
4+
* `Overview`_
5+
* `Directory Structure`_
6+
* `Requirements`_
7+
* `Generating Code`_
8+
* `Compiling, Updating, Testing`_
9+
10+
Overview
11+
--------
12+
13+
This small guide shows how to update PySlurm to a new Major Slurm Release - specifically it shows
14+
how to translate the C-API Headers into an appropriate file with cython definitions.
15+
16+
Directory Structure
17+
-------------------
18+
19+
All the Cython definitions for Slurm can be found in the directory :code:`pyslurm/slurm/`
20+
Essentially, the two most important files are :code:`header.pxi` and :code:`extra.pxi`.
21+
The first one contains all auto-generated definitions, the latter one contains definitions not found in the headers directly, but exported in `libslurm.so`.
22+
23+
The Idea here is to simply have one branch for each Major release, e.g. `20.11`, `21.08`, `22.05` and so on.
24+
25+
Requirements
26+
------------
27+
28+
- `autopxd2 <https://pypi.org/project/autopxd2/>`_
29+
- C-Preprocessor (*cpp*, *clang*)
30+
- Slurm headers (*slurm.h*, *slurmdb.h*, *slurm_errno.h*)
31+
- Cython compiler (latest stable)
32+
33+
Generating Code
34+
---------------
35+
36+
The script in :code:`scripts/pyslurm_bindgen.py` basically generates all of the needed definitions from the Header files.
37+
Inside the script, `autopxd2` is used which helps to create Cython specific definitions for all structs and functions.
38+
In addition, also all constants from the headers (`#define`) are made available with their appropriate data types.
39+
40+
First of all, checkout a new branch in the Repository, and give it the name
41+
of the major release to target, for example:
42+
43+
.. code-block:: bash
44+
45+
git checkout -b 22.05
46+
47+
Then, simply generate the header definitions like in this example:
48+
49+
.. code-block:: bash
50+
51+
scripts/pyslurm_bindgen.py -D /directoy/with/slurm/headers > pyslurm/slurm/header.pxi
52+
53+
The script outputs everything to `stdout`. Simply redirect the output to the file: :code:`pyslurm/slurm/header.pxi`.
54+
55+
Now, 99% of the work is done for generating the headers. For the 1% left, you now need to open the generated file, search for the two follwowing statements and comment them out:
56+
57+
- `slurm_addr_t control_addr`
58+
- `phtread_mutex_t lock`
59+
60+
The compiler will otherwise complain that these are incomplete type definitions.
61+
62+
Compiling, Updating, Testing
63+
----------------------------
64+
65+
Now with the generated headers, you can try and build pyslurm (e.g. by having a slurm installation in a virtual machine):
66+
67+
.. code-block:: bash
68+
69+
python3 setup.py build
70+
71+
This will likely give you a bunch of errors, since usually a few things have changed in between major releases.
72+
Usually it is rather straightforward to adapt the code. Often only a few constants have been deleted/renamed. If no more errors are showing and it compiles, everything is done.

0 commit comments

Comments
 (0)