~ubuntu-branches/ubuntu/quantal/starpu-contrib/quantal

« back to all changes in this revision

Viewing changes to tests/main/subgraph_repeat_regenerate_tag.c

  • Committer: Package Import Robot
  • Author(s): Samuel Thibault
  • Date: 2012-04-12 15:04:15 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120412150415-gzp107thb5wknugm
Tags: 1.0.1-1
* New upstream release.
* Explicitly use gcc-4.6 to fix plugin build (Closes: Bug#667381).
* Use gcc-4.5 for starpu, as nvcc does not actually support all 4.6
  features, notably not __float128.
* patches/relax-gcc-plugin: Relax gcc-4.6 dependency for plugins to upstream
  release version (Closes: #670422)
* watch: Fix URL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* StarPU --- Runtime system for heterogeneous multicore architectures.
 
2
 *
 
3
 * Copyright (C) 2010-2012  Université de Bordeaux 1
 
4
 * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
 
5
 *
 
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.
 
10
 *
 
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.
 
14
 *
 
15
 * See the GNU Lesser General Public License in COPYING.LGPL for more details.
 
16
 */
 
17
 
 
18
#include <sys/time.h>
 
19
#include <starpu.h>
 
20
#include <pthread.h>
 
21
 
 
22
#include "../helper.h"
 
23
 
 
24
static unsigned niter = 16384;
 
25
 
 
26
#define TAG_START 0
 
27
#define TAG_A 1
 
28
#define TAG_B 2
 
29
#define TAG_C 3
 
30
#define TAG_D 4
 
31
 
 
32
/*
 
33
 *
 
34
 *                  /-->B--\
 
35
 *                  |      |
 
36
 *           -----> A      D---\--->
 
37
 *              ^   |      |   |
 
38
 *              |   \-->C--/   |
 
39
 *              |              |
 
40
 *              \--------------/
 
41
 *
 
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)
 
45
 */
 
46
 
 
47
static struct starpu_task taskA, taskB, taskC, taskD;
 
48
 
 
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;
 
53
 
 
54
static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
 
55
{
 
56
        (void) STARPU_ATOMIC_ADD(&check_cnt, 1);
 
57
}
 
58
 
 
59
static struct starpu_codelet dummy_codelet =
 
60
{
 
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},
 
65
        .model = NULL,
 
66
        .nbuffers = 0
 
67
};
 
68
 
 
69
static void callback_task_D(void *arg __attribute__((unused)))
 
70
{
 
71
        _STARPU_PTHREAD_MUTEX_LOCK(&mutex);
 
72
        loop_cnt++;
 
73
 
 
74
        if (loop_cnt == niter)
 
75
        {
 
76
                /* We are done */
 
77
                taskD.regenerate = 0;
 
78
                _STARPU_PTHREAD_COND_SIGNAL(&cond);
 
79
                _STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
 
80
        }
 
81
        else
 
82
        {
 
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);
 
87
        }
 
88
}
 
89
 
 
90
int main(int argc, char **argv)
 
91
{
 
92
//      unsigned i;
 
93
//      double timing;
 
94
//      struct timeval start;
 
95
//      struct timeval end;
 
96
        int ret;
 
97
 
 
98
        ret = starpu_init(NULL);
 
99
        if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
 
100
        STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
101
 
 
102
        /* Implicit data dependencies and regeneratable tasks are not compatible */
 
103
        starpu_data_set_default_sequential_consistency_flag(0);
 
104
 
 
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 */
 
109
        taskA.use_tag = 1;
 
110
        taskA.tag_id = TAG_A;
 
111
 
 
112
        starpu_task_init(&taskB);
 
113
        taskB.cl = &dummy_codelet;
 
114
        taskB.cl_arg = &taskB;
 
115
        taskB.regenerate = 1;
 
116
        taskB.use_tag = 1;
 
117
        taskB.tag_id = TAG_B;
 
118
 
 
119
        starpu_task_init(&taskC);
 
120
        taskC.cl = &dummy_codelet;
 
121
        taskC.cl_arg = &taskC;
 
122
        taskC.regenerate = 1;
 
123
        taskC.use_tag = 1;
 
124
        taskC.tag_id = TAG_C;
 
125
 
 
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;
 
131
        taskD.use_tag = 1;
 
132
        taskD.tag_id = TAG_D;
 
133
 
 
134
        starpu_tag_declare_deps((starpu_tag_t) TAG_A, 1, (starpu_tag_t) TAG_START);
 
135
 
 
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);
 
138
 
 
139
        starpu_tag_declare_deps((starpu_tag_t) TAG_D, 2, (starpu_tag_t) TAG_B, (starpu_tag_t) TAG_C);
 
140
 
 
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");
 
145
 
 
146
        starpu_tag_notify_from_apps((starpu_tag_t) TAG_START);
 
147
 
 
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);
 
153
 
 
154
        STARPU_ASSERT(check_cnt == (4*loop_cnt));
 
155
 
 
156
        starpu_shutdown();
 
157
 
 
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);
 
163
 
 
164
        return EXIT_SUCCESS;
 
165
 
 
166
enodev:
 
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 */
 
170
        starpu_shutdown();
 
171
        return STARPU_TEST_SKIPPED;
 
172
}
 
173