Pthreads vs. OpenMP

后端 未结 4 779
攒了一身酷
攒了一身酷 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:52

    OpenMP has the advantages of being cross platform, and simpler for some operations. It handles threading in a different manner, in that it gives you higher level threading options, such as parallelization of loops, such as:

    #pragma omp parallel for
    for (i = 0; i < 500; i++)
        arr[i] = 2 * i;
    

    If this interests you, and if C++ is an option, I'd also recommend Threading Building Blocks.

    Pthreads is a lower level API for generating threads and synchronization explicitly. In that respect, it provides more control.

提交回复
热议问题