PaStiX Handbook 6.4.0
Loading...
Searching...
No Matches
starpu_tags.c
Go to the documentation of this file.
1/**
2 *
3 * @file starpu_tags.c
4 *
5 * @copyright 2017-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
6 * Univ. Bordeaux. All rights reserved.
7 *
8 * @version 6.4.0
9 * @author Pierre Ramet
10 * @author Mathieu Faverge
11 * @date 2024-07-05
12 *
13 * Functions to manage the MPI data tags.
14 *
15 * @addtogroup pastix_starpu
16 * @{
17 *
18 **/
19#include "common.h"
20#if !defined(PASTIX_WITH_STARPU)
21#error "This file should not be compiled if Starpu is not enabled"
22#endif
23#include "pastix_starpu.h"
24
25#if defined(PASTIX_WITH_MPI)
26
27/**
28 * @brief Structure Pastix StarPU tag
29 *
30 * List structure to manage the set of available tags.
31 */
32struct pst_range_;
33typedef struct pst_range_ pst_range_t;
34
35struct pst_range_ {
36 int64_t min; /**< Minimal value in the range */
37 int64_t max; /**< Maximal value in the range */
38 pst_range_t *next; /**< Pointer to the following range */
39};
40
41/**
42 * @brief Pointer to the first set or registered tags
43 */
44static pst_range_t *pst_first = NULL;
45
46/**
47 * @brief StarPU tag upper bound
48 */
49static int64_t starpu_tag_ub = 0;
50
51/**
52 *******************************************************************************
53 *
54 * @brief Initialize the StarPU tags manager.
55 *
56 *******************************************************************************
57 *
58 * @param[in] pastix
59 * The main pastix_data structure to provide the MPI communicator.
60 *
61 *******************************************************************************
62 *
63 * @retval TODO
64 *
65 ******************************************************************************/
66int
68{
69 if (!starpu_tag_ub) {
70 int ok = 0;
71 void *tag_ub_p = NULL;
72
73 starpu_mpi_comm_get_attr( pastix->inter_node_comm, STARPU_MPI_TAG_UB, &tag_ub_p, &ok );
74 starpu_tag_ub = (uint64_t)((intptr_t)tag_ub_p);
75
76 if ( !ok ) {
77 pastix_print_error("pastix_starpu_tag_init: MPI_TAG_UB not known by StarPU\n");
78 }
79
80 return PASTIX_SUCCESS;
81 }
82 else {
84 }
85}
86
87/**
88 *******************************************************************************
89 *
90 * @brief Book a range of StarPU unique tags of size nbtags.
91 *
92 * This function returns the minimal tag value available to allow the
93 * registration of nbtags data in a continuous range.
94 *
95 * Note that this function must be called exactly the same way on all nodes to
96 * make sure the tags are identical from one node to another.
97 *
98 *******************************************************************************
99 *
100 * @param[in] nbtags
101 * The number of tags required to register the sparse matrix or right
102 * hand side.
103 *
104 *******************************************************************************
105 *
106 * @return V, the minimal tag value to use. The range [V:V+nbtags-1] is booked.
107 *
108 ********************************************************************************/
109int64_t
110pastix_starpu_tag_book( int64_t nbtags )
111{
112 pst_range_t *new;
113 pst_range_t *prev = NULL;
114 pst_range_t *current = pst_first;
115 int64_t min = 0;
116 int64_t max = ( current == NULL ) ? starpu_tag_ub : current->min;
117
118 assert( starpu_tag_ub != 0 ); /* StarPU tag must be initialized */
119
120 while ( ((max - min) < nbtags) && (current != NULL) ) {
121 min = current->max;
122 prev = current;
123 current = current->next;
124 max = ( current == NULL ) ? starpu_tag_ub : current->min;
125 }
126
127 if ( (max - min) < nbtags ) {
128 pastix_print_error( "pastix_starpu_tag_book: No space left in tags (looking for %ld tags)\n",
129 (long)nbtags );
130 return -1;
131 }
132
133 new = malloc( sizeof( pst_range_t ) );
134 new->min = min;
135 new->max = min + nbtags;
136 new->next = current;
137 if ( prev == NULL ) {
138 pst_first = new;
139 }
140 else {
141 assert( prev->next == current );
142 prev->next = new;
143 }
144
145#if defined(PASTIX_DEBUG_STARPU)
146 fprintf( stderr, "pastix_starpu_tag: Book %ld - %ld\n",
147 (long)min, (long)(min + nbtags) );
148#endif
149
150 assert( pst_first != NULL );
151 return new->min;
152}
153
154/**
155 *******************************************************************************
156 *
157 * @brief Release the set of tags starting by min.
158 *
159 * This function releases the range of tags that starts by the min value.
160 *
161 *******************************************************************************
162 *
163 * @param[in] min
164 * The initial value in the range
165 *
166 ******************************************************************************/
167void
168pastix_starpu_tag_release( int64_t min )
169{
170 pst_range_t *prev = NULL;
171 pst_range_t *current = pst_first;
172
173 assert( pst_first != NULL ); /* At least one range must be registered */
174
175 while ( (current != NULL) && (current->min < min) ) {
176 prev = current;
177 current = current->next;
178 }
179
180 assert( current != NULL );
181 assert( current->min == min );
182
183 if ( prev ) {
184 prev->next = current->next;
185 }
186 else {
187 assert( current == pst_first );
188 pst_first = current->next;
189 }
190
191#if defined(PASTIX_DEBUG_STARPU)
192 fprintf( stderr, "pastix_starpu_tag: Release %ld - %ld\n",
193 (long)current->min, (long)current->max );
194#endif
195
196 free( current );
197
198 return;
199}
200
201#else /* defined(PASTIX_WITH_MPI) */
202
203/**
204 *******************************************************************************
205 *
206 * @brief Initialize the StarPU tags manager.
207 *
208 *******************************************************************************
209 *
210 * @param[in] pastix_data
211 * The main pastix_data structure to provide the MPI communicator.
212 *
213 *******************************************************************************
214 *
215 * @retval TODO
216 *
217 ******************************************************************************/
218int
219pastix_starpu_tag_init( __attribute__((unused)) pastix_data_t *pastix_data ) {
220 return PASTIX_SUCCESS;
221}
222
223/**
224 *******************************************************************************
225 *
226 * @brief Book a range of StarPU unique tags of size nbtags.
227 *
228 * This function returns the minimal tag value available to allow the
229 * registration of nbtags data in a continuous range.
230 *
231 * Note that this function must be called exactly the same way on all nodes to
232 * make sure the tags are identical from one node to another.
233 *
234 *******************************************************************************
235 *
236 * @param[in] nbtags
237 * The number of tags required to register the sparse matrix or right
238 * hand side.
239 *
240 *******************************************************************************
241 *
242 * @return V, the minimal tag value to use. The range [V:V+nbtags-1] is booked.
243 *
244 ********************************************************************************/
245int64_t
246pastix_starpu_tag_book( __attribute__((unused)) int64_t nbtags ) {
247 return 0;
248}
249
250/**
251 *******************************************************************************
252 *
253 * @brief Release the set of tags starting by min.
254 *
255 * This function releases the range of tags that starts by the min value.
256 *
257 *******************************************************************************
258 *
259 * @param[in] min
260 * The initial value in the range
261 *
262 ******************************************************************************/
263void
264pastix_starpu_tag_release( __attribute__((unused)) int64_t min ) {
265 return;
266}
267
268#endif
269
270/**
271 * @}
272 */
BEGIN_C_DECLS int pastix(pastix_data_t **pastix_data, PASTIX_Comm pastix_comm, pastix_int_t n, pastix_int_t *colptr, pastix_int_t *rowptr, void *values, pastix_int_t *perm, pastix_int_t *invp, void *B, pastix_int_t nrhs, pastix_int_t *iparm, double *dparm)
Main function for compatibility with former releases.
Definition pastix.c:103
@ PASTIX_ERR_INTERNAL
Definition api.h:373
@ PASTIX_SUCCESS
Definition api.h:367
int64_t pastix_starpu_tag_book(int64_t nbtags)
Book a range of StarPU unique tags of size nbtags.
void pastix_starpu_tag_release(int64_t min)
Release the set of tags starting by min.
int pastix_starpu_tag_init(pastix_data_t *pastix)
Initialize the StarPU tags manager.
Main PaStiX data structure.
Definition pastixdata.h:68