parallel_task.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Inria
  4. * Copyright (C) 2010-2011,2014-2015 Université de Bordeaux
  5. * Copyright (C) 2013,2016-2017 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include <common/config.h>
  20. #include <core/jobs.h>
  21. #include <core/task.h>
  22. #include <common/utils.h>
  23. #include <core/workers.h>
  24. #include <common/barrier.h>
  25. struct starpu_task *starpu_task_dup(struct starpu_task *task)
  26. {
  27. struct starpu_task *task_dup;
  28. _STARPU_MALLOC(task_dup, sizeof(struct starpu_task));
  29. /* TODO perhaps this is a bit too much overhead and we should only copy
  30. * part of the structure ? */
  31. memcpy(task_dup, task, sizeof(struct starpu_task));
  32. return task_dup;
  33. }
  34. void starpu_parallel_task_barrier_init_n(struct starpu_task* task, int worker_size)
  35. {
  36. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  37. j->task_size = worker_size;
  38. j->combined_workerid = -1;
  39. j->active_task_alias_count = 0;
  40. //fprintf(stderr, "POP -> size %d best_size %d\n", worker_size, best_size);
  41. STARPU_PTHREAD_BARRIER_INIT(&j->before_work_barrier, NULL, worker_size);
  42. STARPU_PTHREAD_BARRIER_INIT(&j->after_work_barrier, NULL, worker_size);
  43. j->after_work_busy_barrier = worker_size;
  44. return;
  45. }
  46. void starpu_parallel_task_barrier_init(struct starpu_task* task, int workerid)
  47. {
  48. /* The master needs to dispatch the task between the
  49. * different combined workers */
  50. struct _starpu_combined_worker *combined_worker = _starpu_get_combined_worker_struct(workerid);
  51. int worker_size = combined_worker->worker_size;
  52. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  53. starpu_parallel_task_barrier_init_n(task, worker_size);
  54. j->combined_workerid = workerid;
  55. }