Rate This Document
Findability
Accuracy
Completeness
Readability

kupl_egroup_barrier

Block executor execution until all executors within the egroup have reached the barrier, after which the executors resume execution.

Interface Definition

void kupl_egroup_barrier(kupl_egroup_h group);

Parameters

Table 1 Parameter definition

Parameter

Type

Description

Input/Output

group

kupl_egroup_h

An egroup object for which the barrier operation is performed.

Input

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include "kupl.h"

static inline void task_int_loop(kupl_nd_range_t *nd_range, void *args, int tid, int tnum)
{
    printf("before barrier: tid %d \n", tid);
    kupl_egroup_barrier(nullptr);
    printf("after barrier: tid %d \n", tid);
}

int main()
{
    const int num_threads = kupl_get_num_executors();
    kupl_nd_range_t range;
    int lower = 0, upper = num_threads;
    KUPL_1D_RANGE_INIT(range, 0, num_threads);
    int executors[num_threads];
    for (int i = 0; i < num_threads; i++) {
        executors[i] = i;
    }
    kupl_egroup_h eg = kupl_egroup_create(executors, num_threads);
    kupl_parallel_for_desc_t desc = {
        .field_mask = KUPL_PARALLEL_FOR_DESC_FIELD_DEFAULT,
        .range = &range,
        .egroup = eg,
        .concurrency = num_threads,
        .policy = KUPL_LOOP_POLICY_STATIC
    };
    kupl_parallel_for(&desc, task_int_loop, nullptr);
    kupl_egroup_destroy(eg);
    return 0;
}

The execution result is as follows:

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

The preceding example demonstrates the behavior of the kupl_egroup_barrier function within an omp region. According to the execution result, the "after barrier" messages of all threads start to be printed only after the "before barrier" messages of all threads have been printed. Therefore, the purpose of the kupl_egroup_barrier function is to synchronize all executors within the egroup, ensuring that the code proceeds only after every executor has completed printing its "before barrier" statement.