一种CMA数值预报模式代码质量检测方法与实现

A Quality Detection Method and Its Implementation for CMA Numerical Prediction Model Code

  • 摘要: 中国气象局(CMA)数值预报的统筹研发对支撑平台的能力建设提出了更高要求, 其中一个重要方面就是对数值预报模式代码的质量检测能力。目前缺乏有效针对数值预报模式代码的质量检测方法和工具, 尤其对于性能缺陷和大规模代码的检测不能满足需要。为解决上述问题, 该文针对子程序定义、数组操作和I/O操作等常见编程规则设计检测方法。该方法采用程序代码解析、抽象语法树匹配和流敏感的静态程序检测等关键技术, 其中对分支和循环语句的分析方法有效避免了路径爆炸问题。基于该方法的检测工具在数值预报科创平台V1.0代码协同开发栏目提供使用, 并应用于CMA区域数值模式的国省统筹研发。

     

    Abstract: The coordinated research and development of numerical prediction at the national and provincial levels, conducted by CMA is an innovative shift from CMA Earth System Modeling and Prediction Center to a collaborative approach involving multiple stakeholders. However, diverse technical backgrounds and varying programming proficiency levels of participants present a significant challenge in ensuring the code quality of the numerical prediction model. It is required that the research and development support platform should possess code quality detection capabilities, providing tools to promptly identify and analyze the code submitted by developers, and offering feedback to enhance the software quality and work efficiency.Static detection methods can address challenges associated with reproducing runtime errors in numerical model programs. Additionally, they facilitate the analysis of specific critical code segments, thereby improving detection efficiency. Therefore, it focuses on static detection methods and primarily aims at identifying poor programming practices and performance defects in CMA numerical prediction model codes. There are limited research efforts focused on the quality analysis of numerical prediction model codes, particularly concerning performance defects such as memory access issues and I/O operations. Additionally, the substantial volume of numerical prediction model code places greater demands on the accuracy and performance of detection methods.In response to these issues, a quality detection method for CMA numerical prediction model is proposed and implemented. The method emphasizes 8 standard rules in CMA numerical prediction model coding, which encompass subroutine definitions, array operations, and I/O operations. Finite state machines are utilized to abstractly represent these rules. Key technologies, including program code parsing, abstract syntax tree matching, and flow-sensitive static program analysis, are employed to identify violations of these rules. The approach to managing branch and loop statements can effectively mitigate the problem of path explosion. Based on it, the detection tool is implemented, and its system framework, along with the key technologies, is introduced.The tool is deployed on CMA numerical prediction innovation platform and has been successfully applied to the coordinated development of regional numerical models. The performance, result analysis, and code improvement suggestions for quality inspection tool of CMA-MESO V5.1 are presented in the experimental section. Experimental results demonstrate that the method satisfies performance requirements for code quality detection and holds practical significance for enhancing the quality of model code.

     

/

返回文章
返回