Rate This Document
Findability
Accuracy
Completeness
Readability

kupl_sgraph_add_dep

Add a dependency for two nodes within the KUPL static graph to describe the task execution sequence.

Interface Definition

int kupl_sgraph_add_dep(kupl_sgraph_node_h precede, kupl_sgraph_node_h succeed);

Parameters

Table 1 Parameter definitions

Parameter

Type

Description

Input/Output

precede

kupl_sgraph_node_h

Predecessor node in the dependency relationship.

Input

succeed

kupl_sgraph_node_h

Successor node in the dependency relationship.

Input

Return Value

Success: KUPL_OK

Failure: KUPL_ERROR

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
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h> 
#include "kupl.h" 

void func1(void *args)
{
    printf("gnode1 task finished\n");
}

void func2(void *args)
{
    printf("gnode2 task finished\n");
}

int main() 
{ 
    kupl_graph_h graph = kupl_graph_create(nullptr);

    kupl_sgraph_h sgraph = kupl_sgraph_create();
    kupl_sgraph_node_desc_t node1_desc = {
        .func = func1,
        .args = NULL,
    };
    kupl_sgraph_node_h node1 = kupl_sgraph_add_node(sgraph, &node1_desc);
    kupl_sgraph_node_desc_t node2_desc = {
        .func = func2,
        .args = NULL,
    };
    kupl_sgraph_node_h node2 = kupl_sgraph_add_node(sgraph, &node2_desc);
    kupl_sgraph_add_dep(node1, node2);

    kupl_sgraph_task_desc_t subgraph_task_desc = {
        .sgraph = sgraph,
    };
    kupl_task_info_t info = {
        .type = KUPL_TASK_TYPE_SGRAPH,
        .desc = &subgraph_task_desc,
    };
    kupl_graph_submit(graph, &info);

    kupl_graph_wait(graph);
    kupl_graph_destroy(graph);
    kupl_sgraph_destroy(sgraph);
    return 0;         
}

The execution result is as follows:

gnode1 task finished
gnode2 task finished

The preceding example demonstrates how to add node1 and node2 to a static graph, create a dependency for node1 and node2, and submit the static graph for execution. The kupl_sgraph_add_dep function creates a dependency from node1 to node2, designating node1 as the predecessor and node2 as the successor. The execution results verify this function: the task for node1 completes execution first, followed by the task for node2.