Skip to content

Commit

Permalink
Added basic openMP skeleton to ir2vec
Browse files Browse the repository at this point in the history
  • Loading branch information
nishant-sachdeva committed May 20, 2024
1 parent 3c10194 commit 56f1b64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ if(NOT LLVM_IR2VEC)
# llvm_map_components_to_libnames(llvm_libs all)
llvm_map_components_to_libnames(llvm_libs support core irreader analysis TransformUtils)

# Check if OpenMP is supported by the compiler
find_package(OpenMP REQUIRED)

add_executable(${PROJECT_NAME} ${binsrc})
target_link_libraries (${PROJECT_NAME} ${llvm_libs} objlib)
target_link_libraries (${PROJECT_NAME} ${llvm_libs} objlib OpenMP::OpenMP_CXX)
target_include_directories(${PROJECT_NAME} PRIVATE .)

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

# Add compiler flags for OpenMP
target_compile_options(${PROJECT_NAME} PRIVATE ${OpenMP_CXX_FLAGS})

add_subdirectory(test-suite)

add_custom_target(check
Expand Down
15 changes: 15 additions & 0 deletions src/IR2Vec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Symbolic.h"
#include "version.h"
#include "llvm/Support/CommandLine.h"
#include <omp.h>
#include <stdio.h>
#include <time.h>

Expand Down Expand Up @@ -69,6 +70,20 @@ void printVersion(raw_ostream &ostream) {
}

int main(int argc, char **argv) {
int N = 100;
float a[N], b[N], result[N];

// Initialize arrays a and b with some values
#pragma omp parallel for
for (int i = 0; i < N; ++i) {
a[i] = i;
b[i] = i + 2;
}
#pragma omp parallel for
for (int i = 0; i < N; ++i) {
result[i] = a[i] + b[i];
}

cl::SetVersionPrinter(printVersion);
cl::HideUnrelatedOptions(category);
cl::ParseCommandLineOptions(argc, argv);
Expand Down

0 comments on commit 56f1b64

Please sign in to comment.