diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index cf8c92d..0758e97 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -79,7 +79,10 @@ jobs: run: ${{github.workspace}}/build/main - name: Run example - run: ${{github.workspace}}/build/simple + run: ${{github.workspace}}/build/matrix_eigen + + - name: Run example + run: ${{github.workspace}}/build/loop_omp # - name: Test # working-directory: ${{ steps.strings.outputs.build-output-dir }} diff --git a/.gitignore b/.gitignore index a20d21e..3446d93 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,8 @@ debug # Compiled Static libraries *.a -*.lib \ No newline at end of file +*.lib + +# VIM Tampon file +*.swp +*.swo diff --git a/CMakeLists.txt b/CMakeLists.txt index b7d462c..578f557 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,25 +5,23 @@ set(CMAKE_CXX_STANDARD 14) # specifying the C++ Standard set(GCC_COVERAGE_COMPILE_FLAGS "-Wall -Wextra -pedantic") # probably not the best variable name set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}") -set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -funroll-loops -funroll-all-loops -DNDEBUG") +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "-g -fsanitize=address,undefined") -# include_directories(include) - -# OpenMP -find_package(OpenMP) -if(OpenMP_CXX_FOUND) - set(LINK_LIBS ${LINK_LIBS} ${OpenMP_CXX_LIBRARIES}) -endif() - # Eigen find_package(Eigen3 3.3 REQUIRED NO_MODULE) set(LINK_LIBS ${LINK_LIBS} Eigen3::Eigen) - # Executables add_executable(main examples/main.cpp) # create an executable using the specified file target_link_libraries(main PUBLIC ${LINK_LIBS}) -add_executable(simple examples/simple.cpp) # create an executable using the specified file -target_link_libraries(simple PUBLIC ${LINK_LIBS}) \ No newline at end of file +add_executable(matrix_eigen examples/matrix_eigen.cpp) # create an executable using the specified file +target_link_libraries(matrix_eigen PUBLIC ${LINK_LIBS}) + +find_package(OpenMP) +if(OPENMP_FOUND) + add_executable(loop_omp examples/loop_omp.cpp) # create an executable using the specified file + target_compile_options(loop_omp PUBLIC ${OpenMP_CXX_FLAGS}) + target_link_libraries(loop_omp PUBLIC ${LINK_LIBS} OpenMP::OpenMP_CXX) +endif() diff --git a/examples/loop_omp.cpp b/examples/loop_omp.cpp new file mode 100644 index 0000000..ffdf07f --- /dev/null +++ b/examples/loop_omp.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +int main() { + // Initialisation d'un grand tableau pour simuler une charge de travail + const int N = 1000000; + std::vector tab(N, 1); // Crée un tableau avec des valeurs de 1 + int sum = 0; + + // Mesurer le temps avant le calcul + double start_time = omp_get_wtime(); + + // Début de la région parallèle + #pragma omp parallel for reduction(+:sum) + for (int i = 0; i < N; ++i) { + sum += tab[i]; + } + + // Mesurer le temps après le calcul + double end_time = omp_get_wtime(); + + // Résultats + std::cout << "La somme est: " << sum << std::endl; + std::cout << "Temps d'exécution avec OpenMP: " << (end_time - start_time) << " secondes" << std::endl; + + return 0; +} + diff --git a/examples/simple.cpp b/examples/matrix_eigen.cpp similarity index 100% rename from examples/simple.cpp rename to examples/matrix_eigen.cpp