12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /*
- * StarPU
- * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * See the GNU Lesser General Public License in COPYING.LGPL for more details.
- */
- #include <stdio.h>
- #include <unistd.h>
- #include <errno.h>
- #include <starpu.h>
- #include <stdlib.h>
- #include <pthread.h>
- #define NBUFFERS 16
- #define NITER 128
- struct data {
- unsigned index;
- unsigned val;
- starpu_data_handle handle;
- };
- struct data buffers[NBUFFERS];
- void callback_sync_data(void *arg)
- {
- struct data *data = arg;
- data->val++;
- starpu_data_release(data->handle);
- }
- int main(int argc, char **argv)
- {
- starpu_init(NULL);
- unsigned b;
- for (b = 0; b < NBUFFERS; b++)
- {
- buffers[b].index = b;
- starpu_variable_data_register(&buffers[b].handle, 0, (uintptr_t)&buffers[b].val, sizeof(unsigned));
- }
- unsigned iter;
- for (iter = 0; iter < NITER; iter++)
- for (b = 0; b < NBUFFERS; b++)
- {
- starpu_data_acquire_cb(buffers[b].handle, STARPU_RW,
- callback_sync_data, &buffers[b]);
- }
- starpu_task_wait_for_all();
- /* do some cleanup */
- for (b = 0; b < NBUFFERS; b++)
- {
- starpu_data_unregister(buffers[b].handle);
- /* check result */
- if (buffers[b].val != NITER)
- {
- fprintf(stderr, "buffer[%d] = %d should be %d\n", b, buffers[b].val, NITER);
- STARPU_ABORT();
- }
- }
- starpu_shutdown();
- return 0;
- }
|