starpu_py.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 no input no output
  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. res2 = await fut2
  42. #print the result of function
  43. print("This is a function no input and the return value is", res2)
  44. asyncio.run(func2_wait())
  45. ###############################################################################
  46. #function has 2 int inputs and 1 int output
  47. def multi(a,b):
  48. print ("Example 5:")
  49. return a*b
  50. #submit function "multi"
  51. async def multi_wait():
  52. fut3 = starpu.task_submit(multi, [2, 3])
  53. res3=await fut3
  54. print("The result of function multi is :", res3)
  55. asyncio.run(multi_wait())
  56. #print(multi(2, 3))
  57. ###############################################################################
  58. #function has 4 float inputs and 1 float output
  59. def add(a,b,c,d):
  60. print ("Example 6:")
  61. return a+b+c+d
  62. #submit function "add"
  63. async def add_wait():
  64. fut4 = starpu.task_submit(add, [1.2, 2.5, 3.6, 4.9])
  65. res4=await fut4
  66. print("The result of function add is :", res4)
  67. asyncio.run(add_wait())
  68. #print(add(1.2, 2.5, 3.6, 4.9))
  69. ###############################################################################
  70. #function has 2 int inputs 1 float input and 1 float output 1 int output
  71. def sub(a,b,c):
  72. print ("Example 7:")
  73. return a-b-c, a-b
  74. #submit function "sub"
  75. async def sub_wait():
  76. fut5 = starpu.task_submit(sub, [6, 2, 5.9])
  77. res5 = await fut5
  78. print("The result of function sub is:", res5)
  79. asyncio.run(sub_wait())
  80. #print(sub(6, 2, 5.9))
  81. ###############################################################################
  82. starpu.task_wait_for_all()