Skip to content

Commit

Permalink
Support for Slurm 22.05 (#238)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tazend authored Jul 23, 2022
1 parent 8febf21 commit c449a67
Show file tree
Hide file tree
Showing 19 changed files with 682 additions and 4,730 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This PySlurm branch has been tested with:

* Cython (latest stable)
* Python 3.6, 3.7, 3.8, and 3.9
* Slurm 21.08
* Slurm 22.05

## Installation

Expand Down
72 changes: 72 additions & 0 deletions UPGRADE_C_API.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Contents
--------

* `Overview`_
* `Directory Structure`_
* `Requirements`_
* `Generating Code`_
* `Compiling, Updating, Testing`_

Overview
--------

This small guide shows how to update PySlurm to a new Major Slurm Release - specifically it shows
how to translate the C-API Headers into an appropriate file with cython definitions.

Directory Structure
-------------------

All the Cython definitions for Slurm can be found in the directory :code:`pyslurm/slurm/`
Essentially, the two most important files are :code:`header.pxi` and :code:`extra.pxi`.
The first one contains all auto-generated definitions, the latter one contains definitions not found in the headers directly, but exported in `libslurm.so`.

The Idea here is to simply have one branch for each Major release, e.g. `20.11`, `21.08`, `22.05` and so on.

Requirements
------------

- `autopxd2 <https://pypi.org/project/autopxd2/>`_
- C-Preprocessor (*cpp*, *clang*)
- Slurm headers (*slurm.h*, *slurmdb.h*, *slurm_errno.h*)
- Cython compiler (latest stable)

Generating Code
---------------

The script in :code:`scripts/pyslurm_bindgen.py` basically generates all of the needed definitions from the Header files.
Inside the script, `autopxd2` is used which helps to create Cython specific definitions for all structs and functions.
In addition, also all constants from the headers (`#define`) are made available with their appropriate data types.

First of all, checkout a new branch in the Repository, and give it the name
of the major release to target, for example:

.. code-block:: bash
git checkout -b 22.05
Then, simply generate the header definitions like in this example:

.. code-block:: bash
scripts/pyslurm_bindgen.py -D /directoy/with/slurm/headers > pyslurm/slurm/header.pxi
The script outputs everything to `stdout`. Simply redirect the output to the file: :code:`pyslurm/slurm/header.pxi`.

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:

- `slurm_addr_t control_addr`
- `phtread_mutex_t lock`

The compiler will otherwise complain that these are incomplete type definitions.

Compiling, Updating, Testing
----------------------------

Now with the generated headers, you can try and build pyslurm (e.g. by having a slurm installation in a virtual machine):

.. code-block:: bash
python3 setup.py build
This will likely give you a bunch of errors, since usually a few things have changed in between major releases.
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.
Loading

0 comments on commit c449a67

Please sign in to comment.