使用OpenMP在没有障碍的情况下并行化不同端口中的功能

时间:2019-02-21 17:13:12

标签: c++ multithreading parallel-processing port openmp

我想并行运行一个函数96次。该功能在指定端口上运行机器人模拟器服务器。

在此程序中,我运行24个线程4次。但是,有一个障碍,程序必须等待24个线程完成才能继续。

知道线程具有不同的执行时间。如果花费大量时间,则会减慢执行时间。

是否还有其他方法可以使所有96个线程(或机械手服务器)一次执行,并考虑端口的动态响应性?

int id=0;

for(int i=0; i<4; i++)
{
    #pragma omp parallel 
    {
        #pragma omp sections
        {
            #pragma omp section 
            {
                function(id, 11369);// id of the robot, port
            }
            #pragma omp section
            {
                function(id+1, 11370);
            }
            //...
            //...
            //...
            #pragma omp section
            {
                function(id+23, 11393);
            }
        }
        #pragma omp barrier
        #pragma omp single
        {
            id=id+24;
        }
    }
}

0 个答案:

没有答案
相关问题