| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- /* StarPU --- Runtime system for heterogeneous multicore architectures.
- *
- * Copyright (C) 2014 Inria
- *
- * StarPU 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.
- *
- * StarPU 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 <starpu.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #ifdef STARPU_USE_CUDA
- #include <starpu_cuda.h>
- #endif
- static unsigned cnt;
- static void cpu_memcpy(void *descr[], void *cl_arg)
- {
- double *res = (double *)STARPU_VECTOR_GET_PTR(descr[0]);
- double *dst = (double *)STARPU_VECTOR_GET_PTR(descr[1]);
- int n = (int) STARPU_VECTOR_GET_NX(descr[0]);
- int me = (uintptr_t)cl_arg;
- if (me == 0)
- {
- sleep(1);
- STARPU_ASSERT(STARPU_ATOMIC_ADD(&cnt,1) == 1);
- }
- else
- STARPU_ASSERT(STARPU_ATOMIC_ADD(&cnt,1) != 1);
- memcpy(dst, res, n*sizeof(double));
- }
- static struct starpu_codelet my_cl = {
- .where = STARPU_CPU,
- .cpu_funcs = {cpu_memcpy, NULL},
- .nbuffers = STARPU_VARIABLE_NBUFFERS
- };
- int
- main()
- {
- double *res, *a;
- unsigned n=100000, i;
- starpu_data_handle_t res_handle, a_handle;
- unsigned nb_tasks = 10, worker;
- if (starpu_init(NULL))
- exit(-1);
- starpu_malloc((void**)&res, n*sizeof(double));
- starpu_malloc((void**)&a, n*sizeof(double));
- for(i=0; i < n; i++)
- res[i] = a[i] = 1.0;
-
- starpu_vector_data_register(&res_handle, 0, (uintptr_t)res, (uint32_t)n, sizeof(double));
- starpu_vector_data_register(&a_handle, 0, (uintptr_t)a, (uint32_t)n, sizeof(double));
- for (i = 0; i < nb_tasks; i++) {
- struct starpu_task *task = starpu_task_create();
- task->cl=&my_cl;
- task->nbuffers = 2;
- task->handles[0] = res_handle;
- if (i == 0)
- task->modes[0] = STARPU_RW;
- else
- task->modes[0] = STARPU_RW | STARPU_COMMUTE;
-
- task->handles[1] = a_handle;
- task->modes[1] = STARPU_R;
- task->cl_arg = (void*)(uintptr_t)i;
-
- if (starpu_task_submit(task)) {
- fprintf(stderr,"taks submmition failed!");
- exit(EXIT_FAILURE);
- }
- }
- starpu_task_wait_for_all ();
- starpu_data_unregister(res_handle);
- starpu_data_unregister(a_handle);
- starpu_free(res);
- starpu_free(a);
- starpu_shutdown();
- return EXIT_SUCCESS;
- }
|