arXiv:2506.22703cs.SEcs.AI2025-06被引 2

用检索增强生成技术,让大模型更准确地为串行代码加OpenMP并行指令。

P4OMP: Retrieval-Augmented Prompting for OpenMP Parallelism in Serial Code

  • 通过检索教程知识增强提示,提升代码生成的语法正确性。
  • 在108个真实程序中编译成功率100%,基线有20个失败。
  • 适合需要高效并行化串行代码的开发者和高性能计算场景。

我们提出P4OMP,一种基于检索增强生成(RAG)的框架,利用大语言模型(LLM)将串行C/C++代码自动转换为带OpenMP注释的并行代码。据我们所知,这是首个在不进行模型微调或编译器插桩的情况下,应用检索式提示实现OpenMP指令正确性的系统。P4OMP结合来自OpenMP教程的结构化指导知识,通过检索上下文来约束生成过程,显著提升了提示驱动代码生成的可靠性。在包含108个真实世界C++程序(来自Stack Overflow、PolyBench和NAS基准套件)的综合评测中,P4OMP在所有可并行化案例中均实现100%编译成功,而基线方法(GPT-3.5-Turbo无检索)有20个无法编译。其中6个因使用非随机访问迭代器或线程不安全结构被排除,属OpenMP固有限制。详细分析显示,P4OMP能一致避免作用域错误、语法误用及无效指令组合等常见问题。进一步在七项计算密集型基准上验证了其良好的运行时可扩展性。P4OMP提供了一个鲁棒、模块化的流水线,显著提升了LLM生成OpenMP代码的可靠性与实用性。

原文摘要 · Abstract (English)

We present P4OMP, a retrieval-augmented framework for transforming serial C/C++ code into OpenMP-annotated parallel code using large language models (LLMs). To our knowledge, this is the first system to apply retrieval-based prompting for OpenMP pragma correctness without model fine-tuning or compiler instrumentation. P4OMP leverages Retrieval-Augmented Generation (RAG) with structured instructional knowledge from OpenMP tutorials to improve the reliability of prompt-driven code generation. By grounding generation in the retrieved context, P4OMP improves syntactic correctness compared to baseline prompting with GPT-3.5-Turbo. We evaluate P4OMP against a baseline, GPT-3.5-Turbo without retrieval, on a comprehensive benchmark of 108 real-world C++ programs drawn from Stack Overflow, PolyBench, and NAS benchmark suites. P4OMP achieves 100% compilation success on all parallelizable cases, while the baseline fails to compile in 20 out of 108 cases. Six cases that rely on non-random-access iterators or thread-unsafe constructs are excluded due to fundamental OpenMP limitations. A detailed analysis demonstrates how P4OMP consistently avoids scoping errors, syntactic misuse, and invalid directive combinations that commonly affect baseline-generated code. We further demonstrate strong runtime scaling across seven compute-intensive benchmarks on an HPC cluster. P4OMP offers a robust, modular pipeline that significantly improves the reliability and applicability of LLM-generated OpenMP code.

代码生成并行计算LLM应用OpenMP

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。