---
title: kpccl_egroup_barrier
description: "同步egroup中所有executor都到达该位置后，executor行为才继续执行。"
url: https://www.hikunpeng.com/document/detail/zh/hpchistory/hpckit/develop2400/KunoengHPCKit_developer_026.html
sourcePath: /source/zh/hpchistory/hpckit/develop2400/KunoengHPCKit_developer_026.html
indexId: 3aa8a0704fc125e995c299d9ced5a06ee4c86855d67892035639dd6c5031129173
---
# kpccl_egroup_barrier

同步egroup中所有executor都到达该位置后，executor行为才继续执行。

#### 接口定义

void kpccl_egroup_barrier(kpccl_egroup_h group);


#### 参数


**表1 参数定义**

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| group | kpccl\_egroup\_h | 执行barrier操作的egroup对象 | 输入 |


#### 示例


```
#include <stdio.h>
#include <omp.h>
#include "kpccl.h"
int main()
{
int executor_num = kpccl_get_num_executors();
int executors[executor_num];
for (int i =0; i < executor_num; i++) {
executors[i] = i;
}
kpccl_egroup_h egroup = kpccl_egroup_create(executors, executor_num);
#pragma omp parallel num_threads(executor_num)
{
int tid = omp_get_thread_num();
printf("before barrier: tid %d \n", tid);
kpccl_egroup_barrier
(egroup);
printf("after barrier: tid %d \n", tid);
}
kpccl_egroup_destroy(egroup);
return 0;
}
```


运行结果如下。

```
before barrier: tid 2
before barrier: tid 0
before barrier: tid 1
before barrier: tid 3
after barrier: tid 1
after barrier: tid 0
after barrier: tid 2
after barrier: tid 3
```

上述示例演示了在omp并行区域中kpccl_egroup_barrier函数的作用。根据运行结果，所有线程的before barrier打印完毕后，所有线程的after barrier才开始打印。由此，kpccl_egroup_barrier函数此处的作用是同步egroup中所有executor都到达执行完毕before barrier的打印后，代码才继续执行。
