starpu_py.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import starpu
  2. import time
  3. import asyncio
  4. ############################################################################
  5. #function no input no output print hello world
  6. def hello():
  7. print ("Example 1:")
  8. print ("Hello, world!")
  9. #submit function "hello"
  10. async def hello_wait():
  11. fut = starpu.task_submit(hello)
  12. await fut
  13. asyncio.run(hello_wait())
  14. #############################################################################
  15. #function no input no output
  16. def func1():
  17. print ("Example 2:")
  18. print ("This is a function no input no output")
  19. #submit function "func1"
  20. async def func1_wait():
  21. fut1 = starpu.task_submit(func1)
  22. await fut1
  23. asyncio.run(func1_wait())
  24. ##############################################################################
  25. #using decorator wrap the function
  26. @starpu.delayed
  27. def func1_deco():
  28. #time.sleep(1)
  29. print ("Example 3:")
  30. print ("This is a function wrapped by the decorator function")
  31. #apply starpu.delayed(func1_deco())
  32. func1_deco()
  33. ##############################################################################
  34. #function no input return a value
  35. def func2():
  36. print ("Example 4:")
  37. return 12
  38. #submit function "func2"
  39. async def func2_wait():
  40. fut2 = starpu.task_submit(func2)
  41. res = await fut2
  42. #print the result of function
  43. print("This is a function no input and the return value is", res)
  44. asyncio.run(func2_wait())
  45. ###############################################################################
  46. starpu.task_wait_for_all()