1
/* StarPU --- Runtime system for heterogeneous multicore architectures.
3
* Copyright (C) 2010-2012 Université de Bordeaux 1
4
* Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
6
* StarPU is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; either version 2.1 of the License, or (at
9
* your option) any later version.
11
* StarPU is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
* See the GNU Lesser General Public License in COPYING.LGPL for more details.
22
#include "../helper.h"
24
static unsigned niter = 16384;
42
* - {B, C} depend on A
43
* - D depends on {B, C}
44
* - A, B, C and D are resubmitted at the end of the loop (or not)
47
static struct starpu_task taskA, taskB, taskC, taskD;
49
static unsigned loop_cnt = 0;
50
static unsigned check_cnt = 0;
51
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
52
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
54
static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
56
(void) STARPU_ATOMIC_ADD(&check_cnt, 1);
59
static struct starpu_codelet dummy_codelet =
61
.where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
62
.cpu_funcs = {dummy_func, NULL},
63
.cuda_funcs = {dummy_func, NULL},
64
.opencl_funcs = {dummy_func, NULL},
69
static void callback_task_D(void *arg __attribute__((unused)))
71
_STARPU_PTHREAD_MUTEX_LOCK(&mutex);
74
if (loop_cnt == niter)
78
_STARPU_PTHREAD_COND_SIGNAL(&cond);
79
_STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
83
_STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
84
/* Let's go for another iteration */
85
starpu_tag_restart((starpu_tag_t) TAG_START);
86
starpu_tag_notify_from_apps((starpu_tag_t)TAG_START);
90
int main(int argc, char **argv)
94
// struct timeval start;
95
// struct timeval end;
98
ret = starpu_init(NULL);
99
if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
100
STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
102
/* Implicit data dependencies and regeneratable tasks are not compatible */
103
starpu_data_set_default_sequential_consistency_flag(0);
105
starpu_task_init(&taskA);
106
taskA.cl = &dummy_codelet;
107
taskA.cl_arg = &taskA;
108
taskA.regenerate = 1; /* this task will be explicitely resubmitted if needed */
110
taskA.tag_id = TAG_A;
112
starpu_task_init(&taskB);
113
taskB.cl = &dummy_codelet;
114
taskB.cl_arg = &taskB;
115
taskB.regenerate = 1;
117
taskB.tag_id = TAG_B;
119
starpu_task_init(&taskC);
120
taskC.cl = &dummy_codelet;
121
taskC.cl_arg = &taskC;
122
taskC.regenerate = 1;
124
taskC.tag_id = TAG_C;
126
starpu_task_init(&taskD);
127
taskD.cl = &dummy_codelet;
128
taskD.cl_arg = &taskD;
129
taskD.callback_func = callback_task_D;
130
taskD.regenerate = 1;
132
taskD.tag_id = TAG_D;
134
starpu_tag_declare_deps((starpu_tag_t) TAG_A, 1, (starpu_tag_t) TAG_START);
136
starpu_tag_declare_deps((starpu_tag_t) TAG_B, 1, (starpu_tag_t) TAG_A);
137
starpu_tag_declare_deps((starpu_tag_t) TAG_C, 1, (starpu_tag_t) TAG_A);
139
starpu_tag_declare_deps((starpu_tag_t) TAG_D, 2, (starpu_tag_t) TAG_B, (starpu_tag_t) TAG_C);
141
ret = starpu_task_submit(&taskA); if (ret == -ENODEV) goto enodev; STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
142
ret = starpu_task_submit(&taskB); if (ret == -ENODEV) goto enodev; STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
143
ret = starpu_task_submit(&taskC); if (ret == -ENODEV) goto enodev; STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
144
ret = starpu_task_submit(&taskD); if (ret == -ENODEV) goto enodev; STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
146
starpu_tag_notify_from_apps((starpu_tag_t) TAG_START);
148
/* Wait for the termination of all loops */
149
_STARPU_PTHREAD_MUTEX_LOCK(&mutex);
150
if (loop_cnt < niter)
151
_STARPU_PTHREAD_COND_WAIT(&cond, &mutex);
152
_STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
154
STARPU_ASSERT(check_cnt == (4*loop_cnt));
158
/* Cleanup the statically allocated tasks after shutdown, as StarPU is still working on it after the callback */
159
starpu_task_deinit(&taskA);
160
starpu_task_deinit(&taskB);
161
starpu_task_deinit(&taskC);
162
starpu_task_deinit(&taskD);
167
fprintf(stderr, "WARNING: No one can execute this task\n");
168
/* yes, we do not perform the computation but we did detect that no one
169
* could perform the kernel, so this is not an error from StarPU */
171
return STARPU_TEST_SKIPPED;