Coverage for pySDC/projects/GPU/heat.py: 0%
6 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-16 14:51 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-16 14:51 +0000
1from pySDC.implementations.problem_classes.HeatEquation_ND_FD import heatNd_forced as heat_cpu
2from pySDC.implementations.problem_classes.HeatEquation_ND_FD_CuPy import heatNd_forced as heat_gpu
3from pySDC.core.collocation import CollBase as Collocation
4from pySDC.implementations.sweeper_classes.imex_1st_order import imex_1st_order
5from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI
6from pySDC.helpers.stats_helper import filter_stats, sort_stats
9def set_parameter(): # pragma: no cover
10 # initialize problem parameters
11 problem_params = dict()
12 problem_params['nu'] = 1
13 problem_params['freq'] = (4, 4, 4)
14 problem_params['order'] = 2
15 problem_params['lintol'] = 1e-10
16 problem_params['liniter'] = 99
17 problem_params['solver_type'] = 'CG'
18 problem_params['nvars'] = (32, 32, 32)
19 problem_params['bc'] = 'periodic'
21 # initialize level parameters
22 level_params = dict()
23 level_params['restol'] = 1e-07
24 level_params['dt'] = 1e-07
25 level_params['nsweeps'] = 1
27 # initialize sweeper parameters
28 sweeper_params = dict()
29 sweeper_params['collocation_class'] = Collocation
30 sweeper_params['node_type'] = 'LEGENDRE'
31 sweeper_params['quad_type'] = 'RADAU-RIGHT'
32 sweeper_params['QI'] = ['LU']
33 sweeper_params['QE'] = ['PIC']
34 sweeper_params['num_nodes'] = 3
35 sweeper_params['initial_guess'] = 'spread'
37 # initialize step parameters
38 step_params = dict()
39 step_params['maxiter'] = 50
41 # setup parameters "in time"
42 t0 = 0
43 schritte = 8
44 Tend = schritte * level_params['dt']
46 # initialize controller parameters
47 controller_params = dict()
48 controller_params['logger_level'] = 30
50 # fill description dictionary for easy step instantiation cpu
51 description = dict()
52 description['problem_params'] = problem_params # pass problem parameters
53 description['sweeper_class'] = imex_1st_order # pass sweeper
54 description['sweeper_params'] = sweeper_params # pass sweeper parameters
55 description['level_params'] = level_params # pass level parameters
56 description['step_params'] = step_params # pass step parameters
58 return controller_params, description, t0, Tend
61def main(): # pragma: no cover
62 controller_params, description, t0, Tend = set_parameter()
64 # fill description dictionary with CPU problem
65 description['problem_class'] = heat_cpu
67 # instantiate controller cpu
68 controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description)
70 # get initial values on finest level cpu
71 P = controller.MS[0].levels[0].prob
72 uinit = P.u_exact(t0)
74 # call main function to get things done on cpu...
75 uend_cpu, stats_cpu = controller.run(u0=uinit, t0=t0, Tend=Tend)
76 timing_cpu = sort_stats(filter_stats(stats_cpu, type='timing_run'), sortby='time')
77 print('Runtime CPU:', timing_cpu[0][1])
79 # change description dictionary for GPU problem
80 description['problem_class'] = heat_gpu
82 # instantiate controller cpu
83 controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description)
85 # get initial values on finest level cpu
86 P = controller.MS[0].levels[0].prob
87 uinit = P.u_exact(t0)
89 # call main function to get things done on cpu...
90 uend_gpu, stats_gpu = controller.run(u0=uinit, t0=t0, Tend=Tend)
91 timing_gpu = sort_stats(filter_stats(stats_gpu, type='timing_run'), sortby='time')
92 print('Runtime GPU:', timing_gpu[0][1])
94 assert abs(uend_gpu.get() - uend_cpu) < 1e-13, abs(uend_gpu.get() - uend_cpu)
97if __name__ == '__main__':
98 main()