starpu_py.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #submit function "hello"
  25. async def hello_wait():
  26. fut = starpu.task_submit(hello,[])
  27. await fut
  28. asyncio.run(hello_wait())
  29. #############################################################################
  30. #function no input no output
  31. def func1():
  32. print ("Example 2:")
  33. print ("This is a function no input no output")
  34. #submit function "func1"
  35. async def func1_wait():
  36. fut1 = starpu.task_submit(func1,[])
  37. await fut1
  38. asyncio.run(func1_wait())
  39. ##############################################################################
  40. #using decorator wrap the function no input no output
  41. @starpu.delayed
  42. def func1_deco():
  43. #time.sleep(1)
  44. print ("Example 3:")
  45. print ("This is a function wrapped by the decorator function")
  46. #apply starpu.delayed(func1_deco())
  47. func1_deco()
  48. ##############################################################################
  49. #function no input return a value
  50. def func2():
  51. print ("Example 4:")
  52. return 12
  53. #submit function "func2"
  54. async def func2_wait():
  55. fut2 = starpu.task_submit(func2, [])
  56. res2 = await fut2
  57. #print the result of function
  58. print("This is a function no input and the return value is", res2)
  59. asyncio.run(func2_wait())
  60. ###############################################################################
  61. #function has 2 int inputs and 1 int output
  62. def multi(a,b):
  63. print ("Example 5:")
  64. return a*b
  65. #submit function "multi"
  66. async def multi_wait():
  67. fut3 = starpu.task_submit(multi, [2, 3])
  68. res3=await fut3
  69. print("The result of function multi is :", res3)
  70. asyncio.run(multi_wait())
  71. #print(multi(2, 3))
  72. ###############################################################################
  73. #function has 4 float inputs and 1 float output
  74. def add(a,b,c,d):
  75. print ("Example 6:")
  76. return a+b+c+d
  77. #submit function "add"
  78. async def add_wait():
  79. fut4 = starpu.task_submit(add, [1.2, 2.5, 3.6, 4.9])
  80. res4=await fut4
  81. print("The result of function add is :", res4)
  82. asyncio.run(add_wait())
  83. #print(add(1.2, 2.5, 3.6, 4.9))
  84. ###############################################################################
  85. #function has 2 int inputs 1 float input and 1 float output 1 int output
  86. def sub(a,b,c):
  87. print ("Example 7:")
  88. return a-b-c, a-b
  89. #submit function "sub"
  90. async def sub_wait():
  91. fut5 = starpu.task_submit(sub, [6, 2, 5.9])
  92. res5 = await fut5
  93. print("The result of function sub is:", res5)
  94. asyncio.run(sub_wait())
  95. #print(sub(6, 2, 5.9))
  96. ###############################################################################
  97. starpu.task_wait_for_all()