Skip to content

Commit 55b884e

Browse files
Color filling function, part 1 (#278)
Signed-off-by: Guillaume Mercier <[email protected]>
1 parent 70f95bc commit 55b884e

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed

include/quo-vadis-pthread.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ extern "C" {
3030
/**
3131
* Mapping policies types.
3232
*/
33+
// Intel policies (KMP_AFFINITY) are :
34+
// - disabled: prevents the runtime library from making any affinity-related
35+
// system calls (to avoid interference with other platform affinity mechanisms).
36+
// - compact: threads are placed as close together as possible.
37+
// - scatter: threads are distributed as evenly as possible across the entire system.
38+
// (opposite of compact).
39+
// - explicit: threads are placed according to a list of OS proc IDs (required)
3340
typedef enum qv_policy_s {
3441
QV_POLICY_PACKED = 1,
3542
QV_POLICY_COMPACT = 1,
@@ -88,7 +95,9 @@ int
8895
qv_pthread_colors_fill(
8996
int *color_array,
9097
int array_size,
91-
qv_policy_t policy
98+
qv_policy_t policy,
99+
int stride,
100+
int npieces
92101
);
93102

94103
#ifdef __cplusplus

src/quo-vadis-pthread.cc

+44-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qvi-scope.h"
2525
#include "qvi-utils.h"
2626

27+
2728
struct qvi_pthread_args_s {
2829
qv_scope_t *scope = nullptr;
2930
qvi_pthread_routine_fun_ptr_t th_routine = nullptr;
@@ -137,12 +138,50 @@ qv_pthread_scopes_free(
137138

138139
int
139140
qv_pthread_colors_fill(
140-
int *,//color_array,
141-
int, // array_size,
142-
qv_policy_t //policy
141+
int *color_array,
142+
int array_size,
143+
qv_policy_t policy,
144+
int stride,
145+
int npieces
143146
){
144-
//TODO(GM) implement
145-
return QV_ERR_NOT_SUPPORTED;
147+
int rc = QV_SUCCESS;
148+
149+
switch(policy){
150+
case QV_POLICY_SPREAD:
151+
{
152+
break;
153+
}
154+
155+
case QV_POLICY_DISTRIBUTE:
156+
//case QV_POLICY_ALTERNATE:
157+
//case QV_POLICY_CORESFIRST:
158+
{
159+
break;
160+
}
161+
162+
case QV_POLICY_SCATTER:
163+
{
164+
break;
165+
}
166+
167+
case QV_POLICY_CHOOSE:
168+
{
169+
break;
170+
}
171+
172+
case QV_POLICY_PACKED:
173+
//case QV_POLICY_COMPACT:
174+
//case QV_POLICY_CLOSE:
175+
default:
176+
{
177+
for(int idx = 0 ; idx < array_size ; idx++){
178+
color_array[idx] = (idx+idx*(stride-1))%(npieces);
179+
}
180+
break;
181+
}
182+
}
183+
184+
return rc;
146185
}
147186

148187
/*

tests/test-pthread-split.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,17 @@ main(void)
104104
fprintf(stdout,"[%d] ====== Testing thread_scope_split (number of threads : %i)\n", tid, nthreads);
105105

106106
int colors[nthreads];
107+
108+
/*
107109
for (int i = 0 ; i < nthreads ; i++) {
108110
colors[i] = i % npieces;
109111
}
110-
112+
*/
113+
rc = qv_pthread_colors_fill(colors, nthreads, QV_POLICY_PACKED, 1, npieces);
114+
if (rc != QV_SUCCESS) {
115+
ers = "qv_pthread_colors_fill() failed";
116+
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
117+
}
111118

112119
qv_scope_t **th_scopes = NULL;
113120
rc = qv_pthread_scope_split(
@@ -159,9 +166,16 @@ main(void)
159166
fprintf(stdout,"[%d] ====== Testing thread_scope_split_at (number of threads : %i)\n", tid, nthreads);
160167

161168
int colors2[nthreads];
169+
/*
162170
for (int i = 0 ; i < nthreads ; i++) {
163171
colors2[i] = i % ncores;
164172
}
173+
*/
174+
rc = qv_pthread_colors_fill(colors2, nthreads, QV_POLICY_PACKED, 1, ncores);
175+
if (rc != QV_SUCCESS) {
176+
ers = "qv_pthread_colors_fill() failed";
177+
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
178+
}
165179

166180
rc = qv_pthread_scope_split_at(
167181
mpi_scope, QV_HW_OBJ_CORE, colors2, nthreads, &th_scopes

0 commit comments

Comments
 (0)