Skip to content

Commit 633c07b

Browse files
Cleanup more Pthread code. (#300)
Signed-off-by: Samuel K. Gutierrez <[email protected]>
1 parent 86d7426 commit 633c07b

File tree

3 files changed

+42
-45
lines changed

3 files changed

+42
-45
lines changed

include/quo-vadis-pthread.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern "C" {
2828
#endif
2929

3030
/**
31-
* Mapping policies types.
31+
* Placement (or mapping) policy types.
3232
*/
3333
// Intel policies (KMP_AFFINITY) are :
3434
// - disabled: prevents the runtime library from making any affinity-related
@@ -37,6 +37,7 @@ extern "C" {
3737
// - scatter: threads are distributed as evenly as possible across the entire system.
3838
// (opposite of compact).
3939
// - explicit: threads are placed according to a list of OS proc IDs (required)
40+
// TODO(skg) Do we need all of these synonyms?
4041
typedef enum {
4142
QV_POLICY_PACKED = 1,
4243
QV_POLICY_COMPACT = 1,
@@ -46,10 +47,8 @@ typedef enum {
4647
QV_POLICY_ALTERNATE = 3,
4748
QV_POLICY_CORESFIRST = 3,
4849
QV_POLICY_SCATTER = 4,
49-
QV_POLICY_CHOOSE = 5,
50-
} qv_policy_t;
51-
// TODO(skg) Consider updating prefix to qv_pthread_ if this is only used for
52-
// Pthread code.
50+
QV_POLICY_CHOOSE = 5
51+
} qv_pthread_placement_t;
5352

5453
/**
5554
* Similar to pthread_create(3).
@@ -97,7 +96,7 @@ int
9796
qv_pthread_colors_fill(
9897
int *color_array,
9998
int array_size,
100-
qv_policy_t policy,
99+
qv_pthread_placement_t policy,
101100
int stride,
102101
int npieces
103102
);

src/quo-vadis-pthread.cc

+36-38
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ qvi_pthread_start_routine(
4545
void *arg
4646
) {
4747
qvi_pthread_args *args = (qvi_pthread_args *)arg;
48-
// TODO(skg) Check return code.
49-
args->scope->bind_push();
48+
49+
const int rc = args->scope->bind_push();
50+
if (qvi_unlikely(rc != QV_SUCCESS)) {
51+
qvi_log_error(
52+
"An error occurred in bind_push(): {} ({})", rc, qv_strerr(rc)
53+
);
54+
pthread_exit(nullptr);
55+
}
5056

5157
void *const ret = args->th_routine(args->th_routine_argp);
5258
qvi_delete(&args);
@@ -61,9 +67,9 @@ qv_pthread_scope_split(
6167
int nthreads,
6268
qv_scope_t ***subscope
6369
) {
64-
const bool invld_args = !scope || npieces < 0 || !color_array ||
65-
nthreads < 0 || !subscope;
66-
if (qvi_unlikely(invld_args)) {
70+
const bool invalid_args = !scope || npieces < 0 || !color_array ||
71+
nthreads < 0 || !subscope;
72+
if (qvi_unlikely(invalid_args)) {
6773
return QV_ERR_INVLD_ARG;
6874
}
6975
try {
@@ -143,50 +149,42 @@ int
143149
qv_pthread_colors_fill(
144150
int *color_array,
145151
int array_size,
146-
qv_policy_t policy,
152+
qv_pthread_placement_t policy,
147153
int stride,
148154
int npieces
149155
) {
150-
int rc = QV_SUCCESS;
151-
152-
if (stride < 1) return QV_ERR_INVLD_ARG;
153-
156+
const bool invalid_args = !color_array || array_size < 0 ||
157+
stride < 1 || npieces < 1;
158+
if (qvi_unlikely(invalid_args)) return QV_ERR_INVLD_ARG;
159+
// TODO(skg) We should use the mapping algorithms in qvi-map for these. The
160+
// problem is that its interfaces aren't yet suited for this type of
161+
// mapping.
154162
switch(policy) {
155-
case QV_POLICY_SPREAD:
156-
{
163+
case QV_POLICY_PACKED: {
164+
// TODO(skg) This looks more like spread.
165+
for(int idx = 0 ; idx < array_size ; idx++){
166+
// color_array[idx] = (idx+idx*(stride-1))%(npieces);
167+
color_array[idx] = (idx*stride)%(npieces);
168+
}
157169
break;
158170
}
159-
160-
case QV_POLICY_DISTRIBUTE:
161-
//case QV_POLICY_ALTERNATE:
162-
//case QV_POLICY_CORESFIRST:
163-
{
164-
break;
171+
case QV_POLICY_SPREAD: {
172+
return QV_ERR_NOT_SUPPORTED;
165173
}
166-
167-
case QV_POLICY_SCATTER:
168-
{
169-
break;
174+
case QV_POLICY_DISTRIBUTE: {
175+
return QV_ERR_NOT_SUPPORTED;
170176
}
171-
172-
case QV_POLICY_CHOOSE:
173-
{
174-
break;
177+
case QV_POLICY_SCATTER: {
178+
return QV_ERR_NOT_SUPPORTED;
175179
}
176-
177-
case QV_POLICY_PACKED:
178-
//case QV_POLICY_COMPACT:
179-
//case QV_POLICY_CLOSE:
180-
default:
181-
{
182-
for(int idx = 0 ; idx < array_size ; idx++){
183-
// color_array[idx] = (idx+idx*(stride-1))%(npieces);
184-
color_array[idx] = (idx*stride)%(npieces);
185-
}
186-
break;
180+
case QV_POLICY_CHOOSE: {
181+
return QV_ERR_NOT_SUPPORTED;
182+
}
183+
default: {
184+
return QV_ERR_INVLD_ARG;
187185
}
188186
}
189-
return rc;
187+
return QV_SUCCESS;
190188
}
191189

192190
/*

src/qvi-pthread.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ qvi_pthread_group::call_first_from_pthread_create(
142142
"An error occurred in m_finish_init_by_all_threads(): {} ({})",
143143
rc, qv_strerr(rc)
144144
);
145-
throw qvi_runtime_error();
145+
pthread_exit(nullptr);
146146
}
147147
// Free the provided argument container.
148148
qvi_delete(&args);

0 commit comments

Comments
 (0)