Automatic Identification of Parallelizable Loops Using Transformer-Based Source Code Representations
Authors: Izavan dos S. Correia, Henrique C. T. Santos, Tiago A. E. Ferreira
Organizations: Graduate Program in Applied Informatics (PPGIA), Federal Rural University of Pernambuco (UFRPE), Recife, Pernambuco, Brazil. · Undergraduate Program in Analysis and Systems Development (TADS), Federal Institute of Pernambuco (IFPE), Recife, Pernambuco, Brazil.
Automatic parallelization remains a challenging problem in software engineering, particularly in identifying code regions where loops can be safely executed in parallel on modern multi-core architectures. Traditional static analysis techniques, such as dependence analysis and polyhedral models, often struggle with irregular or dynamically structured code. In this work, we propose a Transformer-based approach to classify the parallelization potential of source code, focusing on distinguishing independent (parallelizable) loops from undefined ones. We adopt DistilBERT to process source code sequences using subword tokenization, enabling the model to capture contextual syntactic and semantic patterns without handcrafted features. The approach is evaluated on a balanced dataset combining synthetically generated loops and manually annotated real-world code, using 10-fold cross-validation and multiple performance metrics. Results show consistently high performance, with mean accuracy above 99% and low false positive rates, demonstrating robustness and reliability. Compared to prior token-based methods, the proposed approach simplifies preprocessing while improving generalization and maintaining computational efficiency. These findings highlight the potential of lightweight Transformer models for practical identification of parallelization opportunities at the loop level.
Figures & tables
Figure 1: Workflow of the proposed methodology.
Figure 2: Boxplot of training, validation, and test accuracies for the 10 cross-validation folds.
Figure 3: Histograms of training, validation, and test accuracies for the 10 folds.
Set
Mean
Std. Dev.
Median
95% CI
Training
0.99965
0.00030
0.99983
0.99944–0.99986
Validation
0.99753
0.00109
0.99784
0.99675–0.99831
Test
0.99600
0.00261
0.99650
0.99413–0.99787
Table 1: Statistical metrics for training, validation, and test accuracies across the 10 cross-validation folds.
Figure 4: Boxplots of precision, recall, and F1-Score metrics across the 10 cross-validation folds.
Figure 5: Histograms of precision, recall, and F1-Score metrics across the 10 cross-validation folds.
Metric
Mean
Std. Dev.
Median
95% CI
Precision
0.9971
0.0026
0.9976
0.9953–0.9989
Recall
0.9949
0.0038
0.9952
0.9922–0.9976
F1-Score
0.9960
0.0026
0.9970
0.9941–0.9979
Table 2: Statistical metrics for Precision, Recall, and F1-Score on the test set.
Figure 6: Boxplot of the validation error (Binary Cross-Entropy) for the 10 folds.
Figure 7: Histogram of the validation error (Binary Cross-Entropy) for the 10 folds.
Metric
Mean
Std. Dev.
Median
95% CI
Validation Error
0.01772
0.00965
0.01512
0.01081–0.02462
Table 3: Statistical metrics of the validation error (Binary Cross-Entropy).
Figure 8: Boxplot of the False Positive Rate (FPR) across the 10-fold cross-validation.
Figure 9: Histogram of the False Positive Rate (FPR) across the 10-fold cross-validation.
Metric
Mean
Std. Dev.
Median
95% CI
FPR
0.002872
0.002439
0.002418
0.001197–0.004546
Table 4: Statistical metrics for the False Positive Rate (FPR) across the 10-fold cross-validation.
Figure 10: Training and validation loss and accuracy curves for Fold 7.
Actual / Predicted
Undefined
Independent
Undefined
414
1
Independent
2
417
Table 5: Confusion matrix for Fold 7.
Metric
Precision
Recall
F1-score
Independent Class
0.9976
0.9952
0.9964
Table 6: Classification report for Fold 7.
Figure 11: Training and validation loss and accuracy curves for Fold 8.
Actual / Predicted
Undefined
Independent
Undefined
419
0
Independent
1
414
Table 7: Confusion matrix for Fold 8.
Metric
Precision
Recall
F1-score
Independent Class
1.0000
0.9976
0.9988
Table 8: Classification report for Fold 8.
Figure 12: Training and validation loss and accuracy curves for Fold 2 (worst critical error).
Actual / Predicted
Undefined
Independent
Undefined
432
3
Independent
5
394
Table 9: Confusion matrix for Fold 2 (worst critical error).
Metric
Precision
Recall
F1-score
Independent
0.9924
0.9875
0.9899
Undefined
0.9886
0.9931
0.9908
Table 10: Classification report for Fold 2 (worst critical error).