-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdist-work.c
157 lines (141 loc) · 4.04 KB
/
dist-work.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
157
/*
* 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 <assert.h>
#include <unistd.h>
#include <stdbool.h>
#include "mpi.h"
/**
* this code tests the QUO_auto_distrib routine.
*/
typedef struct info_t {
QUO_context q;
int rank;
int nranks;
int noderank;
int nnoderanks;
int ncores;
QUO_obj_type_t tres;
} info_t;
typedef void (*bp)(info_t *q);
typedef struct bind_t {
/* bind name */
char *bname;
/* bind function pointer */
bp bfp;
/* pop function pointer */
bp pfp;
} bind_t;
static void
emit_bind(info_t *i)
{
char *binds = NULL;
assert(QUO_SUCCESS == QUO_stringify_cbind(i->q, &binds));
printf("bbb %d %s\n", i->rank, binds);
free(binds);
}
static void
tsync(const info_t *i)
{
MPI_Barrier(MPI_COMM_WORLD);
usleep((i->rank) * 1000);
}
static void
popbind(info_t *i)
{
assert(QUO_SUCCESS == QUO_bind_pop(i->q));
}
static void
nobind(info_t *i)
{
assert(QUO_SUCCESS == QUO_bind_push(i->q, QUO_BIND_PUSH_PROVIDED,
QUO_OBJ_MACHINE, 0));
}
static void
tightbind(info_t *i)
{
assert(QUO_SUCCESS == QUO_bind_push(i->q, QUO_BIND_PUSH_PROVIDED,
QUO_OBJ_CORE, i->noderank));
}
static void
insanity(info_t *i)
{
if (0 == (i->noderank % 2)) {
assert(QUO_SUCCESS == QUO_bind_push(i->q, QUO_BIND_PUSH_OBJ,
QUO_OBJ_MACHINE, -1));
}
else {
assert(QUO_SUCCESS == QUO_bind_push(i->q, QUO_BIND_PUSH_PROVIDED,
QUO_OBJ_CORE, i->noderank));
}
}
static bind_t binds[] =
{
{"complete set overlap", nobind, popbind},
{"no set overlap", tightbind, popbind},
{"some set overlap", insanity, popbind},
{NULL, NULL, NULL}
};
int
main(int argc, char **argv)
{
info_t info;
int work_member = 0, max_members_per_res = 2;
int nres = 0, rc = EXIT_SUCCESS;
info.tres = QUO_OBJ_NUMANODE;
assert(MPI_SUCCESS == MPI_Init(&argc, &argv));
assert(QUO_SUCCESS == QUO_create(&info.q, MPI_COMM_WORLD));
assert(MPI_SUCCESS == MPI_Comm_size(MPI_COMM_WORLD, &info.nranks));
assert(MPI_SUCCESS == MPI_Comm_rank(MPI_COMM_WORLD, &info.rank));
assert(QUO_SUCCESS == QUO_id(info.q, &info.noderank));
assert(QUO_SUCCESS == QUO_nqids(info.q, &info.nnoderanks));
assert(QUO_SUCCESS == QUO_nnumanodes(info.q, &nres));
assert(QUO_SUCCESS == QUO_ncores(info.q, &info.ncores));
setbuf(stdout, NULL);
if (info.ncores < info.nnoderanks) {
if (0 == info.noderank) {
fprintf(stderr, "xxx cannot continue: %d core(s) < %d rank(s).\n",
info.ncores, info.nranks);
}
rc = EXIT_FAILURE;
goto done;
}
if (0 == nres) {
assert(QUO_SUCCESS == QUO_nsockets(info.q, &nres));
info.tres = QUO_OBJ_SOCKET;
if (0 == nres) {
fprintf(stderr, "xxx cannot continue with test! xxx\n");
rc = EXIT_FAILURE;
goto done;
}
}
if (0 == info.rank) {
printf("ooo starting test: max mems per %d = %d (see quo.h) ooo\n",
(int)info.tres, max_members_per_res);
}
for (int i = 0; NULL != binds[i].bname; ++i) {
tsync(&info);
if (0 == info.rank) printf("--- %s\n", binds[i].bname);
binds[i].bfp(&info);
emit_bind(&info);
tsync(&info);
assert(QUO_SUCCESS == QUO_auto_distrib(info.q, info.tres,
max_members_per_res,
&work_member));
printf("*** rank %d work member: %d\n", info.rank, work_member);
tsync(&info);
binds[i].pfp(&info);
tsync(&info);
}
done:
assert(QUO_SUCCESS == QUO_free(info.q));
assert(MPI_SUCCESS == MPI_Finalize());
return rc;
}