Browse Source

Add another classical synchronization problem to stress data management.

Cédric Augonnet 15 years ago
parent
commit
4ac2e92f42
2 changed files with 51 additions and 0 deletions
  1. 4 0
      tests/Makefile.am
  2. 47 0
      tests/datawizard/readers_and_writers.c

+ 4 - 0
tests/Makefile.am

@@ -82,6 +82,7 @@ check_PROGRAMS += 				\
 	core/empty_task_sync_point		\
 	datawizard/write_only_tmp_buffer	\
 	datawizard/dining_philosophers		\
+	datawizard/readers_and_writers		\
 	errorcheck/starpu_init_noworker		\
 	helper/cublas_init			\
 	helper/pinned_memory			\
@@ -132,6 +133,9 @@ datawizard_write_only_tmp_buffer_SOURCES =	\
 datawizard_dining_philosophers_SOURCES = 	\
 	datawizard/dining_philosophers.c
 
+datawizard_readers_and_writers_SOURCES = 	\
+	datawizard/readers_and_writers.c
+
 errorcheck_starpu_init_noworker_SOURCES =	\
 	errorcheck/starpu_init_noworker.c
 

+ 47 - 0
tests/datawizard/readers_and_writers.c

@@ -0,0 +1,47 @@
+#include <starpu.h>
+
+static unsigned book = 0;
+static starpu_data_handle book_handle;
+
+static void dummy_kernel(starpu_data_interface_t *buffers, void *arg)
+{
+}
+
+static starpu_codelet rw_cl = {
+	.where = CORE|CUDA,
+	.cuda_func = dummy_kernel,
+	.core_func = dummy_kernel,
+	.nbuffers = 1
+};
+
+int main(int argc, char **argv)
+{
+	starpu_init(NULL);
+
+	/* initialize the resource */
+	starpu_register_vector_data(&book_handle, 0, (uintptr_t)&book, 1, sizeof(unsigned));
+
+	unsigned ntasks = 16*1024;
+
+	unsigned t;
+	for (t = 0; t < ntasks; t++)
+	{
+		struct starpu_task *task = starpu_task_create();
+
+		task->cl = &rw_cl;
+
+		/* we randomly select either a reader or a writer (give 10
+		 * times more chances to be a reader) */
+		task->buffers[0].mode = ((rand() % 10)==0)?STARPU_W:STARPU_R;
+		task->buffers[0].handle = book_handle;
+
+		int ret = starpu_submit_task(task);
+		STARPU_ASSERT(!ret);
+	}
+
+	starpu_wait_all_tasks();
+
+	starpu_shutdown();
+
+	return 0;
+}