计算机应用 ›› 2016, Vol. 36 ›› Issue (9): 2422-2426.DOI: 10.11772/j.issn.1001-9081.2016.09.2422

• 先进计算 • 上一篇    下一篇

基于JavaCC的C代码自动并行化的设计与实现

刘有耀, 杨鹏程   

  1. 西安邮电大学 电子工程学院, 西安 710121
  • 收稿日期:2016-04-25 修回日期:2016-06-21 出版日期:2016-09-10 发布日期:2016-09-08
  • 通讯作者: 杨鹏程
  • 作者简介:刘有耀(1975-),男,陕西佳县人,副教授,博士,主要研究方向:嵌入式系统、片上网络、SoC设计与验证;杨鹏程(1992-),男,山西沁水人,硕士研究生,主要研究方向:片上系统设计与验证。
  • 基金资助:
    国家自然科学基金资助项目(61136002,61272120)。

Design and implementation of automatic C code parallelization based on JavaCC

LIU Youyao, YANG Pengcheng   

  1. Electronic Engineering school, Xi'an University of Posts and Telecommunications, Xi'an Shaanxi 710121, China
  • Received:2016-04-25 Revised:2016-06-21 Online:2016-09-10 Published:2016-09-08
  • Supported by:
    This work is partially supported by the National Natural Science Foundation of China (61136002, 61272120).

摘要: 针对当前大量遗产代码无法重复利用的问题,设计一种新的编译工具将C的串行代码转换为基于MPI+OpenMP的混合并行编程代码,降低了并行编程的开发成本。首先,通过对JavaCC的优化,实现一种可以解析C语言的词法和语法分析器,进行源代码分析并生成抽象语法树;其次,根据语法树对源代码进行控制依赖性和数据依赖性分析,产生可并行化的语句块分区;再次,按照提出的并行代码生成方法得到目标代码;最后,基于Visual Studio 2010构建目标代码仿真验证环境。实验结果表明,该工具可以较为理想地实现串行代码自动并行化,与手工编写的代码在加速比上的误差为8.2%~18.4%。

关键词: JavaCC, 抽象语法树, 依赖性, 自动并行化, MPI+OpenMP

Abstract: Aiming at the problem that a large amount of legacy code can not be reused, a new compilation tool was designed to convert the serial code of C into a hybrid parallel programming code based on MPI+OpenMP, which can reduce the development cost of parallel programming. First of all, by optimizing Java Compiler Compiler (JavaCC), a lexical and syntax analyzer which can parse the C language was implemented, then the source code analysis was conducted and the abstract syntax tree was generated. Secondly, according to the abstract syntax tree, the control dependence and data dependence of the source code were analyzed to produce the parallelizable statement block partitions. Thirdly, the object code was obtained according to the proposed parallel code generation method. Finally, the target code simulation environment was built based on Visual Studio 2010. The experimental results show that the tool can effectively achieve automatic parallelization of the serial code, and compared with the code written by hand, its speedup of the error is between 8.2% to 18.4%.

Key words: Java Compiler Compiler (JavaCC), abtract syntax tree, dependency, automatic parallelization, MPI+OpenMP

中图分类号: