Skip to content

Commit cb0494b

Browse files
committed
netloc: handle Scotch INTSIZE64
NETLOC_Num replaces int to handle integer that can have different sizes depending on the compilation options. Signed-off-by: Cyril Bordage <[email protected]>
1 parent 81978c8 commit cb0494b

File tree

5 files changed

+60
-46
lines changed

5 files changed

+60
-46
lines changed

include/private/netloc.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright © 2014 Cisco Systems, Inc. All rights reserved.
33
* Copyright © 2013-2014 University of Wisconsin-La Crosse.
44
* All rights reserved.
5-
* Copyright © 2015-2016 Inria. All rights reserved.
5+
* Copyright © 2015-2017 Inria. All rights reserved.
66
*
77
* $COPYRIGHT$
88
*
@@ -19,9 +19,18 @@
1919
#include <netloc.h>
2020
#include <netloc/uthash.h>
2121
#include <netloc/utarray.h>
22+
#include <private/autogen/config.h>
2223

2324
#define NETLOCFILE_VERSION 1
2425

26+
#ifdef NETLOC_SCOTCH
27+
#include <stdint.h>
28+
#include <scotch.h>
29+
#define NETLOC_int SCOTCH_Num
30+
#else
31+
#define NETLOC_int int
32+
#endif
33+
2534
/*
2635
* "Import" a few things from hwloc
2736
*/
@@ -257,9 +266,9 @@ struct netloc_path_t {
257266
* Architecture structures
258267
**********************************************************************/
259268
struct netloc_arch_tree_t {
260-
int num_levels;
261-
int *degrees;
262-
int *cost;
269+
NETLOC_int num_levels;
270+
NETLOC_int *degrees;
271+
NETLOC_int *cost;
263272
};
264273

265274
struct netloc_arch_node_t {
@@ -272,7 +281,7 @@ struct netloc_arch_node_t {
272281
int *slot_os_idx; /* corresponding os index for each leaf in tree */
273282
netloc_arch_tree_t *slot_tree; /* Tree built from hwloc */
274283
int num_current_slots; /* Number of PUs */
275-
int *current_slots; /* indices in the complete tree */
284+
NETLOC_int *current_slots; /* indices in the complete tree */
276285
int *slot_ranks; /* corresponding MPI rank for each leaf in tree */
277286
};
278287

@@ -291,8 +300,8 @@ struct netloc_arch_t {
291300
} arch;
292301
netloc_arch_node_t *nodes_by_name;
293302
netloc_arch_node_slot_t *node_slot_by_idx; /* node_slot by index in complete topo */
294-
int num_current_hosts; /* if has_slots, host is a slot, else host is a node */
295-
int *current_hosts; /* indices in the complete topology */
303+
NETLOC_int num_current_hosts; /* if has_slots, host is a slot, else host is a node */
304+
NETLOC_int *current_hosts; /* indices in the complete topology */
296305
};
297306

298307
/**********************************************************************
@@ -489,7 +498,7 @@ int netloc_arch_node_get_hwloc_info(netloc_arch_node_t *arch);
489498
void netloc_arch_tree_complete(netloc_arch_tree_t *tree, UT_array **down_degrees_by_level,
490499
int num_hosts, int **parch_idx);
491500

492-
int netloc_arch_tree_num_leaves(netloc_arch_tree_t *tree);
501+
NETLOC_int netloc_arch_tree_num_leaves(netloc_arch_tree_t *tree);
493502

494503

495504
/**********************************************************************

netloc/architecture.c

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2016 Inria. All rights reserved.
2+
* Copyright © 2016-2017 Inria. All rights reserved.
33
*
44
* $COPYRIGHT$
55
*
@@ -41,17 +41,17 @@ void netloc_arch_tree_complete(netloc_arch_tree_t *tree, UT_array **down_degrees
4141
int num_hosts, int **parch_idx)
4242
{
4343
int num_levels = tree->num_levels;
44-
int *max_degrees = tree->degrees;
44+
NETLOC_int *max_degrees = tree->degrees;
4545

4646
/* Complete the tree by inserting nodes */
4747
for (int l = 0; l < num_levels-1; l++) { // from the root to the leaves
4848
int num_degrees = utarray_len(down_degrees_by_level[l]);
4949
int *degrees = (int *)down_degrees_by_level[l]->d;
50-
int max_degree = max_degrees[l];
50+
NETLOC_int max_degree = max_degrees[l];
5151

5252
unsigned int down_level_idx = 0;
5353
UT_array *down_level_degrees = down_degrees_by_level[l+1];
54-
int down_level_max_degree = max_degrees[l+1];
54+
NETLOC_int down_level_max_degree = max_degrees[l+1];
5555
for (int d = 0; d < num_degrees; d++) {
5656
int degree = degrees[d];
5757
if (degree > 0) {
@@ -72,7 +72,7 @@ void netloc_arch_tree_complete(netloc_arch_tree_t *tree, UT_array **down_degrees
7272
/* Indices for the list of hosts, in the complete architecture */
7373
int num_degrees = utarray_len(down_degrees_by_level[num_levels-1]);
7474
int *degrees = (int *)down_degrees_by_level[num_levels-1]->d;
75-
int max_degree = max_degrees[num_levels-1];
75+
NETLOC_int max_degree = max_degrees[num_levels-1];
7676
int ghost_idx = 0;
7777
int idx = 0;
7878
netloc_arch_node_t *named_nodes = NULL;
@@ -95,9 +95,9 @@ void netloc_arch_tree_complete(netloc_arch_tree_t *tree, UT_array **down_degrees
9595
*parch_idx = arch_idx;
9696
}
9797

98-
int netloc_arch_tree_num_leaves(netloc_arch_tree_t *tree)
98+
NETLOC_int netloc_arch_tree_num_leaves(netloc_arch_tree_t *tree)
9999
{
100-
int num_leaves = 1;
100+
NETLOC_int num_leaves = 1;
101101
for (int l = 0; l < tree->num_levels; l++) {
102102
num_leaves *= tree->degrees[l];
103103
}
@@ -210,10 +210,10 @@ int netloc_arch_set_current_resources(netloc_arch_t *arch)
210210
if (ret != NETLOC_SUCCESS || num_nodes <= 0)
211211
assert(0); // XXX
212212

213-
int *current_nodes = NULL;
213+
NETLOC_int *current_nodes = NULL;
214214

215215
if (!arch->has_slots) {
216-
current_nodes = (int *) malloc(sizeof(int[num_nodes]));
216+
current_nodes = (NETLOC_int *) malloc(sizeof(NETLOC_int[num_nodes]));
217217
}
218218

219219
netloc_arch_node_t **arch_node_list = (netloc_arch_node_t **)
@@ -267,9 +267,9 @@ int netloc_arch_set_current_resources(netloc_arch_t *arch)
267267
}
268268
}
269269

270-
node->current_slots = (int *)
271-
malloc(sizeof(int[num_slots]));
272-
int num_leaves = netloc_arch_tree_num_leaves(node->slot_tree);
270+
node->current_slots = (NETLOC_int *)
271+
malloc(sizeof(NETLOC_int[num_slots]));
272+
NETLOC_int num_leaves = netloc_arch_tree_num_leaves(node->slot_tree);
273273
node->slot_ranks = (int *)
274274
malloc(sizeof(int[num_leaves]));
275275

@@ -286,7 +286,7 @@ int netloc_arch_set_current_resources(netloc_arch_t *arch)
286286
arch->arch.global_tree = arch->arch.node_tree;
287287

288288
/* Build nodes_by_idx */
289-
int tree_size = netloc_arch_tree_num_leaves(arch->arch.node_tree);
289+
NETLOC_int tree_size = netloc_arch_tree_num_leaves(arch->arch.node_tree);
290290
netloc_arch_node_slot_t *nodes_by_idx = (netloc_arch_node_slot_t *)
291291
malloc(sizeof(netloc_arch_node_slot_t[tree_size]));
292292
for (int n = 0; n < num_nodes; n++) {
@@ -299,7 +299,8 @@ int netloc_arch_set_current_resources(netloc_arch_t *arch)
299299

300300
} else {
301301
int num_hosts = slot_idx[num_nodes];
302-
int *current_hosts = (int *)malloc(sizeof(int[num_hosts]));
302+
NETLOC_int *current_hosts = (NETLOC_int *)
303+
malloc(sizeof(NETLOC_int[num_hosts]));
303304
/* Add the slot trees to the node tree */
304305

305306
/* Check that each slot tree has the same size */
@@ -363,12 +364,12 @@ int netloc_arch_set_current_resources(netloc_arch_t *arch)
363364
int netloc_arch_set_global_resources(netloc_arch_t *arch)
364365
{
365366
int ret;
366-
int *current_nodes = NULL;
367+
NETLOC_int *current_nodes = NULL;
367368
int *slot_idx = NULL;
368369

369370
int num_nodes = HASH_COUNT(arch->nodes_by_name);
370371
if (!arch->has_slots) {
371-
current_nodes = (int *) malloc(sizeof(int[num_nodes]));
372+
current_nodes = (NETLOC_int *) malloc(sizeof(NETLOC_int[num_nodes]));
372373
}
373374

374375
ret = netloc_topology_read_hwloc(arch->topology, 0, NULL);
@@ -431,7 +432,8 @@ int netloc_arch_set_global_resources(netloc_arch_t *arch)
431432

432433
} else {
433434
int num_hosts = slot_idx[num_nodes];
434-
int *current_hosts = (int *)malloc(sizeof(int[num_hosts]));
435+
NETLOC_int *current_hosts = (NETLOC_int *)
436+
malloc(sizeof(NETLOC_int[num_hosts]));
435437
netloc_arch_node_t *node, *node_tmp;
436438
/* Add the slot trees to the node tree */
437439

@@ -492,18 +494,20 @@ netloc_arch_tree_t *tree_merge(netloc_arch_tree_t *main, netloc_arch_tree_t *sub
492494

493495
int num_levels = main->num_levels+sub->num_levels;
494496
new_tree->num_levels = num_levels;
495-
new_tree->degrees = (int *)malloc(sizeof(int[num_levels]));
496-
new_tree->cost = (int *)malloc(sizeof(int[num_levels]));
497+
new_tree->degrees = (NETLOC_int *)malloc(sizeof(NETLOC_int[num_levels]));
498+
new_tree->cost = (NETLOC_int *)malloc(sizeof(NETLOC_int[num_levels]));
497499

498-
memcpy(new_tree->degrees, main->degrees, main->num_levels*sizeof(int));
500+
memcpy(new_tree->degrees, main->degrees,
501+
main->num_levels*sizeof(*new_tree->degrees));
499502
memcpy(new_tree->degrees+main->num_levels, sub->degrees,
500-
sub->num_levels*sizeof(int));
503+
sub->num_levels*sizeof(*new_tree->degrees));
501504

502505
int out_coeff = 10;
503506
for (int l = 0; l < main->num_levels; l++) {
504507
new_tree->cost[l] = main->cost[l]*sub->cost[0]*out_coeff;
505508
}
506-
memcpy(new_tree->cost+main->num_levels, sub->cost, sub->num_levels*sizeof(int));
509+
memcpy(new_tree->cost+main->num_levels, sub->cost,
510+
sub->num_levels*sizeof(*new_tree->cost));
507511

508512
return new_tree;
509513
}
@@ -607,15 +611,16 @@ int partition_topology_to_tleaf(netloc_topology_t *topology,
607611
* structure */
608612
UT_array *ordered_name_array = NULL;
609613
UT_array **down_degrees_by_level = NULL;
610-
int *max_down_degrees_by_level;
614+
NETLOC_int *max_down_degrees_by_level;
611615

612616
utarray_new(ordered_name_array, &ut_ptr_icd);
613617

614618
down_degrees_by_level = (UT_array **)malloc(num_levels*sizeof(UT_array *));
615619
for (int l = 0; l < num_levels; l++) {
616620
utarray_new(down_degrees_by_level[l], &ut_int_icd);
617621
}
618-
max_down_degrees_by_level = (int *)calloc(num_levels-1, sizeof(int));
622+
max_down_degrees_by_level = (NETLOC_int *)
623+
calloc(num_levels-1, sizeof(NETLOC_int));
619624

620625
UT_array *down_edges = NULL;
621626
utarray_new(down_edges, &ut_ptr_icd);
@@ -662,7 +667,7 @@ int partition_topology_to_tleaf(netloc_topology_t *topology,
662667
continue;
663668
netloc_analysis_data *edge_data = (netloc_analysis_data *)edge->userdata;
664669
int edge_level = edge_data->level;
665-
670+
666671
netloc_node_t *dest_node = edge->dest;
667672

668673
/* If the is the node where we are from */
@@ -695,7 +700,7 @@ int partition_topology_to_tleaf(netloc_topology_t *topology,
695700
tree->degrees = max_down_degrees_by_level;
696701

697702
int network_coeff = 2;
698-
tree->cost = (int *)malloc(sizeof(int[tree->num_levels]));
703+
tree->cost = (NETLOC_int *)malloc(sizeof(NETLOC_int[tree->num_levels]));
699704
tree->cost[tree->num_levels-1] = 1;
700705
for (int i = tree->num_levels-2; i >= 0 ; i--) {
701706
tree->cost[i] = tree->cost[i+1]*network_coeff;
@@ -790,9 +795,7 @@ int netloc_arch_build(netloc_arch_t *arch, int add_slots)
790795
}
791796
topopath = strdup(topopath);
792797

793-
netloc_topology_t *topology = NULL;
794-
795-
topology = netloc_topology_construct(topopath);
798+
netloc_topology_t *topology = netloc_topology_construct(topopath);
796799
if (topology == NULL) {
797800
fprintf(stderr, "Error: netloc_topology_construct failed\n");
798801
return NETLOC_ERROR;

netloc/hwloc.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2016 Inria. All rights reserved.
2+
* Copyright © 2016-2017 Inria. All rights reserved.
33
*
44
* $COPYRIGHT$
55
*
@@ -193,13 +193,14 @@ int netloc_arch_node_get_hwloc_info(netloc_arch_node_t *arch_node)
193193
hwloc_obj_t first_object = root->first_child;
194194

195195
UT_array **down_degrees_by_level;
196-
int *max_down_degrees_by_level;
196+
NETLOC_int *max_down_degrees_by_level;
197197

198198
down_degrees_by_level = (UT_array **)malloc(depth*sizeof(UT_array *));
199199
for (int l = 0; l < depth; l++) {
200200
utarray_new(down_degrees_by_level[l], &ut_int_icd);
201201
}
202-
max_down_degrees_by_level = (int *)calloc(depth-1, sizeof(int));
202+
max_down_degrees_by_level = (NETLOC_int *)
203+
calloc(depth-1, sizeof(NETLOC_int));
203204

204205
int level = depth-1;
205206
hwloc_obj_t current_object = first_object;
@@ -242,7 +243,7 @@ int netloc_arch_node_get_hwloc_info(netloc_arch_node_t *arch_node)
242243
ordered_hosts = (int *)ordered_host_array->d;;
243244

244245
/* Weight for the edges in the tree */
245-
int *cost = (int *)malloc((depth-1)*sizeof(int));
246+
NETLOC_int *cost = (NETLOC_int *)malloc((depth-1)*sizeof(NETLOC_int));
246247
int level_coeff = 3;
247248
cost[depth-2] = 1;
248249
for (int l = depth-3; l >= 0; l--) {

netloc/scotch.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2016 Inria. All rights reserved.
2+
* Copyright © 2016-2017 Inria. All rights reserved.
33
*
44
* $COPYRIGHT$
55
*
@@ -32,7 +32,7 @@ static int compareint(void const *a, void const *b)
3232
return *int_a-*int_b;
3333
}
3434

35-
static int build_subarch(SCOTCH_Arch *scotch, int num_nodes, int *node_list,
35+
static int build_subarch(SCOTCH_Arch *scotch, NETLOC_int num_nodes, NETLOC_int *node_list,
3636
SCOTCH_Arch *subarch)
3737
{
3838
int ret;
@@ -237,7 +237,7 @@ int netlocscotch_get_mapping_from_graph(SCOTCH_Graph *graph,
237237
return ret;
238238
}
239239

240-
int graph_size;
240+
NETLOC_int graph_size;
241241
SCOTCH_graphSize(graph, &graph_size, NULL);
242242

243243
int num_hosts = arch->num_current_hosts;
@@ -249,7 +249,7 @@ int netlocscotch_get_mapping_from_graph(SCOTCH_Graph *graph,
249249
SCOTCH_stratGraphMapBuild(&strategy, SCOTCH_STRATQUALITY, graph_size, 0.01);
250250

251251
/* The ranks are the indices of the nodes in the complete graph */
252-
int *ranks = (int *)malloc(graph_size*sizeof(int));
252+
NETLOC_int *ranks = (NETLOC_int *)malloc(graph_size*sizeof(NETLOC_int));
253253
ret = SCOTCH_graphMap(graph, &scotch_subarch, &strategy, ranks);
254254

255255
SCOTCH_stratExit(&strategy);
@@ -289,7 +289,7 @@ int netlocscotch_get_mapping_from_graph(SCOTCH_Graph *graph,
289289
netloc_arch_node_t *node =
290290
arch->node_slot_by_idx[arch->current_hosts[n]].node;
291291
char *nodename = node->name;
292-
int node_ranks[num_processes];
292+
NETLOC_int node_ranks[num_processes];
293293

294294
/* We need to extract the subgraph with only the vertices mapped to the
295295
* current node */

tests/netloc/data/scotch/scotch_get_arch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdio.h> // for scotch
2+
#include <stdint.h>
23
#include <scotch.h>
34
#include <netloc.h>
45
#include <netlocscotch.h>

0 commit comments

Comments
 (0)