DOI QR코드

DOI QR Code

Just-In-Time 컴파일러를 이용한 파이썬 기반 지구동역학 코드 가속화 연구

Boosting the Performance of Python-based Geodynamic Code using the Just-In-Time Compiler

  • 박상진 (강원대학교 지구물리학과) ;
  • 안수정 (강원대학교 지구물리학과) ;
  • 소병달 (강원대학교 지구물리학과)
  • Park, Sangjin (Department of Geophysics, Kangwon National University) ;
  • An, Soojung (Department of Geophysics, Kangwon National University) ;
  • So, Byung-Dal (Department of Geophysics, Kangwon National University)
  • 투고 : 2021.03.08
  • 발행 : 2021.05.31

초록

파이썬은 다른 정적 언어(예, C, C++, FORTRAN 등)에 비해 실행 속도가 느리기 때문에 대규모 반복이 필요한 지구동역학 코드를 작성하는데 적합하지 않은 것으로 인식되어 왔다. 그러나 파이썬의 계산 속도를 향상시키기 위해 Just-In-Time (JIT) 컴파일 등과 같은 많은 고속화 수단이 개발되었다. 우리는 파이썬을 기반으로 JIT 컴파일러에 최적화된 맨틀 유동 지구동역학 코드를 개발했다. 코드는 지구동역학 분야에서 널리 사용되는 PIC (Particle-In-Cell) 방법과 유한요소법을 결합하여 맨틀 대류를 수치 모사하며, 코드의 신뢰성을 정량적으로 평가하기 위해 잘 알려진 2차원 맨틀 대류 문제를 벤치마킹했다. 수치 모사 결과, 제곱근 평균 제곱 속도와 넛셀 수가 이전 연구와 거의 일치함을 확인했다. JIT 컴파일러를 적용한 코드는 적용하지 않았을 경우와 대비해 계산 속도가 PIC 방법에서 최대 258배, 전체 행렬 조립 과정에서 최대 30배 향상했다. 따라서, 이번 연구는 파이썬의 계산 성능이 JIT 등의 가속기를 이용하여 충분히 향상되며, 많은 지구 동역학 문제를 해결하는데 활용될 수 있음을 제시하였다.

As the execution speed of Python is slower than those of other programming languages (e.g., C, C++, and FORTRAN), Python is not considered to be efficient for writing numerical geodynamic code that requires numerous iterations. Recently, many computational techniques, such as the Just-In-Time (JIT) compiler, have been developed to enhance the calculation speed of Python. Here, we developed two-dimensional (2D) numerical geodynamic code that was optimized for the JIT compiler, based on Python. Our code simulates mantle convection by combining the Particle-In-Cell (PIC) scheme and the finite element method (FEM), which are both commonly used in geodynamic modeling. We benchmarked well-known mantle convection problems to evaluate the reliability of our code, which confirmed that the root mean square velocity and Nusselt number obtained from our numerical modeling were consistent with those of the mantle convection problems. The matrix assembly and PIC processes in our code, when run with the JIT compiler, successfully achieved a speed-up 30× and 258× faster than without the JIT compiler, respectively. Our Python-based FEM-PIC code shows the high potential of Python for geodynamic modeling cases that require complex computations.

키워드

과제정보

본 연구는 "행정안전부 지진방재분야 전문인력양성사업", 2021년도 정부(교육부)의 재원으로 한국연구재단의 지원을 받아 수행된 신진연구지원 사업(NRF-2019R1C1C1010804)과 기초연구사업(No.2019R1A6A1A03033167)으로 수행되었습니다.

참고문헌

  1. Aagaard, B. T., Knepley, M. G., & Williams, C. A., 2013, A domain decomposition approach to implementing fault slip in finite-element models of quasi-static and dynamic crustal deformation, J. Geophys. Res.-Solid Earth, 118(6), 3059-3079, doi: 10.1002/jgrb.5021.
  2. Akeret, J., Gamper, L., Amara, A., and Refregier, A., 2015, HOPE: A Python just-in-time compiler for astrophysical computations, Astron. Comput., 10, 1-8, doi: 10.1016/j.ascom.2014.12.001.
  3. Behnel, S., Bradshaw, R., Citro, C., Dalcin, L., Seljebotn, D. S., and Smith, K., 2011, Cython: The best of both worlds, Comput. Sci. Eng., 13(2), 31-39, doi: 10.1109/MCSE.2010.118.
  4. Blankenbach, B., Busse, F., Christensen, U., Cserepes, L., Gunkel, D., Hansen, U., Harder, H., Jarvis, G., Koch, M., and Marquart, G., 1989, A benchmark comparison for mantle convection codes, Geophys. J. Int., 98(1), 23-38, doi: 10.1111/j.1365-246X.1989.tb05511.x.
  5. Chaves, J. C., Nehrbass, J., Guilfoos, B., Gardiner, J., Ahalt, S., Krishnamurthy, A., Unpingco, J., Chalker, A., Warnock, A., and Samsi, S., 2006, Octave and Python: High-level scripting languages productivity and performance evaluation, HPCMP Users Group Conference, 429-434, doi: 10.1109/HPCMPUGC.2006.55.
  6. Cock, P. J., Antao, T., Chang, J. T., Chapman, B. A., Cox, C. J., Dalke, A., Friedberg, I., Hamelryck, T., Kauff, F., and Wilczynski, B., 2009, Biopython: freely available Python tools for computational molecular biology and bioinformatics, Bioinformatics, 25(11), 1422-1423, doi: 10.1093/bioinformatics/btp163.
  7. Dabrowski, M., Krotkiewski, M., and Schmid, D. W., 2008, MILAMIN: MATLAB-based finite element method solver for large problems, Geochem. Geophys. Geosyst., 9(4), Q04030, doi: 10.1029/2007GC001719.
  8. Dalcin, L. D., Paz, R. R., Kler, P. A., and Cosimo, A., 2011, Parallel distributed computing using Python, Adv. Water Resour., 34(9), 1124-1139, doi: 10.1016/j.advwatres. 2011.04.013.
  9. Furuichi, M., and May, D. A., 2015, Implicit solution of the material transport in stokes flow simulation: Toward thermal convection simulation surrounded by free surface, Comput. Phys. Commun., 192, 1-11, doi: 10.1016/j.cpc.2015. 02.011.
  10. Garel, F., Goes, S., Davies, D. R., Davies, J. H., Kramer, S. C., and Wilson, C. R., 2014, Interaction of subducted slabs with the mantle transition-zone: A regime diagram from 2-D thermo-mechanical models with a mobile trench and an overriding plate, Geochem. Geophys. Geosyst., 15(5), 1739-1765, doi: 10.1002/2014GC005257.
  11. Gassmoller, R., Lokavarapu, H., Heien, E., Puckett, E. G., and Bangerth, W., 2018, Flexible and Scalable Particle-in-Cell Methods With Adaptive Mesh Refinement for Geodynamic Computations, Geochem. Geophys. Geosyst., 19(9), 3596-3604, doi: 10.1029/2018GC007508.
  12. Gerya, T., 2015, Tectonic overpressure and underpressure in lithospheric tectonics and metamorphism, J. Metamorph. Geol., 33(8), 785-800, doi: 10.1111/jmg.12144.
  13. Glerum, A., Thieulot, C., Fraters, M., Blom, C., & Spakman, W., 2018, Nonlinear viscoplasticity in ASPECT: benchmarking and applications to subduction, Solid Earth, 9(2), 267-294, doi: 10.1111/jmg.12144.
  14. Gurnis, M., and Davies, G. F., 1986, Mixing in numerical models of mantle convection incorporating plate kinematics, J. Geophys. Res.-Solid Earth, 91(B6), 6375-6395, doi: 10.1029/JB091iB06p06375.
  15. Hunter, J. D., 2007, Matplotlib: A 2D graphics environment, IEEE Ann. Hist. Comput., 9(03), 90-95, doi: 10.1109/MCSE.2007.55.
  16. King, S. D., 2009, On topography and geoid from 2-D stagnant lid convection calculations, Geochem. Geophys. Geosyst., 10(3), Q03002, doi: 10.1029/2008GC002250.
  17. Lam, S. K., Pitrou, A., and Seibert, S., 2015, Numba: A llvm-based python jit compiler, Proceedings of the Second Workshop on the LLVM Compiler Infrastructure in HPC, 1-6, doi: 10.1145/2833157.2833162.
  18. Leng, W., and Zhong, S., 2011, Implementation and application of adaptive mesh refinement for thermochemical mantle convection studies, Geochem. Geophys. Geosyst., 12(4), Q04006, doi: 10.1029/2010GC003425.
  19. Mansour et al., 2020, Underworld2: Python Geodynamics Modelling for Desktop, HPC and Cloud, Journal of Open Source Software, 5(47), 1797, doi: 10.21105/joss.01797.
  20. O'Boyle, N. M., Morley, C., and Hutchison, G. R., 2008, Pybel: a Python wrapper for the OpenBabel cheminformatics toolkit, Chem. Cent. J., 2(1), 1-7, doi: 10.1186/1752-153X-2-5.
  21. Oliphant, T. E., 2007, Python for scientific computing, Comput. Sci. Eng., 9(3), 10-20, doi: 10.1109/MCSE.2007.58.
  22. Omelchenko, Y. A., and Karimabadi, H., 2006, Self-adaptive time integration of flux-conservative equations with sources, J. Comput. Phys., 216(1), 179-194, doi: 10.1016/j.jcp.2005.12.008.
  23. O'Neill, C., Moresi, L., Muller, D., Albert, R., and Dufour, F., 2006, Ellipsis 3D: A particle-in-cell finite-element hybrid code for modelling mantle convection and lithospheric deformation, Comput. Geosci., 32(10), 1769-1779. https://doi.org/10.1016/j.cageo.2006.04.006
  24. Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R. and Dubourg, V., 2011, Scikit-learn: Machine learning in Python, J. Mach. Learn. Res., 12, 2825-2830.
  25. Samuel, H., and Evonuk, M., 2010, Modeling advection in geophysical flows with particle level sets, Geochem. Geophys. Geosyst., 11(8), Q08020, doi: 10.1029/2010GC003081.
  26. Samuel, H., 2018, A deformable particle-in-cell method for advective transport in geodynamic modelling, Geophys. J. Int., 214(3), 1744-1773, doi: 10.1093/gji/ggy231.
  27. Schenk, O., Gartner, K., Fichtner, W., and Stricker, A., 2001, PARDISO: a high-performance serial and parallel sparse linear solver in semiconductor device simulation, Futur. Gener. Comp. Syst., 18(1), 69-78, doi: 10.1016/S0167-739X(00)00076-5.
  28. Srinath, K. R., 2017, Python-the fastest growing programming language, International Research Journal of Engineering and Technology, 4(12), 354-357.
  29. Sun, Q., Berkelbach, T. C., Blunt, N. S., Booth, G. H., Guo, S., Li, Z., Liu, J., McClain, J. D., Sayfutyarova, E. R., Sharma, S., Wouters, S., and Chan, G. K., 2018, PySCF: the Python-based simulations of chemistry framework, Wiley Interdiscip. Rev.-Comput. Mol. Sci., 8, e1340, doi: 10.1002/wcms.1340.
  30. Tackley, P. J., and King, S. D., 2003, Testing the tracer ratio method for modeling active compositional fields in mantle convection simulations, Geochem. Geophys. Geosyst., 4(4), 8302, doi: 10.1029/2001GC000214.
  31. Thieulot, C., 2011, FANTOM: Two-and three-dimensional numerical modelling of creeping flows for the solution of geological problems, Phys. Earth Planet. Inter., 188(1-2), 47-68, doi: 10.1016/j.pepi.2011.06.011.
  32. Thieulot, C., 2014, ELEFANT: a user-friendly multipurpose geodynamics code. Solid Earth Discussions, 6(2), 1949-2096, doi: 10.5194/sed-6-1949-2014.
  33. Van Der Walt, S., Colbert, S. C., and Varoquaux, G., 2011, The NumPy array: a structure for efficient numerical computation, Comput. Sci. Eng., 13(2), 22-30, doi: 10.1109/MCSE.2011.37.
  34. Van Keken, P. E., King, S. D., Schmeling, H., Christensen, U. R., Neumeister, D., and Doin, M. P., 1997, A comparison of methods for the modeling of thermochemical convection, J. Geophys. Res.-Solid Earth, 102(B10), 22477-22495, doi: 10.1029/97JB01353.
  35. Virtanen, P., Gommers, R., Oliphant, T. E., Haberland, M., Reddy, T., Cournapeau, D., Burovski, E., Peterson, P., Weckesser, W., and Bright, J., 2020, SciPy 1.0: fundamental algorithms for scientific computing in Python, Nat. Methods, 17, 261-272. https://doi.org/10.1038/s41592-019-0686-2
  36. Wang, H., Agrusta, R., and van Hunen, J., 2015, Advantages of a conservative velocity interpolation (CVI) scheme for particle-in-cell methods with application in geodynamic modeling, Geochem. Geophys. Geosyst., 16, 2015-2023, doi: 10.1002/2015GC005824.
  37. Wilbers, I. M., Langtangen, H. P., and Odegard, A., 2009, Using cython to speed up numerical python programs, Fifth National Conference on Computational Mechanics, 9, 495-512.
  38. Yuen, D. A., and Peltier, W. R., 1982, Normal modes of the viscoelastic earth, Geophys. J. Int., 69(2), 495-526, doi: 10.1111/j.1365-246X.1982.tb04962.x.