瀏覽代碼

Testcases: add new application to test combined synchronous and asynchronous acquire/release

Nathalie Furmento 15 年之前
父節點
當前提交
5f0f59b8d5
共有 2 個文件被更改,包括 70 次插入0 次删除
  1. 1 0
      tests/Makefile.am
  2. 69 0
      tests/datawizard/acquire_release.c

+ 1 - 0
tests/Makefile.am

@@ -94,6 +94,7 @@ check_PROGRAMS += 				\
 	core/declare_deps_after_submission	\
 	core/declare_deps_after_submission_synchronous	\
 	core/get_current_task			\
+	datawizard/acquire_release		\
 	datawizard/data_implicit_deps		\
 	datawizard/scratch			\
 	datawizard/sync_and_notify_data		\

+ 69 - 0
tests/datawizard/acquire_release.c

@@ -0,0 +1,69 @@
+/*
+ * StarPU
+ * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
+ *
+ * This program 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.
+ *
+ * This program 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>
+
+static unsigned ntasks = 400;
+
+void increment_cpu(void *descr[], __attribute__ ((unused)) void *_args)
+{
+	unsigned *tokenptr = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[0]);
+	(*tokenptr)++;
+}
+
+static starpu_codelet increment_cl = {
+        .where = STARPU_CPU,
+	.cpu_func = increment_cpu,
+	.nbuffers = 1
+};
+
+unsigned token = 42;
+starpu_data_handle token_handle;
+
+void increment_token()
+{
+	struct starpu_task *task = starpu_task_create();
+	task->cl = &increment_cl;
+	task->buffers[0].handle = token_handle;
+	task->buffers[0].mode = STARPU_RW;
+	starpu_task_submit(task);
+}
+
+void callback(void *arg __attribute__ ((unused)))
+{
+        starpu_data_release(token_handle);
+}
+
+int main(int argc, char **argv)
+{
+	int i;
+
+        starpu_init(NULL);
+	starpu_variable_data_register(&token_handle, 0, (uintptr_t)&token, sizeof(unsigned));
+
+	for(i=0; i<ntasks; i++)
+	{
+                starpu_data_acquire(token_handle, STARPU_RW);
+                increment_token();
+                starpu_data_release(token_handle);
+
+                starpu_data_acquire_cb(token_handle, STARPU_RW, callback, NULL);
+	}
+
+	starpu_shutdown();
+
+	return 0;
+}