+/pykokkos
git clone https://git.julia.blue/+/pykokkos
3b7b538
master
1import pykokkos 2from pykokkos .views import View2D 3from pykokkos .workload import KokkosWorkload ,work_unit 4 5 6class MatrixSum (KokkosWorkload ): 7def __init__ (self ,r ,c ): 8self .r = r 9self .c = c 10self .mat = View2D (r ,c ) 11 12for i in range (r ): 13self .mat [i ]= list (range (c * i ,c * (i + 1 ))) 14 15for row in self .mat : 16row ) 17f"Initialized { r } x { c } array" ) 18 19def run_work_units (self ): 20pykokkos .parallel_for (self .r ,self .sum_row ) 21self .total = pykokkos .parallel_reduce (self .r ,self .final_sum ) 22 23def use_results (self ): 24"Total =" ,self .total ) 25 26@work_unit 27def sum_row (self ,i ): 28for j in range (1 ,self .c ): 29self .mat [i ][0 ]+= self .mat [i ][j ] 30 31@work_unit 32def final_sum (self ,i ,accumulator ): 33accumulator += self .mat [i ][0 ] 34 35 36if __name__ == "__main__" : 37MatrixSum (5 ,10 ).execute ()