GCC Code Coverage Report


Directory: ./
File: tests/unit/01_pm/omptm_omp5_00.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 82 82 100.0%
Functions: 2 2 100.0%
Branches: 30 60 50.0%

Line Branch Exec Source
1 /*********************************************************************************/
2 /* Copyright 2009-2024 Barcelona Supercomputing Center */
3 /* */
4 /* This file is part of the DLB library. */
5 /* */
6 /* DLB is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU Lesser General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* DLB is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU Lesser General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU Lesser General Public License */
17 /* along with DLB. If not, see <https://www.gnu.org/licenses/>. */
18 /*********************************************************************************/
19
20 #include "unique_shmem.h"
21
22 #include "LB_numThreads/omptm_omp5.h"
23 #include "LB_numThreads/numThreads.h"
24 #include "LB_numThreads/omptool.h"
25 #include "LB_core/spd.h"
26 #include "apis/dlb_errors.h"
27 #include "apis/dlb_sp.h"
28 #include "support/mask_utils.h"
29
30 #include <assert.h>
31 #include <sched.h>
32 #include <string.h>
33
34 /* array_cpuid_t */
35 #define ARRAY_T cpuid_t
36 #include "support/array_template.h"
37
38 // This test needs at least room for 8 CPUs
39 enum { SYS_SIZE = 8 };
40
41 static int num_omp_threads = 0;
42
43 6 void omp_set_num_threads(int num_threads) {
44 6 num_omp_threads = num_threads;
45 6 }
46
47 1 int main (int argc, char *argv[]) {
48
49 /* Simulate a 4 core system with 2 CPUs per core with its bindings in a
50 * round-robin fashion */
51 enum { NUM_CORES = 4 };
52 enum { NUM_NODES = 1 };
53 cpu_set_t system_mask;
54 cpu_set_t node_masks[NUM_NODES];
55 cpu_set_t core_masks[NUM_CORES];
56 1 mu_parse_mask("0-7", &system_mask);
57 1 mu_parse_mask("0-7", &node_masks[0]);
58 1 mu_parse_mask("0,4", &core_masks[0]);
59 1 mu_parse_mask("1,5", &core_masks[1]);
60 1 mu_parse_mask("2,6", &core_masks[2]);
61 1 mu_parse_mask("3,7", &core_masks[3]);
62 1 mu_testing_set_sys_masks(&system_mask, core_masks, NUM_CORES, node_masks, NUM_NODES);
63
64 1 char options[64] = "--lewi --shm-key=";
65 1 strcat(options, SHMEM_KEY);
66
67 /* P1 init */
68 cpu_set_t p1_mask;
69 1 mu_parse_mask("0,1,4,5", &p1_mask);
70 1 subprocess_descriptor_t *spd1 = DLB_Init_sp(0, &p1_mask, options);
71
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( spd1 != NULL );
72 1 pid_t p1_pid = spd1->id;
73
74 /* P2 init */
75 cpu_set_t p2_mask;
76 1 mu_parse_mask("2,3,6,7", &p2_mask);
77 1 subprocess_descriptor_t *spd2 = DLB_Init_sp(0, &p2_mask, options);
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( spd2 != NULL );
79
80 /* P1 is the active subprocess */
81 1 spd_enter_dlb(spd1);
82
83 /* P1 inits omp5 thread manager with OMP_PLACES="threads" */
84 {
85 1 setenv("OMP_PLACES", "threads", 1);
86 1 omptm_omp5__init(p1_pid, &spd1->options);
87 1 omptm_omp5_testing__set_num_threads_fn(omp_set_num_threads);
88
89 1 const array_cpuid_t *cpu_bindings = omptm_omp5_testing__compute_and_get_cpu_bindings();
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->count == 4 );
91
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[0] == 0);
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[1] == 4);
93
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[2] == 1);
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[3] == 5);
95
96 /* P1 gets P2's CPUs */
97 1 enable_cpu_set(&spd1->pm, &p2_mask);
98
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( num_omp_threads == 8 );
99
100 1 cpu_bindings = omptm_omp5_testing__compute_and_get_cpu_bindings();
101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->count == 8 );
102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[0] == 0);
103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[1] == 4);
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[2] == 1);
105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[3] == 5);
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[4] == 2);
107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[5] == 6);
108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[6] == 3);
109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[7] == 7);
110
111 /* P1 reset */
112 1 disable_cpu_set(&spd1->pm, &p2_mask);
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( num_omp_threads == 4 );
114
115 1 omptm_omp5__finalize();
116 }
117
118 /* P1 inits omp5 thread manager with OMP_PLACES="cores" */
119 {
120 1 setenv("OMP_PLACES", "cores", 1);
121 1 omptm_omp5__init(p1_pid, &spd1->options);
122 1 omptm_omp5_testing__set_num_threads_fn(omp_set_num_threads);
123
124 1 const array_cpuid_t *cpu_bindings = omptm_omp5_testing__compute_and_get_cpu_bindings();
125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->count == 2 );
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[0] == 0);
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[1] == 1);
128
129 /* P1 gets 1 core */
130 cpu_set_t mask;
131 1 mu_parse_mask("3,7", &mask);
132 1 enable_cpu_set(&spd1->pm, &mask);
133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( num_omp_threads == 3 );
134
135 1 cpu_bindings = omptm_omp5_testing__compute_and_get_cpu_bindings();
136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->count == 3 );
137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[0] == 0);
138
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[1] == 1);
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( cpu_bindings->items[2] == 3);
140
141 1 omptm_omp5__finalize();
142 }
143
144 /* Finalize */
145
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( DLB_Finalize_sp(spd1) == DLB_SUCCESS );
146
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( DLB_Finalize_sp(spd2) == DLB_SUCCESS );
147
148 /* Test --ompt-thread-manager=omp5 without --lewi/--drom */
149 {
150 1 spd1 = DLB_Init_sp(0, &p1_mask, options);
151 1 spd1->options.lewi = false;
152 1 omptm_omp5__init(spd1->id, &spd1->options);
153 1 omptool_parallel_data_t parallel_data = {.level = 1};
154 1 omptm_omp5__parallel_begin(&parallel_data);
155 1 omptm_omp5__into_parallel_function(&parallel_data, 0);
156 1 omptm_omp5__into_parallel_implicit_barrier(&parallel_data);
157 1 omptm_omp5__parallel_end(&parallel_data);
158 1 omptm_omp5__finalize();
159
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( DLB_Finalize_sp(spd1) == DLB_SUCCESS );
160 }
161
162 /* Test --ompt-thread-manager=omp5 with an empty mask */
163 {
164 1 setenv("OMP_NUM_THREADS", "2", 1);
165 1 unsetenv("OMP_PLACES");
166 cpu_set_t empty_mask;
167 1 CPU_ZERO(&empty_mask);
168 1 spd1 = DLB_Init_sp(0, &empty_mask, options);
169 1 omptm_omp5__init(spd1->id, &spd1->options);
170 1 omptm_omp5__finalize();
171
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( DLB_Finalize_sp(spd1) == DLB_SUCCESS );
172 }
173
174 1 mu_finalize();
175
176 1 return 0;
177 }
178