Fortran2CPP: Automating Fortran-to-C++ Translation using LLMs via Multi-Turn Dialogue and Dual-Agent Integration

Le Chen, Bin Lei, Dunzhi Zhou, Pei-Hung Lin, Chunhua Liao +2 more
12/27/2024
8 citations
cs.LG

Official code: HPC-Fortran2CPP/Fortran2Cpp (18 stars, C++, Apache-2.0, last commit 2025-03-28).

Abstract

Translating legacy Fortran code into C++ is a crucial step in modernizing high-performance computing (HPC) applications. However, the scarcity of high-quality, parallel Fortran-to-C++ datasets and the limited domain-specific expertise in large language models (LLMs) present significant challenges for automated translation.

Show full abstract

In this paper, we introduce Fortran2CPP, a multi-turn dialogue dataset generated by a novel LLM agent-based approach that integrates a dual-LLM Questioner-Solver module to enhance translation accuracy. Our dataset comprises 11.7k dialogues capturing iterative feedback-decision workflows including code translation, compilation, execution, unit testing, and error-fixing. Using this dataset, we fine-tune several open-weight LLMs and achieve up to a 3.31x improvement in CodeBLEU scores and a 92\% increase in compilation success rate, demonstrating enhanced syntactic accuracy and functional reliability. Our findings highlight the value of dialogue-based LLM training for complex code translation tasks. The dataset and model have been open-sourced and are available on our public GitHub repository\footnote{\url{https://github.com/HPC-Fortran2CPP/Fortran2Cpp}}.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Fortran2Cpp: A new model designed for the Code translation between the Fortran and C++

186C++, FortranApr 5, 20241 years agoApache-2.0
cppfortranllmtranspiler

Similar Papers

Cite this paper

@article{chen2024fortrancpp,
  title  = {Fortran2CPP: Automating Fortran-to-C++ Translation using LLMs via Multi-Turn Dialogue and Dual-Agent Integration},
  author = {Le Chen and Bin Lei and Dunzhi Zhou and Pei-Hung Lin and Chunhua Liao and Caiwen Ding and Ali Jannesari},
  year   = {2024},
  eprint = {2412.19770},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2412.19770v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2412.19770.svg)](https://codeofpaper.com/paper/2412.19770)

Discussion