how to use openmp in a c++ program

前端 未结 1 776
无人共我
无人共我 2021-01-16 23:47

I would like to use OpenMP to parallelize some of my functions in a c++ program.

I am using ubuntu 12.04, on intel i5 with 4 cores. But after following certain step

相关标签:
1条回答
  • 2021-01-17 00:24

    As mentioned by @Mikael Persson , I removed -fopenmp from the target link libraries and added find_package(OpenMP) if (OPENMP_FOUND) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") endif()

    This is working.

    The error r *** double free or corruption (!prev): 0x00007ff424006b20 *** was arising because in the for loop, i was trying to use push_back() function to load a stack and the index was dependant on the for loop index. I think that was the cause of the problem.

    I learnt one more thing that one can have nested for loops and OMP can work without errors if their variables are independent and produce valid results

    0 讨论(0)
提交回复
热议问题