8
8
#include "private/autogen/config.h"
9
9
#include "hwloc.h"
10
10
11
+ #ifdef HWLOC_WIN_SYS
12
+ #include <windows.h>
13
+ #endif
14
+
11
15
struct hwloc_distrib_level {
12
16
hwloc_obj_type_t type ; // level type.
13
17
unsigned depth ; // level depth.
@@ -29,48 +33,61 @@ struct hwloc_distrib_iterator{
29
33
static size_t * range (const size_t n ){
30
34
size_t * r = malloc (n * sizeof (* r ));
31
35
32
- if (r == NULL ) return NULL ;
33
- for (size_t i = 0 ; i < n ; i ++ ){ r [i ] = i ; }
36
+ if (r == NULL )
37
+ return NULL ;
38
+ for (size_t i = 0 ; i < n ; i ++ )
39
+ r [i ] = i ;
34
40
return r ;
35
41
}
36
42
37
43
static size_t * reversed_range (const size_t n ){
38
44
size_t * r = malloc (n * sizeof (* r ));
39
45
40
- if (r == NULL ) return NULL ;
46
+ if (r == NULL )
47
+ return NULL ;
41
48
for (size_t i = 0 ; i < n ; i ++ ){ r [i ] = n - i - 1 ; }
42
49
return r ;
43
50
}
44
51
45
52
static size_t * shuffled_range (const size_t n ){
46
53
size_t i , * index , * ret , val ;
47
54
48
- if ((index = range (n )) == NULL ) return NULL ;
49
- if ((ret = malloc (n * sizeof (* ret ))) == NULL ) { free (index ); return NULL ; }
55
+ if ((index = range (n )) == NULL )
56
+ return NULL ;
57
+
58
+ ret = malloc (n * sizeof (* ret ));
59
+ if (ret == NULL ) {
60
+ free (index );
61
+ return NULL ;
62
+ }
50
63
51
64
srand (time (NULL ));
52
65
for (i = n ;i > 0 ;i -- ){
53
66
val = rand ()%(i );
54
67
ret [i - 1 ] = index [val ];
55
68
index [val ] = index [i - 1 ];
56
- }
57
- free (index );
58
- return ret ;
69
+ }
70
+ free (index );
71
+ return ret ;
59
72
}
60
73
61
74
static int hwloc_distrib_level_cmp_depth (const void * la , const void * lb ){
62
75
const struct hwloc_distrib_level * a = (struct hwloc_distrib_level * )la ;
63
76
const struct hwloc_distrib_level * b = (struct hwloc_distrib_level * )lb ;
64
- if (a -> depth > b -> depth ) { return 1 ; }
65
- if (a -> depth < b -> depth ) { return -1 ; }
77
+ if (a -> depth > b -> depth )
78
+ return 1 ;
79
+ if (a -> depth < b -> depth )
80
+ return -1 ;
66
81
return 0 ;
67
82
}
68
83
69
84
static int hwloc_distrib_level_cmp_user_index (const void * la , const void * lb ){
70
85
const struct hwloc_distrib_level * a = (struct hwloc_distrib_level * )la ;
71
86
const struct hwloc_distrib_level * b = (struct hwloc_distrib_level * )lb ;
72
- if (a -> user_index > b -> user_index ) { return 1 ; }
73
- if (a -> user_index < b -> user_index ) { return -1 ; }
87
+ if (a -> user_index > b -> user_index )
88
+ return 1 ;
89
+ if (a -> user_index < b -> user_index )
90
+ return -1 ;
74
91
return 0 ;
75
92
}
76
93
@@ -172,7 +189,8 @@ hwloc_distrib_build_iterator(hwloc_topology_t topology,
172
189
173
190
struct hwloc_distrib_iterator * it = malloc (sizeof (* it ) +
174
191
sizeof (* it -> levels ) * n_roots );
175
- if (it == NULL ) return NULL ;
192
+ if (it == NULL )
193
+ return NULL ;
176
194
177
195
it -> roots = roots ;
178
196
it -> n_roots = n_roots ;
@@ -203,7 +221,8 @@ hwloc_distrib_iterator_round_robin(hwloc_topology_t topology,
203
221
struct hwloc_distrib_iterator * it = malloc (sizeof (* it ) +
204
222
sizeof (hwloc_obj_t ) +
205
223
sizeof (struct hwloc_distrib_level * ));
206
- if (it == NULL ) return NULL ;
224
+ if (it == NULL )
225
+ return NULL ;
207
226
208
227
it -> roots = (hwloc_obj_t * ) ((char * )it + sizeof (* it ));
209
228
* it -> roots = root ;
@@ -255,7 +274,8 @@ hwloc_distrib_iterator_scatter(hwloc_topology_t topology,
255
274
struct hwloc_distrib_iterator * it = malloc (sizeof (* it ) +
256
275
sizeof (hwloc_obj_t ) +
257
276
sizeof (struct hwloc_distrib_level * ));
258
- if (it == NULL ) return NULL ;
277
+ if (it == NULL )
278
+ return NULL ;
259
279
260
280
it -> roots = (hwloc_obj_t * ) ((char * )it + sizeof (* it ));
261
281
* it -> roots = root ;
0 commit comments