Skip to content

Commit 56e3529

Browse files
Restructure scope code. (#259)
Signed-off-by: Samuel K. Gutierrez <[email protected]>
1 parent 3adb1cd commit 56e3529

10 files changed

+235
-328
lines changed

include/quo-vadis.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ qv_scope_nobjs(
179179
int
180180
qv_scope_taskid(
181181
qv_scope_t *scope,
182-
int *taskid
182+
int *rank
183183
);
184184

185185
/**

src/quo-vadis-mpi.cc

+2-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ qvi_mpi_scope_get(
6464
const int rc = qvi_new(&izgroup, comm);
6565
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
6666

67-
return qvi_scope_get(izgroup, iscope, scope);
67+
return qv_scope_s::makei(izgroup, iscope, scope);
6868
}
6969

7070
int
@@ -87,10 +87,7 @@ qvi_mpi_scope_comm_dup(
8787
qv_scope_t *scope,
8888
MPI_Comm *comm
8989
) {
90-
qvi_group_mpi_t *const mpi_group = dynamic_cast<qvi_group_mpi_t *>(
91-
qvi_scope_group(scope)
92-
);
93-
return mpi_group->comm_dup(comm);
90+
return dynamic_cast<qvi_group_mpi_t *>(scope->group())->comm_dup(comm);
9491
}
9592

9693
int

src/quo-vadis-omp.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ qvi_omp_scope_get(
3535
*scope = nullptr;
3636
return rc;
3737
}
38-
return qvi_scope_get(zgroup, iscope, scope);
38+
return qv_scope_s::makei(zgroup, iscope, scope);
3939
}
4040

4141
int

src/quo-vadis-process.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ qvi_process_scope_get(
2828
*scope = nullptr;
2929
return rc;
3030
}
31-
return qvi_scope_get(zgroup, iscope, scope);
31+
return qv_scope_s::makei(zgroup, iscope, scope);
3232
}
3333

3434
int

src/quo-vadis-pthread.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ qvi_pthread_routine(
4545
void *arg
4646
) {
4747
qvi_pthread_args_s *arg_ptr = (qvi_pthread_args_s *)arg;
48-
qvi_scope_bind_push(arg_ptr->scope);
48+
// TODO(skg) Check return code.
49+
arg_ptr->scope->bind_push();
4950

5051
void *const ret = arg_ptr->th_routine(arg_ptr->th_routine_argp);
5152
qvi_delete(&arg_ptr);
@@ -66,9 +67,8 @@ qv_pthread_scope_split(
6667
return QV_ERR_INVLD_ARG;
6768
}
6869
try {
69-
return qvi_scope_thsplit(
70-
scope, npieces, color_array, nthreads,
71-
QV_HW_OBJ_LAST, subscope
70+
return scope->thsplit(
71+
npieces, color_array, nthreads, QV_HW_OBJ_LAST, subscope
7272
);
7373
}
7474
qvi_catch_and_return();
@@ -86,8 +86,8 @@ qv_pthread_scope_split_at(
8686
return QV_ERR_INVLD_ARG;
8787
}
8888
try {
89-
return qvi_scope_thsplit_at(
90-
scope, type, color_array, nthreads, subscopes
89+
return scope->thsplit_at(
90+
type, color_array, nthreads, subscopes
9191
);
9292
}
9393
qvi_catch_and_return();
@@ -108,7 +108,7 @@ qv_pthread_create(
108108
// pthread_create(), return a reasonable errno.
109109
if (qvi_unlikely(rc != QV_SUCCESS)) return ENOMEM;
110110

111-
auto group = dynamic_cast<qvi_group_pthread_t *>(qvi_scope_group(scope));
111+
auto group = dynamic_cast<qvi_group_pthread_t *>(scope->group());
112112
qvi_pthread_group_pthread_create_args_s *cargs = nullptr;
113113
rc = qvi_new(&cargs, group->thgroup, qvi_pthread_routine, arg_ptr);
114114
if (qvi_unlikely(rc != QV_SUCCESS)) {
@@ -129,7 +129,7 @@ qv_pthread_scopes_free(
129129
return QV_ERR_INVLD_ARG;
130130
}
131131
try {
132-
qvi_scope_thdelete(&scopes, nscopes);
132+
qv_scope_s::thdel(&scopes, nscopes);
133133
return QV_SUCCESS;
134134
}
135135
qvi_catch_and_return();

src/quo-vadis.cc

+17-22
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ qv_scope_bind_push(
4141
return QV_ERR_INVLD_ARG;
4242
}
4343
try {
44-
return qvi_scope_bind_push(scope);
44+
return scope->bind_push();
4545
}
4646
qvi_catch_and_return();
4747
}
@@ -54,7 +54,7 @@ qv_scope_bind_pop(
5454
return QV_ERR_INVLD_ARG;
5555
}
5656
try {
57-
return qvi_scope_bind_pop(scope);
57+
return scope->bind_pop();
5858
}
5959
qvi_catch_and_return();
6060
}
@@ -69,7 +69,7 @@ qv_scope_bind_string(
6969
return QV_ERR_INVLD_ARG;
7070
}
7171
try {
72-
return qvi_scope_bind_string(scope, format, str);
72+
return scope->bind_string(format, str);
7373
}
7474
qvi_catch_and_return();
7575
}
@@ -82,7 +82,7 @@ qv_scope_free(
8282
return QV_ERR_INVLD_ARG;
8383
}
8484
try {
85-
qvi_scope_delete(&scope);
85+
qv_scope_s::del(&scope);
8686
return QV_SUCCESS;
8787
}
8888
qvi_catch_and_return();
@@ -98,7 +98,8 @@ qv_scope_nobjs(
9898
return QV_ERR_INVLD_ARG;
9999
}
100100
try {
101-
return qvi_scope_nobjects(scope, obj, nobjs);
101+
*nobjs = scope->nobjects(obj);
102+
return QV_SUCCESS;
102103
}
103104
qvi_catch_and_return();
104105
}
@@ -107,13 +108,14 @@ qv_scope_nobjs(
107108
int
108109
qv_scope_taskid(
109110
qv_scope_t *scope,
110-
int *taskid
111+
int *rank
111112
) {
112-
if (qvi_unlikely(!scope || !taskid)) {
113+
if (qvi_unlikely(!scope || !rank)) {
113114
return QV_ERR_INVLD_ARG;
114115
}
115116
try {
116-
return qvi_scope_group_rank(scope, taskid);
117+
*rank = scope->group_rank();
118+
return QV_SUCCESS;
117119
}
118120
qvi_catch_and_return();
119121
}
@@ -128,7 +130,8 @@ qv_scope_ntasks(
128130
return QV_ERR_INVLD_ARG;
129131
}
130132
try {
131-
return qvi_scope_group_size(scope, ntasks);
133+
*ntasks = scope->group_size();
134+
return QV_SUCCESS;
132135
}
133136
qvi_catch_and_return();
134137
}
@@ -141,7 +144,7 @@ qv_scope_barrier(
141144
return QV_ERR_INVLD_ARG;
142145
}
143146
try {
144-
return qvi_scope_barrier(scope);
147+
return scope->barrier();
145148
}
146149
qvi_catch_and_return();
147150
}
@@ -159,9 +162,7 @@ qv_scope_create(
159162
return QV_ERR_INVLD_ARG;
160163
}
161164
try {
162-
return qvi_scope_create(
163-
scope, type, nobjs, hints, subscope
164-
);
165+
return scope->create(type, nobjs, hints, subscope);
165166
}
166167
qvi_catch_and_return();
167168
}
@@ -180,9 +181,7 @@ qv_scope_split(
180181
// We use the sentinel value QV_HW_OBJ_LAST to differentiate between
181182
// calls from split() and split_at(). Since this call doesn't have a
182183
// hardware type argument, we use QV_HW_OBJ_LAST as the hardware type.
183-
return qvi_scope_split(
184-
scope, npieces, color, QV_HW_OBJ_LAST, subscope
185-
);
184+
return scope->split(npieces, color, QV_HW_OBJ_LAST, subscope);
186185
}
187186
qvi_catch_and_return();
188187
}
@@ -198,9 +197,7 @@ qv_scope_split_at(
198197
return QV_ERR_INVLD_ARG;
199198
}
200199
try {
201-
return qvi_scope_split_at(
202-
scope, type, group_id, subscope
203-
);
200+
return scope->split_at(type, group_id, subscope);
204201
}
205202
qvi_catch_and_return();
206203
}
@@ -217,9 +214,7 @@ qv_scope_get_device_id(
217214
return QV_ERR_INVLD_ARG;
218215
}
219216
try {
220-
return qvi_scope_device_id(
221-
scope, dev_obj, dev_index, id_type, dev_id
222-
);
217+
return scope->device_id(dev_obj, dev_index, id_type, dev_id);
223218
}
224219
qvi_catch_and_return();
225220
}

0 commit comments

Comments
 (0)