Skip to content

Commit 8b18de3

Browse files
Added basic openMP skeleton to ir2vec
1 parent 3c10194 commit 8b18de3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ if(NOT LLVM_IR2VEC)
2424
# llvm_map_components_to_libnames(llvm_libs all)
2525
llvm_map_components_to_libnames(llvm_libs support core irreader analysis TransformUtils)
2626

27+
# Check if OpenMP is supported by the compiler
28+
find_package(OpenMP REQUIRED)
29+
2730
add_executable(${PROJECT_NAME} ${binsrc})
28-
target_link_libraries (${PROJECT_NAME} ${llvm_libs} objlib)
31+
target_link_libraries (${PROJECT_NAME} ${llvm_libs} objlib OpenMP::OpenMP_CXX)
2932
target_include_directories(${PROJECT_NAME} PRIVATE .)
3033

3134
add_library(objlib OBJECT ${libsrc})
@@ -48,6 +51,9 @@ if(NOT LLVM_IR2VEC)
4851
PUBLIC_HEADER DESTINATION include
4952
RESOURCE DESTINATION ./)
5053

54+
# Add compiler flags for OpenMP
55+
target_compile_options(${PROJECT_NAME} PRIVATE ${OpenMP_CXX_FLAGS})
56+
5157
add_subdirectory(test-suite)
5258

5359
add_custom_target(check

src/IR2Vec.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "llvm/Support/CommandLine.h"
1313
#include <stdio.h>
1414
#include <time.h>
15+
#include <omp.h>
1516

1617
using namespace llvm;
1718
using namespace IR2Vec;
@@ -69,6 +70,20 @@ void printVersion(raw_ostream &ostream) {
6970
}
7071

7172
int main(int argc, char **argv) {
73+
int N = 100;
74+
float a[N], b[N], result[N];
75+
76+
// Initialize arrays a and b with some values
77+
#pragma omp parallel for
78+
for (int i = 0; i < N; ++i) {
79+
a[i] = i;
80+
b[i] = i * 2;
81+
}
82+
#pragma omp parallel for
83+
for (int i = 0; i < N; ++i) {
84+
result[i] = a[i] + b[i];
85+
}
86+
7287
cl::SetVersionPrinter(printVersion);
7388
cl::HideUnrelatedOptions(category);
7489
cl::ParseCommandLineOptions(argc, argv);

0 commit comments

Comments
 (0)