Bläddra i källkod

Add a the classical dining philosopher example: we have to explicitely order
the resources yet otherwise we get a deadlock as StarPU does not try to get the
data in a sorted way. This is a bug that should be fixed at some point.

Cédric Augonnet 15 år sedan
förälder
incheckning
152b6a7329
2 ändrade filer med 80 tillägg och 0 borttagningar
  1. 4 0
      tests/Makefile.am
  2. 76 0
      tests/datawizard/dining_philosophers.c

+ 4 - 0
tests/Makefile.am

@@ -81,6 +81,7 @@ check_PROGRAMS += 				\
 	core/empty_task				\
 	core/empty_task_sync_point		\
 	datawizard/write_only_tmp_buffer	\
+	datawizard/dining_philosophers		\
 	errorcheck/starpu_init_noworker		\
 	helper/cublas_init			\
 	helper/pinned_memory			\
@@ -128,6 +129,9 @@ core_empty_task_sync_point_SOURCES =		\
 datawizard_write_only_tmp_buffer_SOURCES =	\
 	datawizard/write_only_tmp_buffer.c
 
+datawizard_dining_philosophers_SOURCES = 	\
+	datawizard/dining_philosophers.c
+
 errorcheck_starpu_init_noworker_SOURCES =	\
 	errorcheck/starpu_init_noworker.c
 

+ 76 - 0
tests/datawizard/dining_philosophers.c

@@ -0,0 +1,76 @@
+#include <starpu.h>
+
+/* number of philosophers */
+#define N	16
+
+starpu_data_handle fork_handles[N];
+unsigned forks[N];
+
+static void eat_kernel(starpu_data_interface_t *buffers, void *arg)
+{
+}
+
+static starpu_codelet eating_cl = {
+	.where = CORE|CUDA,
+	.cuda_func = eat_kernel,
+	.core_func = eat_kernel,
+	.nbuffers = 2
+};
+
+void submit_one_task(unsigned p)
+{
+	struct starpu_task *task = starpu_task_create();
+
+	task->cl = &eating_cl;
+
+	unsigned left = p;
+	unsigned right = (p+1)%N;
+
+	/* TODO we should not have to order these ressources ! */
+	/* the last philosopher is left-handed ;) */
+	if (p == (N - 1))
+	{
+		unsigned tmp;
+		tmp = right;
+		right = left;
+		left = tmp;
+	}
+
+	task->buffers[0].handle = fork_handles[left];
+	task->buffers[0].mode = STARPU_RW;
+	task->buffers[1].handle = fork_handles[right];
+	task->buffers[1].mode = STARPU_RW;
+
+	int ret = starpu_submit_task(task);
+	STARPU_ASSERT(!ret);
+}
+
+int main(int argc, int argv)
+{
+	starpu_init(NULL);
+
+	/* initialize the forks */
+	unsigned f;
+	for (f = 0; f < N; f++)
+	{
+		forks[f] = 0;
+
+		starpu_register_vector_data(&fork_handles[f], 0, (uintptr_t)&forks[f], 1, sizeof(unsigned));
+	}
+
+	unsigned ntasks = 1024;
+
+	unsigned t;
+	for (t = 0; t < ntasks; t++)
+	{
+		/* select one philosopher randomly */
+		unsigned philosopher = rand() % N;
+		submit_one_task(philosopher);
+	}
+
+	starpu_wait_all_tasks();
+
+	starpu_shutdown();
+
+	return 0;
+}