1 /*
2 * Copyright © 2016 Inria. All rights reserved.
3 *
4 * $COPYRIGHT$
5 *
6 * Additional copyrights may follow
7 * See COPYING in top-level directory.
8 *
9 * $HEADER$
10 */
11
12 #define _GNU_SOURCE /* See feature_test_macros(7) */
13 #include <stdio.h>
14 #include <stdlib.h>
15
16 #include <netloc.h>
17 #include <private/netloc.h>
18
compareint(void const * a,void const * b)19 static int compareint(void const *a, void const *b)
20 {
21 const int *int_a = (const int *)a;
22 const int *int_b = (const int *)b;
23 return *int_a-*int_b;
24 }
25
26
main(int argc,char ** argv)27 int main(int argc, char **argv)
28 {
29 int ret;
30 /* First we need to get the topology of the whole machine */
31 netloc_arch_t arch;
32 ret = netloc_arch_build(&arch, 0);
33 if( NETLOC_SUCCESS != ret ) {
34 return ret;
35 }
36
37 /* Set the current nodes and slots in the arch */
38 ret = netloc_arch_set_current_resources(&arch);
39 if( NETLOC_SUCCESS != ret ) {
40 return ret;
41 }
42 int num_nodes = arch.num_current_hosts;
43
44 /* Order the idx_list to have the nodes sorted */
45 qsort(arch.current_hosts, num_nodes, sizeof(*arch.current_hosts), compareint);
46
47 /* Show the list */
48 for (int n = 0; n < num_nodes; n++) {
49 netloc_arch_node_t *arch_node = arch.node_slot_by_idx[arch.current_hosts[n]].node;
50 qsort(arch_node->current_slots, arch_node->num_current_slots,
51 sizeof(*arch_node->current_slots), compareint);
52
53 for (int s = 0; s < arch_node->num_current_slots; s++) {
54 int slot_idx = arch_node->current_slots[s];
55 int slot = arch_node->slot_os_idx[slot_idx];
56 printf("%s %d", arch_node->name, slot);
57 }
58 }
59
60 return NETLOC_SUCCESS;
61 }
62