PaStiX Handbook  6.3.2
queue.h
Go to the documentation of this file.
1 /**
2  *
3  * @file queue.h
4  *
5  * PaStiX queue structure header.
6  *
7  * @copyright 2004-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.3.2
11  * @author Pascal Henon
12  * @author Mathieu Faverge
13  * @author Tony Delarue
14  * @date 2023-07-21
15  *
16  * @addtogroup blend_dev_queue
17  * @{
18  * This module describes the queue structure used in the analyze part of the solver.
19  * The sorting is based on a balanced tree that is partially updated at
20  * insertion and suppression.
21  *
22  **/
23 #ifndef _queue_h_
24 #define _queue_h_
25 
26 /**
27  * @brief Queue item structure.
28  */
29 typedef struct pastix_queue_item_s {
30  double key1; /**< Key 1 of the element */
31  double key2; /**< Key 2 of the element */
32  pastix_int_t eltptr; /**< Pointer to the element */
34 
35 /**
36  * @brief Queue structure.
37  */
38 typedef struct pastix_queue_s {
39  pastix_int_t size; /**< Allocated memory size */
40  volatile pastix_int_t used; /**< Number of element in the queue */
41  pastix_queue_item_t *elttab; /**< Array of the element */
42  pastix_atomic_lock_t lock; /**< Lock for insertion and removal in shared memory */
44 
46 void pqueueExit( pastix_queue_t * );
48 void pqueueClear( pastix_queue_t * );
49 void pqueuePush2( pastix_queue_t *, pastix_int_t, double, double );
51 pastix_int_t pqueuePop2 ( pastix_queue_t *, double *, double * );
52 void pqueuePrint( const pastix_queue_t * );
53 
54 /**
55  * @brief Push an element with a single key.
56  * @param[inout] q
57  * The queue structure.
58  * @param[in] elt
59  * The element to insert.
60  * @param[in] key1
61  * The first key of the element to insert (the second will be 0.).
62  */
63 static inline void
64 pqueuePush1(pastix_queue_t *q, pastix_int_t elt, double key1) {
65  pqueuePush2( q, elt, key1, 0. );
66 }
67 
68 /**
69  * @brief Pop the head of the queue whithout returning the keys.
70  * @param[inout] q
71  * The queue structure.
72  * @return The element at the head of the queue.
73  */
74 static inline pastix_int_t
76  return pqueuePop2(q, NULL, NULL);
77 }
78 
79 /**
80  * @brief Pop the head of the queue and get the associated first key.
81  * @param[inout] q
82  * The queue structure.
83  * @param[out] key1
84  * The first key of the element removed from the head of the queue.
85  * @return The element at the head of the queue.
86  */
87 static inline pastix_int_t
88 pqueuePop1(pastix_queue_t *q, double *key1){
89  return pqueuePop2(q, key1, NULL);
90 }
91 
92 #endif /* _queue_h_ */
93 
94 /**
95  * @}
96  */
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
pastix_int_t size
Definition: queue.h:39
pastix_atomic_lock_t lock
Definition: queue.h:42
pastix_int_t eltptr
Definition: queue.h:32
pastix_queue_item_t * elttab
Definition: queue.h:41
volatile pastix_int_t used
Definition: queue.h:40
void pqueuePush2(pastix_queue_t *, pastix_int_t, double, double)
Insert an element into the sorted queue.
Definition: queue.c:178
pastix_int_t pqueueRead(const pastix_queue_t *)
Read the first element of the queue.
Definition: queue.c:239
struct pastix_queue_s pastix_queue_t
Queue structure.
static void pqueuePush1(pastix_queue_t *q, pastix_int_t elt, double key1)
Push an element with a single key.
Definition: queue.h:64
void pqueueClear(pastix_queue_t *)
Reset the number of used element to 0.
Definition: queue.c:152
void pqueueExit(pastix_queue_t *)
Free the structure associated to the queue.
Definition: queue.c:110
pastix_int_t pqueuePop2(pastix_queue_t *, double *, double *)
Remove the first element of the queue and return its keys if needed.
Definition: queue.c:268
void pqueuePrint(const pastix_queue_t *)
Print the queue.
Definition: queue.c:334
pastix_int_t pqueueSize(const pastix_queue_t *)
Return the size of the queue.
Definition: queue.c:135
static pastix_int_t pqueuePop1(pastix_queue_t *q, double *key1)
Pop the head of the queue and get the associated first key.
Definition: queue.h:88
static pastix_int_t pqueuePop(pastix_queue_t *q)
Pop the head of the queue whithout returning the keys.
Definition: queue.h:75
int pqueueInit(pastix_queue_t *, pastix_int_t)
Initialize the queue structure with an initial space to store the elements.
Definition: queue.c:81
struct pastix_queue_item_s pastix_queue_item_t
Queue item structure.
Queue item structure.
Definition: queue.h:29
Queue structure.
Definition: queue.h:38