Pthreads vs. OpenMP

后端 未结 4 776
攒了一身酷
攒了一身酷 2020-12-07 12:26

I\'m creating a multi-threaded application in C using Linux.

I\'m unsure whether I should use the POSIX thread API or the OpenMP API.

What are the pros &

4条回答
  •  离开以前
    2020-12-07 12:38

    If you use OpenMP, it can be as simple as adding a single pragma, and you'll be 90% of the way to properly multithreaded code with linear speedup. To get the same performance boost with pthreads takes a lot more work.

    But as usual, you get more flexibility with pthreads.

    Basically, it depends on what your application is. Do you have a trivially-parallelisable algorithm? Or do you just have lots of arbitrary tasks that you'd like to simultaneously? How much do the tasks need to talk to each other? How much synchronisation is required?

提交回复
热议问题