Browse Source

starpupy: add python main function to use starpu wrapper

HE Kun 4 years ago
parent
commit
8c7b6dddbe
2 changed files with 55 additions and 19 deletions
  1. 7 2
      starpupy/wrapper/starpu/delay.py
  2. 48 17
      starpupy/wrapper/starpu_py.py

+ 7 - 2
starpupy/wrapper/starpu/delay.py

@@ -1,5 +1,10 @@
 from starpu import task
+import asyncio
+
 def delayed(f):
 	def submit():
-		task.task_submit(f)
-	return submit
+		async def fut_wait():
+			fut = task.task_submit(f)
+			await fut
+		asyncio.run(fut_wait())
+	return submit

+ 48 - 17
starpupy/wrapper/starpu_py.py

@@ -1,28 +1,59 @@
 import starpu
 import time
+import asyncio
 
+############################################################################
+#function no input no output print hello world
+def hello():
+	print ("Example 1:")
+	print ("Hello, world!")
+
+#submit function "hello"
+async def hello_wait():
+    fut = starpu.task_submit(hello)
+    await fut
+asyncio.run(hello_wait())
+
+#############################################################################
+
+#function no input no output
+def func1():
+	print ("Example 2:")
+	print ("This is a function no input no output")
+
+#submit function "func1"
+async def func1_wait():
+    fut1 = starpu.task_submit(func1)
+    await fut1
+asyncio.run(func1_wait())
+
+##############################################################################
+
+#using decorator wrap the function
 @starpu.delayed
-def salut():
-	time.sleep(1)
-	print ("salut, le monde")
+def func1_deco():
+	#time.sleep(1)
+	print ("Example 3:")
+	print ("This is a function wrapped by the decorator function")
 
+#apply starpu.delayed(func1_deco())
+func1_deco()
 
-def hello():
-	print ("print in python")
-	print ("Hello, world!")
+##############################################################################
 
-starpu.pause()
+#function no input return a value
+def func2():
+	print ("Example 4:")
+	return 12
 
-print("begin to submit task in python")
-fut=starpu.task_submit(hello)
-salut()
-#starpu.task_submit(hello)
-#starpu.task_submit(hello)
-print("finish to submit task in python")
-starpu.resume()
+#submit function "func2"
+async def func2_wait():
+    fut2 = starpu.task_submit(func2)
+    res = await fut2
+    #print the result of function
+    print("This is a function no input and the return value is", res)
+asyncio.run(func2_wait())
 
-#print("begin to sleep")
-#time.sleep(1)
-#print("finish to sleep")
+###############################################################################
 
 starpu.task_wait_for_all()