123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #include <starpu.h>
- #ifdef STARPU_USE_CPU
- #include <omp.h>
- #ifdef STARPU_QUICK_CHECK
- #define NTASKS 4
- #else
- #define NTASKS 10
- #endif
- int parallel_code(unsigned *sched_ctx)
- {
- int i;
- int t = 0;
- int *cpuids = NULL;
- int ncpuids = 0;
- starpu_sched_ctx_get_available_cpuids(*sched_ctx, &cpuids, &ncpuids);
-
- omp_set_num_threads(ncpuids);
- #pragma omp parallel
- {
- starpu_sched_ctx_bind_current_thread_to_cpuid(cpuids[omp_get_thread_num()]);
-
- #pragma omp for
- for(i = 0; i < NTASKS; i++)
- {
- #pragma omp atomic
- t++;
- }
- }
- free(cpuids);
- return t;
- }
- void *th(void* p)
- {
- unsigned* sched_ctx = (unsigned*)p;
- void* ret;
- ret = starpu_sched_ctx_exec_parallel_code((void*)parallel_code, p, *sched_ctx);
- pthread_exit(ret);
- }
- int main(void)
- {
- int ret;
- void* tasks_executed;
- ret = starpu_init(NULL);
- if (ret == -ENODEV)
- return 77;
- STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
- int nprocs1;
- int *procs1;
- unsigned ncpus = starpu_cpu_worker_get_count();
- procs1 = (int*)malloc(ncpus*sizeof(int));
- starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, procs1, ncpus);
- nprocs1 = ncpus;
- unsigned sched_ctx1 = starpu_sched_ctx_create(procs1, nprocs1, "ctx1", STARPU_SCHED_CTX_POLICY_NAME, "dmda", 0);
-
- pthread_t mp;
- pthread_create(&mp, NULL, th, &sched_ctx1);
- pthread_join(mp, &tasks_executed);
-
- starpu_sched_ctx_delete(sched_ctx1);
- printf("ctx%u: tasks starpu executed %ld out of %d\n", sched_ctx1, (intptr_t)tasks_executed, NTASKS);
- starpu_shutdown();
- free(procs1);
- return 0;
- }
- #else
- int main(int argc, char **argv)
- {
-
- return 77;
- }
- #endif
|