-
Notifications
You must be signed in to change notification settings - Fork 9
/
basic-info.c
156 lines (147 loc) · 4.21 KB
/
basic-info.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* Copyright (c) 2013-2019 Triad National Security, LLC
* All rights reserved.
*
* This file is part of the libquo project. See the LICENSE file at the
* top-level directory of this distribution.
*/
#include "quo.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <sys/types.h>
#include <unistd.h>
#include "mpi.h"
typedef struct inf_t {
int rank;
int nranks;
bool mpi_inited;
} inf_t;
static int
init(inf_t *inf)
{
(void)memset(inf, 0, sizeof(*inf));
if (MPI_SUCCESS != MPI_Init(NULL, NULL)) {
return 1;
}
if (MPI_SUCCESS != MPI_Comm_size(MPI_COMM_WORLD, &(inf->nranks))) {
return 1;
}
if (MPI_SUCCESS != MPI_Comm_rank(MPI_COMM_WORLD, &(inf->rank))) {
return 1;
}
inf->mpi_inited = true;
return 0;
}
static int
fini(inf_t *inf)
{
if (inf->mpi_inited) MPI_Finalize();
return 0;
}
int
main(void)
{
int qrc = QUO_SUCCESS, erc = EXIT_SUCCESS;
int qv = 0, qsv = 0, nnodes = 0, nnoderanks = 0;
int nsockets = 0, ncores = 0, npus = 0;
char *bad_func = NULL;
char *cbindstr = NULL, *cbindstr2 = NULL, *cbindstr3 = NULL;
int bound = 0, bound2 = 0, bound3 = 0;
QUO_context quo = NULL;
inf_t info;
if (init(&info)) {
bad_func = "info";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_version(&qv, &qsv))) {
bad_func = "QUO_version";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_create(&quo, MPI_COMM_WORLD))) {
bad_func = "QUO_create";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_nsockets(quo, &nsockets))) {
bad_func = "QUO_nsockets";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_ncores(quo, &ncores))) {
bad_func = "QUO_ncores";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_npus(quo, &npus))) {
bad_func = "QUO_npus";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_bound(quo, &bound))) {
bad_func = "QUO_bound";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_stringify_cbind(quo, &cbindstr))) {
bad_func = "QUO_stringify_cbind";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_nnodes(quo, &nnodes))) {
bad_func = "QUO_nnodes";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_nqids(quo, &nnoderanks))) {
bad_func = "QUO_nnodes";
goto out;
}
/* last argument ignored with QUO_BIND_PUSH_OBJ option */
if (QUO_SUCCESS != (qrc = QUO_bind_push(quo, QUO_BIND_PUSH_OBJ,
QUO_OBJ_CORE, 0))) {
bad_func = "QUO_bind_push";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_stringify_cbind(quo, &cbindstr2))) {
bad_func = "QUO_stringify_cbind";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_bound(quo, &bound2))) {
bad_func = "QUO_bound";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_bind_pop(quo))) {
bad_func = "QUO_bind_pop";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_stringify_cbind(quo, &cbindstr3))) {
bad_func = "QUO_stringify_cbind";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_bound(quo, &bound3))) {
bad_func = "QUO_bound";
goto out;
}
if (QUO_SUCCESS != (qrc = QUO_free(quo))) {
bad_func = "QUO_free";
goto out;
}
printf("### quo version: %d.%d ###\n", qv, qsv);
printf("### nnodes: %d\n", nnodes);
printf("### nnoderanks: %d\n", nnoderanks);
printf("### nsockets: %d\n", nsockets);
printf("### ncores: %d\n", ncores);
printf("### npus: %d\n", npus);
printf("### process %d [%s] bound: %s\n",
(int)getpid(), cbindstr, bound ? "true" : "false");
printf("### process %d [%s] bound: %s\n",
(int)getpid(), cbindstr2, bound2 ? "true" : "false");
printf("### process %d [%s] bound: %s\n",
(int)getpid(), cbindstr3, bound3 ? "true" : "false");
/* the string returned by QUO_machine_topo_stringify MUST be free'd by us */
free(cbindstr);
free(cbindstr2);
free(cbindstr3);
out:
if (NULL != bad_func) {
fprintf(stderr, "xxx %s failure in: %s\n", __FILE__, bad_func);
erc = EXIT_FAILURE;
}
(void)fini(&info);
return erc;
}