Skip to content

Commit d331c8a

Browse files
Update example (#288)
Signed-off-by: Guillaume Mercier <[email protected]>
1 parent dd0c7a1 commit d331c8a

File tree

2 files changed

+68
-25
lines changed

2 files changed

+68
-25
lines changed

src/quo-vadis-pthread.cc

+7-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ qv_pthread_colors_fill(
146146
){
147147
int rc = QV_SUCCESS;
148148

149+
if(stride < 1)
150+
return QV_ERR_INVLD_ARG;
151+
149152
switch(policy){
150153
case QV_POLICY_SPREAD:
151154
{
@@ -161,6 +164,8 @@ qv_pthread_colors_fill(
161164

162165
case QV_POLICY_SCATTER:
163166
{
167+
168+
164169
break;
165170
}
166171

@@ -175,7 +180,8 @@ qv_pthread_colors_fill(
175180
default:
176181
{
177182
for(int idx = 0 ; idx < array_size ; idx++){
178-
color_array[idx] = (idx+idx*(stride-1))%(npieces);
183+
// color_array[idx] = (idx+idx*(stride-1))%(npieces);
184+
color_array[idx] = (idx*stride)%(npieces);
179185
}
180186
break;
181187
}

tests/test-pthread-split.c

+61-24
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,28 @@ thread_work(
2323
qvi_test_panic("%s", ers);
2424
}
2525

26-
char *binds = NULL;
27-
int rc = qv_scope_bind_string(scope, QV_BIND_STRING_AS_LIST, &binds);
28-
if (rc != QV_SUCCESS) {
29-
ers = "qv_bind_string() failed";
30-
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
31-
}
32-
33-
fprintf(stdout,"[%d] Thread running on %s\n", tid, binds);
34-
free(binds);
35-
3626
int rank = 0;
37-
rc = qv_scope_group_rank(thargs->scope, &rank);
27+
int rc = qv_scope_group_rank(scope, &rank);
3828
if (rc != QV_SUCCESS) {
3929
ers = "qv_scope_group_rank failed";
4030
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
4131
}
42-
43-
fprintf(stdout,"[%d] Thread %d splitting in two pieces\n", tid, rank);
44-
32+
33+
qvi_test_scope_report(scope, "thread_scope_in_thread_routine");
34+
qvi_test_emit_task_bind(scope);
35+
36+
fprintf(stdout,"[%d] ============ Thread %d splitting in two pieces\n", tid, rank);
4537
qv_scope_t *pthread_subscope = NULL;
46-
rc = qv_scope_split(thargs->scope, 2, rank, &pthread_subscope);
47-
if (rc != QV_SUCCESS) {
38+
rc = qv_scope_split(scope, 2, rank, &pthread_subscope);
39+
N if (rc != QV_SUCCESS) {
4840
ers = "qv_scope_split failed";
4941
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
5042
}
5143

44+
qvi_test_scope_report(pthread_subscope, "thread_subscope");
45+
qvi_test_emit_task_bind(pthread_subscope);
46+
47+
5248
rc = qv_scope_free(pthread_subscope);
5349
if (rc != QV_SUCCESS) {
5450
ers = "qv_scope_free failed";
@@ -101,21 +97,49 @@ main(void)
10197
ers = "qv_scope_nobjs() failed";
10298
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
10399
}
100+
101+
qvi_test_scope_report(mpi_scope, "mpi_scope");
102+
qvi_test_emit_task_bind(mpi_scope);
103+
104+
//As Edgar pointed out, this will work only in the
105+
//single process case.
106+
//The mpi_scope need to be plsit in order to get
107+
//a new mpi_single_process_scope
108+
104109
//
105110
// Test qv_pthread_scope_split
106111
//
107112
int npieces = 2;
108113
int nthreads = ncores;
114+
int stride = 1;
115+
int colors[nthreads];
116+
117+
printf("[%d] Testing thread_scope_split (nthreads=%i, npieces=%i)\n", tid, nthreads, npieces);
118+
119+
for (int i = 0 ; i < nthreads ; i++) {
120+
colors[i] = i % npieces;
121+
}
109122

110-
printf("[%d] Testing thread_scope_split (nthreads=%i)\n", tid, nthreads);
123+
fprintf(stdout,"Array values :");
124+
for (int i = 0 ; i < nthreads ; i++) {
125+
fprintf(stdout,"val[%i]: %i |",i,colors[i]);
126+
}
127+
fprintf(stdout,"\n");
128+
111129

112-
int colors[nthreads];
113-
rc = qv_pthread_colors_fill(colors, nthreads, QV_POLICY_PACKED, 1, npieces);
130+
rc = qv_pthread_colors_fill(colors, nthreads, QV_POLICY_PACKED, stride, ncores, npieces);
114131
if (rc != QV_SUCCESS) {
115132
ers = "qv_pthread_colors_fill() failed";
116133
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
117134
}
118135

136+
fprintf(stdout,"Array values :");
137+
for (int i = 0 ; i < nthreads ; i++) {
138+
fprintf(stdout,"val[%i]: %i |",i,colors[i]);
139+
}
140+
fprintf(stdout,"\n");
141+
142+
119143
qv_scope_t **th_scopes = NULL;
120144
rc = qv_pthread_scope_split(
121145
mpi_scope, npieces, colors, nthreads, &th_scopes
@@ -158,24 +182,37 @@ main(void)
158182
ers = "qv_pthread_scope_free() failed";
159183
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
160184
}
185+
161186
#if 0
162187
//Test qv_pthread_scope_split_at
163188
nthreads = 2 * ncores;
164189

165-
fprintf(stdout,"[%d] ====== Testing thread_scope_split_at (number of threads : %i)\n", tid, nthreads);
190+
printf("[%d] Testing thread_scope_split_at (nthreads=%i)\n", tid, nthreads);
166191

167-
int colors2[nthreads];
168-
/*
192+
int colors2[nthreads];
169193
for (int i = 0 ; i < nthreads ; i++) {
170194
colors2[i] = i % ncores;
171195
}
172-
*/
173-
rc = qv_pthread_colors_fill(colors2, nthreads, QV_POLICY_PACKED, 1, ncores);
196+
197+
fprintf(stdout,"Array values :");
198+
for (int i = 0 ; i < nthreads ; i++) {
199+
fprintf(stdout,"val[%i]: %i |",i,colors2[i]);
200+
}
201+
fprintf(stdout,"\n");
202+
203+
204+
rc = qv_pthread_colors_fill(colors2, nthreads, QV_POLICY_PACKED, stride, ncores, ncores);
174205
if (rc != QV_SUCCESS) {
175206
ers = "qv_pthread_colors_fill() failed";
176207
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
177208
}
178209

210+
fprintf(stdout,"Array values :");
211+
for (int i = 0 ; i < nthreads ; i++) {
212+
fprintf(stdout,"val[%i]: %i |",i,colors2[i]);
213+
}
214+
fprintf(stdout,"\n");
215+
179216
rc = qv_pthread_scope_split_at(
180217
mpi_scope, QV_HW_OBJ_CORE, colors2, nthreads, &th_scopes
181218
);

0 commit comments

Comments
 (0)