What's the difference between “static” and “dynamic” schedule in OpenMP?

后端 未结 3 1698
既然无缘
既然无缘 2020-11-27 11:21

I started working with OpenMP using C++.

I have two questions:

  1. What is #pragma omp for schedule?
  2. What is the difference between
3条回答
  •  清歌不尽
    2020-11-27 12:12

    I think the misunderstanding comes from the fact that you miss the point about OpenMP. In a sentence OpenMP allows you to execute you program faster by enabling parallelism. In a program parallelism can be enabled in many ways and one of the is by using threads. Suppose you have and array:

    [1,2,3,4,5,6,7,8,9,10]
    

    and you want to increment all elements by 1 in this array.

    If you are going to use

    #pragma omp for schedule(static, 5)
    

    it means that to each of the threads will be assigned 5 contiguous iterations. In this case the first thread will take 5 numbers. The second one will take another 5 and so on until there are no more data to process or the maximum number of threads is reached (typically equal to the number of cores). Sharing of workload is done during the compilation.

    In case of

    #pragma omp for schedule(dynamic, 5)
    

    The work will be shared amongst threads but this procedure will occur at a runtime. Thus involving more overhead. Second parameter specifies size of the chunk of the data.

    Not being very familiar to OpenMP I risk to assume that dynamic type is more appropriate when compiled code is going to run on the system that has a different configuration that the one on which code was compiled.

    I would recommend the page bellow where there are discussed techniques used for parallelizing the code, preconditions and limitations

    https://computing.llnl.gov/tutorials/parallel_comp/

    Additional links:
    http://en.wikipedia.org/wiki/OpenMP
    Difference between static and dynamic schedule in openMP in C
    http://openmp.blogspot.se/

提交回复
热议问题