Coverage for pySDC/projects/GPU/ac_fft.py: 0%

50 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-16 14:51 +0000

1from pySDC.implementations.problem_classes.AllenCahn_2D_FFT import allencahn2d_imex as ac_fft_cpu 

2from pySDC.implementations.problem_classes.AllenCahn_2D_FFT_gpu import allencahn2d_imex as ac_fft_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 

7 

8 

9def set_parameter(): 

10 # initialize problem parameters 

11 problem_params = dict() 

12 problem_params['nu'] = 2 

13 problem_params['eps'] = 0.04 

14 problem_params['radius'] = 0.25 

15 problem_params['nvars'] = (512, 512) 

16 

17 # initialize level parameters 

18 level_params = dict() 

19 level_params['restol'] = 1e-07 

20 level_params['dt'] = 1e-07 

21 level_params['nsweeps'] = 1 

22 

23 # initialize sweeper parameters 

24 sweeper_params = dict() 

25 sweeper_params['collocation_class'] = Collocation 

26 sweeper_params['node_type'] = 'LEGENDRE' 

27 sweeper_params['quad_type'] = 'RADAU-RIGHT' 

28 sweeper_params['QI'] = ['LU'] 

29 sweeper_params['QE'] = ['PIC'] 

30 sweeper_params['num_nodes'] = 3 

31 sweeper_params['initial_guess'] = 'spread' 

32 

33 # initialize step parameters 

34 step_params = dict() 

35 step_params['maxiter'] = 50 

36 

37 # setup parameters "in time" 

38 t0 = 0 

39 schritte = 8 

40 Tend = schritte * level_params['dt'] 

41 

42 # initialize controller parameters 

43 controller_params = dict() 

44 controller_params['logger_level'] = 30 

45 

46 # fill description dictionary for easy step instantiation 

47 description = dict() 

48 description['problem_params'] = problem_params # pass problem parameters 

49 description['sweeper_class'] = imex_1st_order # pass sweeper 

50 description['sweeper_params'] = sweeper_params # pass sweeper parameters 

51 description['level_params'] = level_params # pass level parameters 

52 description['step_params'] = step_params # pass step parameters 

53 

54 return controller_params, description, t0, Tend 

55 

56 

57def main(): 

58 controller_params, description, t0, Tend = set_parameter() 

59 

60 # fill description dictionary with CPU problem 

61 description['problem_class'] = ac_fft_cpu 

62 

63 # instantiate controller cpu 

64 controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description) 

65 

66 # get initial values on finest level cpu 

67 P = controller.MS[0].levels[0].prob 

68 uinit = P.u_exact(t0) 

69 

70 # call main function to get things done on cpu... 

71 uend_cpu, stats_cpu = controller.run(u0=uinit, t0=t0, Tend=Tend) 

72 timing_cpu = sort_stats(filter_stats(stats_cpu, type='timing_run'), sortby='time') 

73 print('Runtime CPU:', timing_cpu[0][1]) 

74 

75 # change description dictionary with GPU problem 

76 description['problem_class'] = ac_fft_gpu 

77 

78 # instantiate controller cpu 

79 controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description) 

80 

81 # get initial values on finest level cpu 

82 P = controller.MS[0].levels[0].prob 

83 uinit = P.u_exact(t0) 

84 

85 # call main function to get things done on cpu... 

86 uend_gpu, stats_gpu = controller.run(u0=uinit, t0=t0, Tend=Tend) 

87 timing_gpu = sort_stats(filter_stats(stats_gpu, type='timing_run'), sortby='time') 

88 print('Runtime GPU:', timing_gpu[0][1]) 

89 

90 assert abs(uend_gpu.get() - uend_cpu) < 1e-13, abs(uend_gpu.get() - uend_cpu) 

91 

92 

93if __name__ == '__main__': 

94 main()