starpu_py.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # StarPU --- Runtime system for heterogeneous multicore architectures.
  2. #
  3. # Copyright (C) 2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. #
  5. # StarPU is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU Lesser General Public License as published by
  7. # the Free Software Foundation; either version 2.1 of the License, or (at
  8. # your option) any later version.
  9. #
  10. # StarPU is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. #
  14. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. #
  16. import starpu
  17. import time
  18. import asyncio
  19. ############################################################################
  20. #function no input no output print hello world
  21. def hello():
  22. print ("Example 1:")
  23. print ("Hello, world!")
  24. #############################################################################
  25. #function no input no output
  26. def func1():
  27. print ("Example 2:")
  28. print ("This is a function no input no output")
  29. ##############################################################################
  30. #using decorator wrap the function no input no output
  31. @starpu.delayed
  32. def func1_deco():
  33. #time.sleep(1)
  34. print ("Example 3:")
  35. print ("This is a function no input no output wrapped by the decorator function")
  36. ##############################################################################
  37. #function no input return a value
  38. def func2():
  39. print ("Example 4:")
  40. return 12
  41. ###############################################################################
  42. #function has 2 int inputs and 1 int output
  43. def multi(a,b):
  44. print ("Example 5:")
  45. return a*b
  46. #print(multi(2, 3))
  47. ###############################################################################
  48. #function has 4 float inputs and 1 float output
  49. def add(a,b,c,d):
  50. print ("Example 6:")
  51. return a+b+c+d
  52. #print(add(1.2, 2.5, 3.6, 4.9))
  53. ###############################################################################
  54. #function has 2 int inputs 1 float input and 1 float output 1 int output
  55. def sub(a,b,c):
  56. print ("Example 7:")
  57. return a-b-c, a-b
  58. #print(sub(6, 2, 5.9))
  59. ###############################################################################
  60. #using decorator wrap the function with input
  61. @starpu.delayed
  62. def add_deco(a,b,c):
  63. #time.sleep(1)
  64. print ("Example 8:")
  65. print ("This is a function with input and output wrapped by the decorator function:")
  66. return a+b+c
  67. ###############################################################################
  68. async def main():
  69. #submit function "hello"
  70. fut = starpu.task_submit(hello)
  71. await fut
  72. #submit function "func1"
  73. fut1 = starpu.task_submit(func1)
  74. await fut1
  75. #apply starpu.delayed(func1_deco())
  76. await func1_deco()
  77. #submit function "func2"
  78. fut2 = starpu.task_submit(func2)
  79. res2 = await fut2
  80. #print the result of function
  81. print("This is a function no input and the return value is", res2)
  82. #submit function "multi"
  83. fut3 = starpu.task_submit(multi, 2, 3)
  84. res3 = await fut3
  85. print("The result of function multi is :", res3)
  86. #submit function "add"
  87. fut4 = starpu.task_submit(add, 1.2, 2.5, 3.6, 4.9)
  88. res4 = await fut4
  89. print("The result of function add is :", res4)
  90. #submit function "sub"
  91. fut5 = starpu.task_submit(sub, 6, 2, 5.9)
  92. res5 = await fut5
  93. print("The result of function sub is:", res5)
  94. #apply starpu.delayed(add_deco)
  95. res6 = await add_deco(1,2,3)
  96. print("The result of function is", res6)
  97. asyncio.run(main())
  98. #starpu.task_wait_for_all()