Hi -

I'm trying to understand the slurmdb API better so i wrote a small C
program that just goes through the TRESs (slurmdb_tres_get) and QOSs
(slurmdb_qos_get) which works fine. However, i have a few things i'm not
sure i understand correctly:

(1) the `max_wall_pj` field in the `slurmdb_qos_rec_t` struct seems to
    be set to `INFINITE` when no limit was set in a QOS. Is that
    correct?

(2) Is this the correct way to determine if the OverPartQOS flag is set
    in a qos (based on the `flags` field in `slurmdb_qos_rec_t`):

       (qos->flags & QOS_FLAG_BASE) & QOS_FLAG_OVER_PART_QOS

(3) the `max_tres_pu` field contains a string describing the tres
    limits. For example `1=128,1003=8` where 1 is the id of the CPU
    TRES and 1003 corresponts to the gres/gpu. Based on the comment
    in the source code `max_tres_pu_ctld` sounds like it might
    contain an array of just the values from that string but it
    seems to be set to NULL. What is the most straight forward way
    to get the TRES limit for a particular TRES out of `max_tres_pu`?

Thanks in advance for any input. Code is attached for reference.

Regards,
Wolfgang
--
Wolfgang Resch, PhD
Computational Biologist
HPC @ NIH staff
Twitter: @nih_hpc
301.451.4345
#define _GNU_SOURCE

#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

#include "slurm/slurm.h"
#include "slurm/slurmdb.h"

#define xstr(s) str(s)
#define str(s) #s

/******************************************************************************/
/*                                    main                                    */
/******************************************************************************/
int main(void)
{
    int rc = 0;
    int cpu_tres_idx = 0;
    char intstr[30] = {'\0'};

    // QOSs
    List qos_list = NULL;
    ListIterator qos_iter = NULL;
    slurmdb_qos_rec_t *qos = NULL;

    // TRES (not really needed here - just curiosity)
    List tres_list = NULL;
    ListIterator tres_iter = NULL;
    slurmdb_tres_rec_t *tres = NULL;

    printf("Slurm version: %s\n", xstr(SLURM_VER));
    printf("Slurm library: %s\n", xstr(SLURM));
    
    void * db_conn = slurmdb_connection_get();
    if (!db_conn) {
        rc = EXIT_FAILURE;
        goto cleanup;
    }

    // figure out at what index in the list the CPU TRES is  
--------------------------
    tres_list = slurmdb_tres_get(db_conn, NULL);
    if (!tres_list) {
        rc = EXIT_FAILURE;
        goto cleanup;
    }
    tres_iter = slurm_list_iterator_create(tres_list);
    if (!tres_iter) {
        rc = EXIT_FAILURE;
        goto cleanup;
    }
    while ((tres = slurm_list_next(tres_iter))) {
        if (strcmp(tres->type, "cpu") == 0) {
            printf("CPU TRES:      index=%i id=%"PRIu32"\n", cpu_tres_idx,
                    tres->id);
            break;
        }
        cpu_tres_idx++;
    }
    if (slurm_list_count(tres_list) == cpu_tres_idx) {
        printf("Could not find CPU tres");
        rc = EXIT_FAILURE;
        goto cleanup;
    }

    
    // find all the QOSs 
--------------------------------------------------------------
    qos_list = slurmdb_qos_get(db_conn, NULL);
    if (!qos_list) {
        rc = EXIT_FAILURE;
        goto cleanup;
    }

    // iterate through list
    printf("Found %i QOSs in the database\n", slurm_list_count(qos_list));
    qos_iter = slurm_list_iterator_create(qos_list);
    if (!qos_iter) {
        rc = EXIT_FAILURE;
        goto cleanup;
    }
    
    while ((qos = slurm_list_next(qos_iter))) {
        if (qos->max_wall_pj == NO_VAL) {
            snprintf(intstr, 30, "NO_VAL");
        } else if (qos->max_wall_pj == INFINITE) {
            snprintf(intstr, 30, "INFINITE");
        } else {
            snprintf(intstr, 30, "%"PRIu32, qos->max_wall_pj);
        }

        printf("name=%-12s OverPartQOS=%-3s  max_wall_pj=%-10s 
max_tres_pu=%-12s flags=0x%08x\n", 
                qos->name,
                (qos->flags & QOS_FLAG_BASE) & QOS_FLAG_OVER_PART_QOS ? "yes" : 
"no" ,
                intstr,
                qos->max_tres_pu,
                qos->flags);
    }


cleanup:
    if (qos_iter) slurm_list_iterator_destroy(qos_iter);
    if (qos_list) slurm_list_destroy(qos_list);
    if (tres_iter) slurm_list_iterator_destroy(tres_iter);
    if (tres_list) slurm_list_destroy(tres_list);
    if (db_conn) slurmdb_connection_close(&db_conn);
    return rc;
}

Reply via email to