Rate This Document
Findability
Accuracy
Completeness
Readability

kupl_egroup_join_barrier

This interface provides a partial synchronization logic rather than a global mandatory barrier.

Specifically, calling this interface does not block sub-threads, which continue execution immediately. However, the main thread enters a blocked state and only resumes once sub-threads reach the barrier.

Interface Definition

void kupl_egroup_join_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 join 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
#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_join_barrier(nullptr);
    kupl_egroup_fork_barrier(nullptr);
    printf("after barrier: tid %d \n", tid);
}

int main()
{
    const int num_threads = kupl_get_num_executors();
    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 = nullptr,
        .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_join_barrier function within a parallel 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 function kupl_egroup_join_barrier is to unblock the main executor only after the sub-thread executors arrive at the barrier; when combined with the kupl_egroup_fork_barrier function, it achieves synchronization for all executors within the egroup.