1 | #include <Python.h> |
2 | #include <dlfcn.h> |
3 | #include <errno.h> |
4 | #include <omp-tools.h> |
5 | #include <pthread.h> |
6 | #include <stdio.h> |
7 | #include <stdlib.h> |
8 | #include <string.h> |
9 | |
10 | extern void *ompd_library; |
11 | |
12 | struct _ompd_aspace_cont { |
13 | int id; |
14 | }; |
15 | struct _ompd_thread_cont { |
16 | int id; |
17 | }; |
18 | ompd_address_space_context_t context = {42}; |
19 | ompd_address_space_context_t invalidcontext = {99}; |
20 | |
21 | // call back functions for ompd_initialize |
22 | ompd_rc_t _alloc(ompd_size_t bytes, void **ptr); |
23 | ompd_rc_t _free(void *ptr); |
24 | ompd_rc_t _sizes(ompd_address_space_context_t *_acontext, |
25 | ompd_device_type_sizes_t *sizes); |
26 | ompd_rc_t _sym_addr(ompd_address_space_context_t *context, |
27 | ompd_thread_context_t *tcontext, const char *symbol_name, |
28 | ompd_address_t *symbol_addr, const char *file_name); |
29 | ompd_rc_t _read(ompd_address_space_context_t *context, |
30 | ompd_thread_context_t *tcontext, const ompd_address_t *addr, |
31 | ompd_size_t nbytes, void *buffer); |
32 | ompd_rc_t _read_string(ompd_address_space_context_t *context, |
33 | ompd_thread_context_t *tcontext, |
34 | const ompd_address_t *addr, ompd_size_t nbytes, |
35 | void *buffer); |
36 | ompd_rc_t _endianess(ompd_address_space_context_t *address_space_context, |
37 | const void *input, ompd_size_t unit_size, |
38 | ompd_size_t count, void *output); |
39 | ompd_rc_t _thread_context(ompd_address_space_context_t *context, |
40 | ompd_thread_id_t kind, ompd_size_t sizeof_thread_id, |
41 | const void *thread_id, |
42 | ompd_thread_context_t **thread_context); |
43 | ompd_rc_t _print(const char *str, int category); |
44 | |
45 | /* |
46 | Test API: ompd_get_thread_handle |
47 | |
48 | ompdtestapi threadandparallel |
49 | |
50 | Program: |
51 | 1. #include <stdio.h> |
52 | 2. #include <omp.h> |
53 | 3. int main () { |
54 | 4. omp_set_num_threads(2); |
55 | 5. #pragma omp parallel |
56 | 6. { |
57 | 7. printf("Parallel level 1, thread num = %d", |
58 | omp_get_thread_num()); |
59 | 8. } |
60 | 9. return 0; |
61 | 10. } |
62 | |
63 | GDB Commands: |
64 | ompd init |
65 | b 7 |
66 | c |
67 | ompdtestapi ompd_get_thread_handle |
68 | |
69 | for ompd_rc_unavailable: |
70 | ompd init |
71 | ompdtestapi ompd_get_thread_handle |
72 | */ |
73 | |
74 | PyObject *test_ompd_get_thread_handle(PyObject *self, PyObject *args) { |
75 | printf(format: "Testing \"ompd_get_thread_handle\"...\n" ); |
76 | |
77 | PyObject *addrSpaceTup = PyTuple_GetItem(args, 0); |
78 | ompd_address_space_handle_t *addr_handle = |
79 | (ompd_address_space_handle_t *)PyCapsule_GetPointer(capsule: addrSpaceTup, |
80 | name: "AddressSpace" ); |
81 | |
82 | PyObject *threadIdTup = PyTuple_GetItem(args, 1); |
83 | uint64_t threadID = (uint64_t)PyLong_AsLong(threadIdTup); |
84 | |
85 | ompd_size_t sizeof_thread_id = sizeof(threadID); |
86 | ompd_thread_handle_t *thread_handle; |
87 | |
88 | // should be successful |
89 | printf(format: "Test: With Correct Arguments.\n" ); |
90 | ompd_rc_t rc = ompd_get_thread_handle( |
91 | handle: addr_handle, kind: 1 /*lwp*/, sizeof_thread_id, thread_id: &threadID, thread_handle: &thread_handle); |
92 | |
93 | if (rc == ompd_rc_unavailable) { |
94 | // ompd_rc_unavailable if the thread is not an OpenMP thread. |
95 | printf(format: "Success. ompd_rc_unavailable, OpenMP is disabled.\n" ); |
96 | printf(format: "This is not a Parallel Region, No more testing is possible.\n" ); |
97 | return Py_None; |
98 | } else if (rc != ompd_rc_ok) |
99 | printf(format: "Failed, with return code = %d\n" , rc); |
100 | else |
101 | printf(format: "Success.\n" ); |
102 | |
103 | // as in ompd-types.h, only 0-3 are valid for thread kind |
104 | // ompd_rc_unsupported if thread kind is not supported. |
105 | printf(format: "Test: Unsupported thread kind.\n" ); |
106 | rc = ompd_get_thread_handle(handle: addr_handle, kind: 4, sizeof_thread_id, thread_id: &threadID, |
107 | thread_handle: &thread_handle); |
108 | if (rc != ompd_rc_unsupported) |
109 | printf(format: "Failed, with return code = %d\n" , rc); |
110 | else |
111 | printf(format: "Success.\n" ); |
112 | |
113 | // ompd_rc_bad_input: if a different value in sizeof_thread_id is expected for |
114 | // a thread kind. |
115 | // sizeof_thread_id is validated at thread_context which is call back function |
116 | // "_thread_context" where we expect size to be sizeof(long int) |
117 | printf(format: "Test: Wrong value for sizeof threadID.\n" ); |
118 | rc = ompd_get_thread_handle(handle: addr_handle, kind: 1 /*lwp*/, sizeof_thread_id: sizeof_thread_id - 1, |
119 | thread_id: &threadID, thread_handle: &thread_handle); |
120 | if (rc != ompd_rc_bad_input) |
121 | printf(format: "Failed, with return code = %d\n" , rc); |
122 | else |
123 | printf(format: "Success.\n" ); |
124 | |
125 | // Random checks with null and invalid args. |
126 | /* |
127 | ompd_rc_stale_handle: is returned when the specified handle is no |
128 | longer valid; |
129 | ompd_rc_bad_input: is returned when the input parameters |
130 | (other than handle) are invalid; |
131 | ompd_rc_error: is returned when a fatal error occurred; |
132 | */ |
133 | |
134 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL thread_handle.\n" ); |
135 | rc = ompd_get_thread_handle(handle: addr_handle, kind: 1 /*lwp*/, sizeof_thread_id, |
136 | thread_id: &threadID, NULL); |
137 | if (rc != ompd_rc_bad_input) |
138 | printf(format: "Failed, with return code = %d\n" , rc); |
139 | else |
140 | printf(format: "Success.\n" ); |
141 | |
142 | printf( |
143 | format: "Test: Expecting ompd_rc_error or stale_handle for NULL addr_handle.\n" ); |
144 | rc = ompd_get_thread_handle(NULL, kind: 1 /*lwp*/, sizeof_thread_id, thread_id: &threadID, |
145 | thread_handle: &thread_handle); |
146 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
147 | printf(format: "Failed, with return code = %d\n" , rc); |
148 | else |
149 | printf(format: "Success.\n" ); |
150 | |
151 | return Py_None; |
152 | } |
153 | |
154 | /* |
155 | Test API: ompd_get_curr_parallel_handle. |
156 | |
157 | Program: |
158 | 1. #include <stdio.h> |
159 | 2. #include <omp.h> |
160 | 3. int main () { |
161 | 4. omp_set_num_threads(2); |
162 | 5. #pragma omp parallel |
163 | 6. { |
164 | 7. printf("Parallel level 1, thread num = %d", |
165 | omp_get_thread_num()); |
166 | 8. } |
167 | 9. return 0; |
168 | 10. } |
169 | |
170 | GDB Commands: |
171 | ompd init |
172 | b 7 |
173 | omptestapi ompd_get_curr_parallel_handle |
174 | |
175 | for ompd_rc_unavailable |
176 | ompd init |
177 | omptestapi ompd_get_curr_parallel_handle (or break at line 4 |
178 | before this) |
179 | */ |
180 | |
181 | PyObject *test_ompd_get_curr_parallel_handle(PyObject *self, PyObject *args) { |
182 | printf(format: "Testing \"ompd_get_curr_parallel_handle\"...\n" ); |
183 | |
184 | PyObject *threadHandlePy = PyTuple_GetItem(args, 0); |
185 | ompd_thread_handle_t *thread_handle = |
186 | (ompd_thread_handle_t *)(PyCapsule_GetPointer(capsule: threadHandlePy, |
187 | name: "ThreadHandle" )); |
188 | |
189 | ompd_parallel_handle_t *parallel_handle; |
190 | |
191 | printf(format: "Test: With Correct Arguments.\n" ); |
192 | ompd_rc_t rc = ompd_get_curr_parallel_handle(thread_handle, parallel_handle: ¶llel_handle); |
193 | if (rc == ompd_rc_unavailable) { |
194 | // ompd_rc_unavailable if the thread is not currently part of a team |
195 | |
196 | // ToCheck: Even in non parallel region, error code is stale_handle |
197 | // Need to find a test case for ompd_rc_unavailable ????? |
198 | printf(format: "Success. ompd_rc_unavailable, Not in parallel region\n" ); |
199 | printf(format: "No more testing is possible.\n" ); |
200 | return Py_None; |
201 | } else if (rc == ompd_rc_stale_handle) { |
202 | printf(format: "Return code is stale_handle, may be in non-parallel region.\n" ); |
203 | printf(format: "No more testing is possible.\n" ); |
204 | return Py_None; |
205 | } else if (rc != ompd_rc_ok) |
206 | printf(format: "Failed, with return code = %d\n" , rc); |
207 | else |
208 | printf(format: "Success.\n" ); |
209 | |
210 | // Random checks with null and invalid args. |
211 | /* |
212 | ompd_rc_stale_handle: is returned when the specified handle is no |
213 | longer valid; |
214 | ompd_rc_bad_input: is returned when the input parameters |
215 | (other than handle) are invalid; |
216 | ompd_rc_error: is returned when a fatal error occurred; |
217 | */ |
218 | |
219 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL parallel_handle.\n" ); |
220 | rc = ompd_get_curr_parallel_handle(thread_handle, NULL); |
221 | if (rc != ompd_rc_bad_input) |
222 | printf(format: "Failed, with return code = %d\n" , rc); |
223 | else |
224 | printf(format: "Success.\n" ); |
225 | |
226 | printf(format: "Test: Expecting ompd_rc_error or stale_handle for NULL " |
227 | "thread_handle.\n" ); |
228 | rc = ompd_get_curr_parallel_handle(NULL, parallel_handle: ¶llel_handle); |
229 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
230 | printf(format: "Failed, with return code = %d\n" , rc); |
231 | else |
232 | printf(format: "Success.\n" ); |
233 | |
234 | return Py_None; |
235 | } |
236 | |
237 | /* |
238 | Test API: ompd_get_thread_in_parallel. |
239 | |
240 | Program: |
241 | 1. #include <stdio.h> |
242 | 2. #include <omp.h> |
243 | 3. int main () { |
244 | 4. omp_set_num_threads(3); |
245 | 5. #pragma omp parallel |
246 | 6. { |
247 | 7. printf("Parallel level 1, thread num = %d", |
248 | omp_get_thread_num()); |
249 | 8. } |
250 | 9. return 0; |
251 | 10. } |
252 | |
253 | GDB Commands: |
254 | ompd init |
255 | b 7 |
256 | omptestapi ompd_get_thread_in_parallel |
257 | */ |
258 | PyObject *test_ompd_get_thread_in_parallel(PyObject *self, PyObject *args) { |
259 | printf(format: "Testing \"ompd_get_thread_in_parallel\"...\n" ); |
260 | |
261 | PyObject *parallelHandlePy = PyTuple_GetItem(args, 0); |
262 | ompd_parallel_handle_t *parallel_handle = |
263 | (ompd_parallel_handle_t *)(PyCapsule_GetPointer(capsule: parallelHandlePy, |
264 | name: "ParallelHandle" )); |
265 | ompd_thread_handle_t *thread_handle; |
266 | |
267 | printf(format: "Test: With Correct Arguments.\n" ); |
268 | ompd_rc_t rc = ompd_get_thread_in_parallel( |
269 | parallel_handle, thread_num: 1 /* lesser than team-size-var*/, thread_handle: &thread_handle); |
270 | if (rc != ompd_rc_ok) { |
271 | printf(format: "Failed, with return code = %d\n" , rc); |
272 | return Py_None; |
273 | } else |
274 | printf(format: "Success.\n" ); |
275 | |
276 | // ompd_rc_bad_input: if the thread_num argument is greater than or equal to |
277 | // the team-size-var ICV or negative |
278 | printf(format: "Test: Invalid thread num (199).\n" ); |
279 | rc = ompd_get_thread_in_parallel(parallel_handle, thread_num: 199, thread_handle: &thread_handle); |
280 | if (rc != ompd_rc_bad_input) |
281 | printf(format: "Failed, with return code = %d\n" , rc); |
282 | else |
283 | printf(format: "Success.\n" ); |
284 | |
285 | printf(format: "Test: Invalid thread num (-5).\n" ); |
286 | rc = ompd_get_thread_in_parallel(parallel_handle, thread_num: -5, thread_handle: &thread_handle); |
287 | if (rc != ompd_rc_bad_input) |
288 | printf(format: "Failed, with return code = %d\n" , rc); |
289 | else |
290 | printf(format: "Success.\n" ); |
291 | |
292 | // Random checks with null and invalid args. |
293 | /* |
294 | ompd_rc_stale_handle: is returned when the specified handle is no |
295 | longer valid; |
296 | ompd_rc_bad_input: is returned when the input parameters |
297 | (other than handle) are invalid; |
298 | ompd_rc_error: is returned when a fatal error occurred; |
299 | */ |
300 | |
301 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL thread_handle.\n" ); |
302 | rc = ompd_get_thread_in_parallel(parallel_handle, thread_num: 1, NULL); |
303 | if (rc != ompd_rc_bad_input) |
304 | printf(format: "Failed, with return code = %d\n" , rc); |
305 | else |
306 | printf(format: "Success.\n" ); |
307 | |
308 | printf(format: "Test: Expecting ompd_rc_error or stale_handle for NULL " |
309 | "parallel_handle.\n" ); |
310 | rc = ompd_get_thread_in_parallel(NULL, thread_num: 1, thread_handle: &thread_handle); |
311 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
312 | printf(format: "Failed, with return code = %d\n" , rc); |
313 | else |
314 | printf(format: "Success.\n" ); |
315 | |
316 | return Py_None; |
317 | } |
318 | |
319 | /* |
320 | Test API: ompd_thread_handle_compare. |
321 | |
322 | Program: |
323 | 1. #include <stdio.h> |
324 | 2. #include <omp.h> |
325 | 3. int main () { |
326 | 4. omp_set_num_threads(4); |
327 | 5. #pragma omp parallel |
328 | 6. { |
329 | 7. printf("Parallel level 1, thread num = %d", |
330 | omp_get_thread_num()); |
331 | 8. } |
332 | 9. return 0; |
333 | 10. } |
334 | |
335 | GDB Commands: |
336 | ompd init |
337 | b 7 |
338 | omptestapi ompd_thread_handle_compare |
339 | */ |
340 | |
341 | PyObject *test_ompd_thread_handle_compare(PyObject *self, PyObject *args) { |
342 | printf(format: "Testing \"ompd_thread_handle_compare\"...\n" ); |
343 | |
344 | PyObject *threadHandlePy1 = PyTuple_GetItem(args, 0); |
345 | ompd_thread_handle_t *thread_handle1 = |
346 | (ompd_thread_handle_t *)(PyCapsule_GetPointer(capsule: threadHandlePy1, |
347 | name: "ThreadHandle" )); |
348 | PyObject *threadHandlePy2 = PyTuple_GetItem(args, 1); |
349 | ompd_thread_handle_t *thread_handle2 = |
350 | (ompd_thread_handle_t *)(PyCapsule_GetPointer(capsule: threadHandlePy2, |
351 | name: "ThreadHandle" )); |
352 | |
353 | int cmp_value; |
354 | |
355 | printf(format: "Test: With Correct Arguments.\n" ); |
356 | ompd_rc_t rc = |
357 | ompd_thread_handle_compare(thread_handle_1: thread_handle1, thread_handle_2: thread_handle2, cmp_value: &cmp_value); |
358 | if (rc != ompd_rc_ok) { |
359 | printf(format: "Failed, with return code = %d\n" , rc); |
360 | return Py_None; |
361 | } else |
362 | printf(format: "Success.\n" ); |
363 | |
364 | if (cmp_value == 0) { |
365 | printf(format: "Threads are Equal.\n" ); |
366 | } else { |
367 | // a value less than, equal to, or greater than 0 indicates that the thread |
368 | // corresponding to thread_handle_1 is, respectively, less than, equal to, |
369 | // or greater than that corresponding to thread_handle_2. |
370 | if (cmp_value <= 0) { |
371 | printf(format: "Thread 1 is lesser than thread 2, cmp_val = %d\n" , cmp_value); |
372 | printf(format: "Test: Changing the order.\n" ); |
373 | rc = ompd_thread_handle_compare(thread_handle_1: thread_handle2, thread_handle_2: thread_handle1, |
374 | cmp_value: &cmp_value); |
375 | if (rc != ompd_rc_ok) { |
376 | printf(format: "Failed, with return code = %d\n" , rc); |
377 | return Py_None; |
378 | } |
379 | if (cmp_value >= 0) |
380 | printf(format: "Success now cmp_value is greater, %d.\n" , cmp_value); |
381 | else |
382 | printf(format: "Failed.\n" ); |
383 | } else { |
384 | printf(format: "Thread 1 is greater than thread 2.\n" ); |
385 | printf(format: "Test: Changing the order.\n" ); |
386 | rc = ompd_thread_handle_compare(thread_handle_1: thread_handle2, thread_handle_2: thread_handle1, |
387 | cmp_value: &cmp_value); |
388 | if (rc != ompd_rc_ok) { |
389 | printf(format: "Failed, with return code = %d\n" , rc); |
390 | return Py_None; |
391 | } |
392 | if (cmp_value <= 0) |
393 | printf(format: "Success now cmp_value is lesser, %d.\n" , cmp_value); |
394 | else |
395 | printf(format: "Failed.\n" ); |
396 | } |
397 | |
398 | // Random checks with null and invalid args. |
399 | /* |
400 | ompd_rc_stale_handle: is returned when the specified handle is no |
401 | longer valid; |
402 | ompd_rc_bad_input: is returned when the input parameters |
403 | (other than handle) are invalid; |
404 | ompd_rc_error: is returned when a fatal error occurred; |
405 | */ |
406 | |
407 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL cmp_value.\n" ); |
408 | rc = ompd_thread_handle_compare(thread_handle_1: thread_handle2, thread_handle_2: thread_handle1, NULL); |
409 | if (rc != ompd_rc_bad_input) |
410 | printf(format: "Failed, with return code = %d\n" , rc); |
411 | else |
412 | printf(format: "Success.\n" ); |
413 | |
414 | printf(format: "Test: Expecting ompd_rc_error or stale_handle for NULL " |
415 | "thread_handle.\n" ); |
416 | rc = ompd_thread_handle_compare(NULL, thread_handle_2: thread_handle1, cmp_value: &cmp_value); |
417 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
418 | printf(format: "Failed, with return code = %d\n" , rc); |
419 | else |
420 | printf(format: "Success.\n" ); |
421 | } |
422 | |
423 | return Py_None; |
424 | } |
425 | |
426 | /* |
427 | Test API: ompd_get_thread_id. |
428 | |
429 | Program: |
430 | 1. #include <stdio.h> |
431 | 2. #include <omp.h> |
432 | 3. int main () { |
433 | 4. omp_set_num_threads(2); |
434 | 5. #pragma omp parallel |
435 | 6. { |
436 | 7. printf("Parallel level 1, thread num = %d", |
437 | omp_get_thread_num()); |
438 | 8. } |
439 | 9. return 0; |
440 | 10. } |
441 | |
442 | GDB Commands: |
443 | ompd init |
444 | b 7 |
445 | omptestapi ompd_get_thread_id |
446 | */ |
447 | |
448 | PyObject *test_ompd_get_thread_id(PyObject *self, PyObject *args) { |
449 | printf(format: "Testing \"ompd_get_thread_id\"...\n" ); |
450 | |
451 | PyObject *threadHandlePy = PyTuple_GetItem(args, 0); |
452 | ompd_thread_handle_t *thread_handle = |
453 | (ompd_thread_handle_t *)(PyCapsule_GetPointer(capsule: threadHandlePy, |
454 | name: "ThreadHandle" )); |
455 | |
456 | uint64_t threadID; |
457 | ompd_size_t sizeof_thread_id = sizeof(threadID); |
458 | |
459 | printf(format: "Test: With Correct Arguments.\n" ); |
460 | ompd_rc_t rc = ompd_get_thread_id(thread_handle, kind: 0 /*OMPD_THREAD_ID_PTHREAD*/, |
461 | sizeof_thread_id, thread_id: &threadID); |
462 | if (rc != ompd_rc_ok) { |
463 | printf(format: "Failed, with return code = %d\n" , rc); |
464 | return Py_None; |
465 | } else |
466 | printf(format: "Success. Thread id = %ld\n" , threadID); |
467 | |
468 | // ompd_rc_bad_input: if a different value in sizeof_thread_id is expected for |
469 | // a thread kind of kind |
470 | printf(format: "Test: Wrong sizeof_thread_id.\n" ); |
471 | rc = ompd_get_thread_id(thread_handle, kind: 0 /*OMPD_THREAD_ID_PTHREAD*/, |
472 | sizeof_thread_id: sizeof_thread_id - 1, thread_id: &threadID); |
473 | if (rc != ompd_rc_bad_input) |
474 | printf(format: "Failed, with return code = %d\n" , rc); |
475 | else |
476 | printf(format: "Success.\n" ); |
477 | |
478 | // ompd_rc_unsupported: if the kind of thread is not supported |
479 | printf(format: "Test: Unsupported thread kind.\n" ); |
480 | // thread kind currently support from 0-3, refer in ompd-types.h |
481 | rc = ompd_get_thread_id(thread_handle, kind: 4, sizeof_thread_id: sizeof_thread_id - 1, thread_id: &threadID); |
482 | if (rc != ompd_rc_unsupported) |
483 | printf(format: "Failed, with return code = %d\n" , rc); |
484 | else |
485 | printf(format: "Success.\n" ); |
486 | |
487 | // Random checks with null and invalid args. |
488 | /* |
489 | ompd_rc_stale_handle: is returned when the specified handle is no |
490 | longer valid; |
491 | ompd_rc_bad_input: is returned when the input parameters |
492 | (other than handle) are invalid; |
493 | ompd_rc_error: is returned when a fatal error occurred; |
494 | */ |
495 | |
496 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL threadID.\n" ); |
497 | rc = ompd_get_thread_id(thread_handle, kind: 0 /*OMPD_THREAD_ID_PTHREAD*/, |
498 | sizeof_thread_id, NULL); |
499 | if (rc != ompd_rc_bad_input) |
500 | printf(format: "Failed, with return code = %d\n" , rc); |
501 | else |
502 | printf(format: "Success.\n" ); |
503 | |
504 | printf(format: "Test: Expecting ompd_rc_error for NULL thread_handle.\n" ); |
505 | rc = ompd_get_thread_id(NULL, kind: 0 /*OMPD_THREAD_ID_PTHREAD*/, sizeof_thread_id, |
506 | thread_id: &threadID); |
507 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
508 | printf(format: "Failed, with return code = %d\n" , rc); |
509 | else |
510 | printf(format: "Success.\n" ); |
511 | |
512 | return Py_None; |
513 | } |
514 | |
515 | /* |
516 | Test API: ompd_rel_thread_handle |
517 | |
518 | Program: |
519 | 1. #include <stdio.h> |
520 | 2. #include <omp.h> |
521 | 3. int main () { |
522 | 4. omp_set_num_threads(2); |
523 | 5. #pragma omp parallel |
524 | 6. { |
525 | 7. printf("Parallel level 1, thread num = %d", |
526 | omp_get_thread_num()); |
527 | 8. } |
528 | 9. return 0; |
529 | 10. } |
530 | |
531 | GDB Commands: |
532 | ompd init |
533 | b 7 |
534 | omptestapi ompd_rel_thread_handle |
535 | */ |
536 | |
537 | // TODO: This might not be the right way to do,as this handle comes from |
538 | // python not generated by ompd API |
539 | |
540 | PyObject *test_ompd_rel_thread_handle(PyObject *self, PyObject *args) { |
541 | printf(format: "Testing Not enabled for \"ompd_rel_thread_handle\"...\n" ); |
542 | printf(format: "Disabled.\n" ); |
543 | return Py_None; |
544 | } |
545 | |
546 | /* |
547 | Test API: ompd_get_enclosing_parallel_handle. |
548 | |
549 | Program: |
550 | 1. #include <stdio.h> |
551 | 2. #include <omp.h> |
552 | 3. int main () { |
553 | 4. omp_set_num_threads(2); |
554 | 5. #pragma omp parallel |
555 | 6. { |
556 | 7. printf("Parallel level 1, thread num = %d", |
557 | omp_get_thread_num()); |
558 | 8. omp_set_num_threads(3); |
559 | 9. #pragma omp parallel |
560 | 10. { |
561 | 11. printf ("Parallel level 2, thread num = %d", |
562 | omp_get_thread_num()); |
563 | 12. } |
564 | 13. } |
565 | 14. return 0; |
566 | 15. } |
567 | |
568 | GDB Commands: |
569 | ompd init |
570 | b 11 |
571 | ompdtestapi ompd_get_enclosing_parallel_handle |
572 | |
573 | for "ompd_rc_unavailable": |
574 | ompd init |
575 | omptestapi ompd_get_enclosing_parallel_handle |
576 | (or break at line 4 before this) |
577 | */ |
578 | |
579 | PyObject *test_ompd_get_enclosing_parallel_handle(PyObject *self, |
580 | PyObject *args) { |
581 | printf(format: "Testing \"ompd_get_enclosing_parallel_handle\"...\n" ); |
582 | |
583 | PyObject *parallelHandlePy = PyTuple_GetItem(args, 0); |
584 | ompd_parallel_handle_t *parallel_handle = |
585 | (ompd_parallel_handle_t *)(PyCapsule_GetPointer(capsule: parallelHandlePy, |
586 | name: "ParallelHandle" )); |
587 | ompd_parallel_handle_t *enclosing_parallel_handle; |
588 | |
589 | printf(format: "Test: With Correct Arguments.\n" ); |
590 | ompd_rc_t rc = ompd_get_enclosing_parallel_handle(parallel_handle, |
591 | enclosing_parallel_handle: &enclosing_parallel_handle); |
592 | if (rc == ompd_rc_unavailable) { |
593 | // ompd_rc_unavailable: if no enclosing parallel region exists. |
594 | printf(format: "Success. return code is ompd_rc_unavailable, Not in parallel " |
595 | "region\n" ); |
596 | printf(format: "No more testing is possible.\n" ); |
597 | return Py_None; |
598 | } else if (rc != ompd_rc_ok) { |
599 | printf(format: "Failed, with return code = %d\n" , rc); |
600 | return Py_None; |
601 | } else |
602 | printf(format: "Success.\n" ); |
603 | |
604 | // Random checks with null and invalid args. |
605 | /* |
606 | ompd_rc_stale_handle: is returned when the specified handle is no |
607 | longer valid; |
608 | ompd_rc_bad_input: is returned when the input parameters |
609 | (other than handle) are invalid; |
610 | ompd_rc_error: is returned when a fatal error occurred; |
611 | */ |
612 | |
613 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL " |
614 | "enclosing_parallel_handle.\n" ); |
615 | rc = ompd_get_enclosing_parallel_handle(parallel_handle, NULL); |
616 | if (rc != ompd_rc_bad_input) |
617 | printf(format: "Failed, with return code = %d\n" , rc); |
618 | else |
619 | printf(format: "Success.\n" ); |
620 | |
621 | printf(format: "Test: Expecting ompd_rc_error or stale_handle for NULL " |
622 | "parallel_handle.\n" ); |
623 | rc = ompd_get_enclosing_parallel_handle(NULL, enclosing_parallel_handle: &enclosing_parallel_handle); |
624 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
625 | printf(format: "Failed, with return code = %d\n" , rc); |
626 | else |
627 | printf(format: "Success.\n" ); |
628 | |
629 | return Py_None; |
630 | } |
631 | |
632 | /* |
633 | Test API: ompd_parallel_handle_compare. |
634 | |
635 | Program: |
636 | 1. #include <stdio.h> |
637 | 2. #include <omp.h> |
638 | 3. int main () { |
639 | 4. omp_set_num_threads(2); |
640 | 5. #pragma omp parallel |
641 | 6. { |
642 | 7. printf("Parallel level 1, thread num = %d", |
643 | omp_get_thread_num()); |
644 | 8. omp_set_num_threads(3); |
645 | 9. #pragma omp parallel |
646 | 10. { |
647 | 11. printf ("Parallel level 2, thread num = %d", |
648 | omp_get_thread_num()); |
649 | 12. } |
650 | 13. } |
651 | 14. return 0; |
652 | 15. } |
653 | |
654 | GDB Commands: |
655 | ompd init |
656 | b 11 |
657 | ompdtestapi ompd_parallel_handle_compare |
658 | */ |
659 | |
660 | PyObject *test_ompd_parallel_handle_compare(PyObject *self, PyObject *args) { |
661 | printf(format: "Testing \"ompd_parallel_handle_compare\"...\n" ); |
662 | |
663 | PyObject *parallelHandlePy1 = PyTuple_GetItem(args, 0); |
664 | ompd_parallel_handle_t *parallel_handle1 = |
665 | (ompd_parallel_handle_t *)(PyCapsule_GetPointer(capsule: parallelHandlePy1, |
666 | name: "ParallelHandle" )); |
667 | PyObject *parallelHandlePy2 = PyTuple_GetItem(args, 1); |
668 | ompd_parallel_handle_t *parallel_handle2 = |
669 | (ompd_parallel_handle_t *)(PyCapsule_GetPointer(capsule: parallelHandlePy2, |
670 | name: "ParallelHandle" )); |
671 | |
672 | int cmp_value; |
673 | |
674 | printf(format: "Test: With Correct Arguments.\n" ); |
675 | ompd_rc_t rc = ompd_parallel_handle_compare(parallel_handle_1: parallel_handle1, |
676 | parallel_handle_2: parallel_handle2, cmp_value: &cmp_value); |
677 | if (rc != ompd_rc_ok) { |
678 | printf(format: "Failed, with return code = %d\n" , rc); |
679 | return Py_None; |
680 | } else |
681 | printf(format: "Success.\n" ); |
682 | |
683 | if (cmp_value == 0) { |
684 | printf(format: "Parallel regions are Same.\n" ); |
685 | } else { |
686 | // A value less than, equal to, or greater than 0 indicates that the region |
687 | // corresponding to parallel_handle_1 is, respectively, less than, equal to, |
688 | // or greater than that corresponding to parallel_handle_2 |
689 | if (cmp_value <= 0) { |
690 | printf(format: "Parallel handle 1 is lesser than handle 2, cmp_val = %d\n" , |
691 | cmp_value); |
692 | printf(format: "Test: Changing the order.\n" ); |
693 | rc = ompd_parallel_handle_compare(parallel_handle_1: parallel_handle2, parallel_handle_2: parallel_handle1, |
694 | cmp_value: &cmp_value); |
695 | if (rc != ompd_rc_ok) { |
696 | printf(format: "Failed, with return code = %d\n" , rc); |
697 | return Py_None; |
698 | } |
699 | if (cmp_value >= 0) |
700 | printf(format: "Success now cmp_value is greater, %d.\n" , cmp_value); |
701 | else |
702 | printf(format: "Failed.\n" ); |
703 | } else { |
704 | printf(format: "Parallel 1 is greater than handle 2.\n" ); |
705 | printf(format: "Test: Changing the order.\n" ); |
706 | rc = ompd_parallel_handle_compare(parallel_handle_1: parallel_handle2, parallel_handle_2: parallel_handle1, |
707 | cmp_value: &cmp_value); |
708 | if (rc != ompd_rc_ok) { |
709 | printf(format: "Failed, with return code = %d\n" , rc); |
710 | return Py_None; |
711 | } |
712 | if (cmp_value <= 0) |
713 | printf(format: "Success now cmp_value is lesser, %d.\n" , cmp_value); |
714 | else |
715 | printf(format: "Failed.\n" ); |
716 | } |
717 | |
718 | // Random checks with null and invalid args. |
719 | /* |
720 | ompd_rc_stale_handle: is returned when the specified handle is no |
721 | longer valid; |
722 | ompd_rc_bad_input: is returned when the input parameters |
723 | (other than handle) are invalid; |
724 | ompd_rc_error: is returned when a fatal error occurred; |
725 | */ |
726 | |
727 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL cmp_value.\n" ); |
728 | rc = ompd_parallel_handle_compare(parallel_handle_1: parallel_handle2, parallel_handle_2: parallel_handle1, NULL); |
729 | if (rc != ompd_rc_bad_input) |
730 | printf(format: "Failed, with return code = %d\n" , rc); |
731 | else |
732 | printf(format: "Success.\n" ); |
733 | |
734 | printf(format: "Test: Expecting ompd_rc_error or stale_handle for NULL " |
735 | "thread_handle.\n" ); |
736 | rc = ompd_parallel_handle_compare(NULL, parallel_handle_2: parallel_handle1, cmp_value: &cmp_value); |
737 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
738 | printf(format: "Failed, with return code = %d\n" , rc); |
739 | else |
740 | printf(format: "Success.\n" ); |
741 | } |
742 | |
743 | return Py_None; |
744 | } |
745 | |
746 | /* |
747 | Test API: ompd_rel_parallel_handle |
748 | |
749 | Program: |
750 | 1. #include <stdio.h> |
751 | 2. #include <omp.h> |
752 | 3. int main () { |
753 | 4. omp_set_num_threads(2); |
754 | 5. #pragma omp parallel |
755 | 6. { |
756 | 7. printf("Parallel level 1, thread num = %d", |
757 | omp_get_thread_num()); |
758 | 8. } |
759 | 9. return 0; |
760 | 10. } |
761 | |
762 | GDB Commands: |
763 | ompd init |
764 | b 7 |
765 | omptestapi ompd_rel_parallel_handle |
766 | */ |
767 | |
768 | // TODO: Same as thread_rel_handle, might not be a right way to test |
769 | // What released should be provided by ompd API, this address is actually from |
770 | // python |
771 | PyObject *test_ompd_rel_parallel_handle(PyObject *self, PyObject *args) { |
772 | printf(format: "Testing NOT enabled for \"ompd_rel_parallel_handle\"...\n" ); |
773 | printf(format: "Disabled.\n" ); |
774 | return Py_None; |
775 | } |
776 | |
777 | /* |
778 | Test API: ompd_initialize |
779 | |
780 | Program: |
781 | 1. #include <stdio.h> |
782 | 2. #include <omp.h> |
783 | 3. int main () { |
784 | 4. omp_set_num_threads(2); |
785 | 5. #pragma omp parallel |
786 | 6. { |
787 | 7. printf("Parallel level 1, thread num = %d", |
788 | omp_get_thread_num()); |
789 | 8. } |
790 | 9. return 0; |
791 | 10. } |
792 | |
793 | GDB Commands: |
794 | b 4 |
795 | ompdtestapi ompd_initialize\ |
796 | */ |
797 | PyObject *test_ompd_initialize(PyObject *self, PyObject *noargs) { |
798 | printf(format: "Testing \"test_ompd_initialize\"...\n" ); |
799 | |
800 | ompd_word_t version; |
801 | ompd_rc_t rc = ompd_get_api_version(version: &version); |
802 | if (rc != ompd_rc_ok) { |
803 | printf(format: "Failed in \"ompd_get_api_version\".\n" ); |
804 | return Py_None; |
805 | } |
806 | |
807 | static ompd_callbacks_t table = { |
808 | _alloc, _free, _print, _sizes, _sym_addr, _read, |
809 | NULL, _read_string, _endianess, _endianess, _thread_context}; |
810 | |
811 | printf(format: "Test: With Correct Arguments.\n" ); |
812 | ompd_rc_t (*my_ompd_init)(ompd_word_t version, ompd_callbacks_t *) = |
813 | dlsym(handle: ompd_library, name: "ompd_initialize" ); |
814 | rc = my_ompd_init(version, &table); |
815 | if (rc != ompd_rc_ok) { |
816 | printf(format: "Failed, with return code = %d\n" , rc); |
817 | return Py_None; |
818 | } else |
819 | printf(format: "Success.\n" ); |
820 | |
821 | static ompd_callbacks_t invalid_table = { |
822 | NULL, /* _alloc, */ |
823 | NULL, /* _free, */ |
824 | NULL, /* _print,*/ |
825 | NULL, /* _sizes, */ |
826 | NULL, /* _sym_addr, */ |
827 | NULL, /* _read,*/ |
828 | NULL, NULL, /* _read_string, */ |
829 | NULL, /* _endianess, */ |
830 | NULL, /* _endianess, */ |
831 | NULL, /* _thread_context */ |
832 | }; |
833 | |
834 | // ompd_rc_bad_input: if invalid callbacks are provided |
835 | printf(format: "Test: Invalid callbacks.\n" ); |
836 | rc = my_ompd_init(version, &invalid_table); |
837 | if (rc != ompd_rc_bad_input) |
838 | printf(format: "Warning, with return code = %d\n" , rc); |
839 | else |
840 | printf(format: "Success.\n" ); |
841 | |
842 | // ompd_rc_unsupported: if the requested API version cannot be provided |
843 | printf(format: "Test: Wrong API version.\n" ); |
844 | rc = my_ompd_init(150847, &table); |
845 | if (rc != ompd_rc_unsupported) |
846 | printf(format: "Failed, with return code = %d\n" , rc); |
847 | else |
848 | printf(format: "Success.\n" ); |
849 | |
850 | // Random checks with null and invalid args. |
851 | /* |
852 | ompd_rc_stale_handle: is returned when the specified handle is no |
853 | longer valid; |
854 | ompd_rc_bad_input: is returned when the input parameters |
855 | (other than handle) are invalid; |
856 | ompd_rc_error: is returned when a fatal error occurred; |
857 | */ |
858 | |
859 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL table.\n" ); |
860 | rc = my_ompd_init(version, NULL); |
861 | if (rc != ompd_rc_bad_input) |
862 | printf(format: "Failed, with return code = %d\n" , rc); |
863 | else |
864 | printf(format: "Success.\n" ); |
865 | |
866 | printf(format: "Test: Expecting ompd_rc_error or ompd_rc_bad_input for NULL\n" ); |
867 | rc = my_ompd_init(0, &table); |
868 | if (rc != ompd_rc_unsupported && rc != ompd_rc_bad_input) |
869 | printf(format: "Failed, with return code = %d\n" , rc); |
870 | else |
871 | printf(format: "Success.\n" ); |
872 | |
873 | return Py_None; |
874 | } |
875 | |
876 | /* |
877 | Test API: ompd_get_api_version |
878 | |
879 | Program: |
880 | 1. #include <stdio.h> |
881 | 2. #include <omp.h> |
882 | 3. int main () { |
883 | 4. omp_set_num_threads(2); |
884 | 5. #pragma omp parallel |
885 | 6. { |
886 | 7. printf("Parallel level 1, thread num = %d", |
887 | omp_get_thread_num()); |
888 | 8. } |
889 | 9. return 0; |
890 | 10. } |
891 | |
892 | GDB Commands: |
893 | ompd init |
894 | b 7 |
895 | ompdtestapi ompd_get_version |
896 | |
897 | */ |
898 | |
899 | PyObject *test_ompd_get_api_version(PyObject *self, PyObject *noargs) { |
900 | printf(format: "Testing \"ompd_get_api_version\"...\n" ); |
901 | |
902 | ompd_word_t version; |
903 | |
904 | printf(format: "Test: With Correct Arguments.\n" ); |
905 | ompd_rc_t rc = ompd_get_api_version(version: &version); |
906 | if (rc != ompd_rc_ok) { |
907 | printf(format: "Failed, with return code = %d\n" , rc); |
908 | return Py_None; |
909 | } else |
910 | printf(format: "Success. API version is %ld\n" , version); |
911 | |
912 | printf( |
913 | format: "Test: Expecting ompd_rc_error or ompd_rc_bad_input for NULL version\n" ); |
914 | rc = ompd_get_api_version(NULL); |
915 | if (rc != ompd_rc_error && rc != ompd_rc_bad_input) |
916 | printf(format: "Failed, with return code = %d\n" , rc); |
917 | else |
918 | printf(format: "Success.\n" ); |
919 | |
920 | return Py_None; |
921 | } |
922 | |
923 | /* |
924 | Test API: ompd_get_version_string |
925 | |
926 | Program: |
927 | 1. #include <stdio.h> |
928 | 2. #include <omp.h> |
929 | 3. int main () { |
930 | 4. omp_set_num_threads(2); |
931 | 5. #pragma omp parallel |
932 | 6. { |
933 | 7. printf("Parallel level 1, thread num = %d", |
934 | omp_get_thread_num()); |
935 | 8. } |
936 | 9. return 0; |
937 | 10. } |
938 | |
939 | GDB Commands: |
940 | ompd init |
941 | b 7 |
942 | omptestapi ompd_get_version_string |
943 | |
944 | */ |
945 | |
946 | PyObject *test_ompd_get_version_string(PyObject *self, PyObject *noargs) { |
947 | printf(format: "Testing \"ompd_get_version_string\"...\n" ); |
948 | |
949 | const char *string; |
950 | |
951 | printf(format: "Test: With Correct Arguments.\n" ); |
952 | ompd_rc_t rc = ompd_get_version_string(string: &string); |
953 | if (rc != ompd_rc_ok) { |
954 | printf(format: "Failed, with return code = %d\n" , rc); |
955 | return Py_None; |
956 | } else |
957 | printf(format: "Success. API version is %s\n" , string); |
958 | |
959 | printf( |
960 | format: "Test: Expecting ompd_rc_error or ompd_rc_bad_input for NULL version\n" ); |
961 | rc = ompd_get_version_string(NULL); |
962 | if (rc != ompd_rc_error && rc != ompd_rc_bad_input) |
963 | printf(format: "Failed, with return code = %d\n" , rc); |
964 | else |
965 | printf(format: "Success.\n" ); |
966 | |
967 | return Py_None; |
968 | } |
969 | |
970 | /* |
971 | Test API: ompd_finalize |
972 | |
973 | Program: |
974 | 1. #include <stdio.h> |
975 | 2. #include <omp.h> |
976 | 3. int main () { |
977 | 4. omp_set_num_threads(2); |
978 | 5. #pragma omp parallel |
979 | 6. { |
980 | 7. printf("Parallel level 1, thread num = %d", |
981 | omp_get_thread_num()); |
982 | 8. } |
983 | 9. return 0; |
984 | 10. } |
985 | |
986 | GDB Commands: |
987 | ompd init |
988 | b 7 |
989 | ompdtestapi ompd_finalize |
990 | |
991 | |
992 | b 4 |
993 | r |
994 | ompdtestapi ompd_finalize |
995 | */ |
996 | |
997 | PyObject *test_ompd_finalize(PyObject *self, PyObject *noargs) { |
998 | printf(format: "Testing \"ompd_finalize\"...\n" ); |
999 | |
1000 | printf(format: "Test: With Correct Arguments.\n" ); |
1001 | ompd_rc_t rc = ompd_finalize(); |
1002 | if (rc == ompd_rc_ok) |
1003 | printf(format: "Ret code: ompd_rc_ok, Success if ompd is initialized.\n" ); |
1004 | // ompd_rc_unsupported: if the OMPD library is not initialized. |
1005 | else if (rc == ompd_rc_unsupported) |
1006 | printf( |
1007 | format: "Ret code: ompd_rc_unsupported, Success if ompd is NOT initialized.\n" ); |
1008 | else |
1009 | printf(format: "Failed: Return code is %d.\n" , rc); |
1010 | |
1011 | return Py_None; |
1012 | } |
1013 | |
1014 | /* |
1015 | Test API: ompd_process_initialize |
1016 | |
1017 | Program: |
1018 | 1. #include <stdio.h> |
1019 | 2. #include <omp.h> |
1020 | 3. int main () { |
1021 | 4. omp_set_num_threads(2); |
1022 | 5. #pragma omp parallel |
1023 | 6. { |
1024 | 7. printf("Parallel level 1, thread num = %d", |
1025 | omp_get_thread_num()); |
1026 | 8. } |
1027 | 9. return 0; |
1028 | 10. } |
1029 | |
1030 | GDB Commands: |
1031 | |
1032 | */ |
1033 | |
1034 | PyObject *test_ompd_process_initialize(PyObject *self, PyObject *noargs) { |
1035 | |
1036 | printf(format: "Testing \"ompd_process_initialize\"....\n" ); |
1037 | |
1038 | ompd_address_space_handle_t *addr_handle; |
1039 | |
1040 | // ompd_address_space_context_t context = {42}; |
1041 | |
1042 | printf(format: "Test: with correct Args.\n" ); |
1043 | ompd_rc_t rc = ompd_process_initialize(context: &context, handle: &addr_handle); |
1044 | if (rc != ompd_rc_ok) { |
1045 | printf(format: "Failed, with return code = %d\n" , rc); |
1046 | return Py_None; |
1047 | } else |
1048 | printf(format: "Success.\n" ); |
1049 | |
1050 | printf(format: "Test: With Unsupported library.\n" ); |
1051 | printf(format: "Warning: Have to test manually with 32 and 64 bit combination.\n" ); |
1052 | |
1053 | // ompd_address_space_context_t invalidcontext = {99}; |
1054 | printf(format: "Test: with wrong context value.\n" ); |
1055 | rc = ompd_process_initialize(context: &invalidcontext, handle: &addr_handle); |
1056 | if ((rc != ompd_rc_bad_input) && (rc != ompd_rc_incompatible) && |
1057 | (rc != ompd_rc_stale_handle)) |
1058 | printf(format: "Failed, with return code = %d\n" , rc); |
1059 | else |
1060 | printf(format: "Success.\n" ); |
1061 | |
1062 | // Random checks with null and invalid args. |
1063 | /* |
1064 | ompd_rc_stale_handle: is returned when the specified handle is no |
1065 | longer valid; |
1066 | ompd_rc_bad_input: is returned when the input parameters |
1067 | (other than handle) are invalid; |
1068 | ompd_rc_error: is returned when a fatal error occurred; |
1069 | */ |
1070 | |
1071 | printf(format: "Test: Expecting stale handle or bad_input for NULL addr_handle.\n" ); |
1072 | rc = ompd_process_initialize(context: &context, NULL); |
1073 | if ((rc != ompd_rc_bad_input) && (rc != ompd_rc_stale_handle)) |
1074 | printf(format: "Failed, with return code = %d\n" , rc); |
1075 | else |
1076 | printf(format: "Success.\n" ); |
1077 | |
1078 | return Py_None; |
1079 | } |
1080 | |
1081 | /* |
1082 | Test API: ompd_device_initialize |
1083 | |
1084 | Program: |
1085 | 1. #include <stdio.h> |
1086 | 2. #include <omp.h> |
1087 | 3. int main () { |
1088 | 4. omp_set_num_threads(2); |
1089 | 5. #pragma omp parallel |
1090 | 6. { |
1091 | 7. printf("Parallel level 1, thread num = %d", |
1092 | omp_get_thread_num()); |
1093 | 8. } |
1094 | 9. return 0; |
1095 | 10. } |
1096 | |
1097 | GDB Commands: |
1098 | |
1099 | */ |
1100 | |
1101 | PyObject *test_ompd_device_initialize(PyObject *self, PyObject *noargs) { |
1102 | printf(format: "Testing Not enabled for \"ompd_device_initialize\".\n" ); |
1103 | printf(format: "Disabled.\n" ); |
1104 | |
1105 | return Py_None; |
1106 | } |
1107 | |
1108 | /* |
1109 | Test API: ompd_rel_address_space_handle |
1110 | |
1111 | Program: |
1112 | 1. #include <stdio.h> |
1113 | 2. #include <omp.h> |
1114 | 3. int main () { |
1115 | 4. omp_set_num_threads(2); |
1116 | 5. #pragma omp parallel |
1117 | 6. { |
1118 | 7. printf("Parallel level 1, thread num = %d", |
1119 | omp_get_thread_num()); |
1120 | 8. } |
1121 | 9. return 0; |
1122 | 10. } |
1123 | |
1124 | GDB Commands: |
1125 | |
1126 | */ |
1127 | PyObject *test_ompd_rel_address_space_handle(PyObject *self, PyObject *noargs) { |
1128 | printf(format: "Testing Not enabled for \"ompd_rel_address_space_handle\".\n" ); |
1129 | printf(format: "Disabled.\n" ); |
1130 | |
1131 | return Py_None; |
1132 | } |
1133 | |
1134 | /* |
1135 | Test API: ompd_get_omp_version |
1136 | |
1137 | Program: |
1138 | 1. #include <stdio.h> |
1139 | 2. #include <omp.h> |
1140 | 3. int main () { |
1141 | 4. omp_set_num_threads(2); |
1142 | 5. #pragma omp parallel |
1143 | 6. { |
1144 | 7. printf("Parallel level 1, thread num = %d", |
1145 | omp_get_thread_num()); |
1146 | 8. } |
1147 | 9. return 0; |
1148 | 10. } |
1149 | |
1150 | GDB Commands: |
1151 | ompd init |
1152 | b 10 |
1153 | c |
1154 | ompdtestapi ompd_get_omp_version |
1155 | */ |
1156 | PyObject *test_ompd_get_omp_version(PyObject *self, PyObject *args) { |
1157 | printf(format: "Testing \"ompd_get_omp_version\" ...\n" ); |
1158 | |
1159 | PyObject *addrSpaceTup = PyTuple_GetItem(args, 0); |
1160 | ompd_address_space_handle_t *addr_handle = |
1161 | (ompd_address_space_handle_t *)PyCapsule_GetPointer(capsule: addrSpaceTup, |
1162 | name: "AddressSpace" ); |
1163 | |
1164 | ompd_word_t omp_version; |
1165 | |
1166 | printf(format: "Test: With Correct Arguments.\n" ); |
1167 | ompd_rc_t rc = ompd_get_omp_version(address_space: addr_handle, omp_version: &omp_version); |
1168 | if (rc != ompd_rc_ok) { |
1169 | printf(format: "Failed, with return code = %d\n" , rc); |
1170 | return Py_None; |
1171 | } else |
1172 | printf(format: "Success. API version is %ld\n" , omp_version); |
1173 | |
1174 | // Random checks with null and invalid args. |
1175 | /* |
1176 | ompd_rc_stale_handle: is returned when the specified handle is no |
1177 | longer valid; |
1178 | ompd_rc_bad_input: is returned when the input parameters |
1179 | (other than handle) are invalid; |
1180 | ompd_rc_error: is returned when a fatal error occurred; |
1181 | */ |
1182 | |
1183 | printf(format: "Test: Expecting stale handle or bad_input for NULL addr_handle.\n" ); |
1184 | rc = ompd_get_omp_version(NULL, omp_version: &omp_version); |
1185 | if ((rc != ompd_rc_bad_input) && (rc != ompd_rc_stale_handle)) |
1186 | printf(format: "Failed, with return code = %d\n" , rc); |
1187 | else |
1188 | printf(format: "Success.\n" ); |
1189 | |
1190 | printf(format: "Test: Expecting ompd_rc_error or bad_input for NULL omp_version.\n" ); |
1191 | rc = ompd_get_omp_version(address_space: addr_handle, NULL); |
1192 | if (rc != ompd_rc_error && rc != ompd_rc_bad_input) |
1193 | printf(format: "Failed, with return code = %d\n" , rc); |
1194 | else |
1195 | printf(format: "Success.\n" ); |
1196 | |
1197 | return Py_None; |
1198 | } |
1199 | |
1200 | /* |
1201 | Test API: ompd_get_omp_version_string |
1202 | |
1203 | Program: |
1204 | 1. #include <stdio.h> |
1205 | 2. #include <omp.h> |
1206 | 3. int main () { |
1207 | 4. omp_set_num_threads(2); |
1208 | 5. #pragma omp parallel |
1209 | 6. { |
1210 | 7. printf("Parallel level 1, thread num = %d", |
1211 | omp_get_thread_num()); |
1212 | 8. } |
1213 | 9. return 0; |
1214 | 10. } |
1215 | |
1216 | GDB Commands: |
1217 | ompd init |
1218 | b 7 |
1219 | ompdtestapi ompd_get_omp_version_string |
1220 | */ |
1221 | PyObject *test_ompd_get_omp_version_string(PyObject *self, PyObject *args) { |
1222 | printf(format: "Testing \"ompd_get_omp_version_string\" ...\n" ); |
1223 | |
1224 | PyObject *addrSpaceTup = PyTuple_GetItem(args, 0); |
1225 | ompd_address_space_handle_t *addr_handle = |
1226 | (ompd_address_space_handle_t *)PyCapsule_GetPointer(capsule: addrSpaceTup, |
1227 | name: "AddressSpace" ); |
1228 | |
1229 | const char *string; |
1230 | |
1231 | printf(format: "Test: With Correct Arguments.\n" ); |
1232 | ompd_rc_t rc = ompd_get_omp_version_string(address_space: addr_handle, string: &string); |
1233 | if (rc != ompd_rc_ok) { |
1234 | printf(format: "Failed, with return code = %d\n" , rc); |
1235 | return Py_None; |
1236 | } else |
1237 | printf(format: "Success. API version is %s\n" , string); |
1238 | |
1239 | // Random checks with null and invalid args. |
1240 | /* |
1241 | ompd_rc_stale_handle: is returned when the specified handle is no |
1242 | longer valid; |
1243 | ompd_rc_bad_input: is returned when the input parameters |
1244 | (other than handle) are invalid; |
1245 | ompd_rc_error: is returned when a fatal error occurred; |
1246 | */ |
1247 | |
1248 | printf(format: "Test: Expecting stale handle or bad_input for NULL addr_handle.\n" ); |
1249 | rc = ompd_get_omp_version_string(NULL, string: &string); |
1250 | if ((rc != ompd_rc_bad_input) && (rc != ompd_rc_stale_handle)) |
1251 | printf(format: "Failed, with return code = %d\n" , rc); |
1252 | else |
1253 | printf(format: "Success.\n" ); |
1254 | |
1255 | printf(format: "Test: Expecting ompd_rc_error or bad_input for NULL omp_version.\n" ); |
1256 | rc = ompd_get_omp_version_string(address_space: addr_handle, NULL); |
1257 | if (rc != ompd_rc_error && rc != ompd_rc_bad_input) |
1258 | printf(format: "Failed, with return code = %d\n" , rc); |
1259 | else |
1260 | printf(format: "Success.\n" ); |
1261 | |
1262 | return Py_None; |
1263 | } |
1264 | |
1265 | /* |
1266 | Test API: ompd_get_curr_task_handle |
1267 | |
1268 | Program: |
1269 | 1 #include <stdio.h> |
1270 | 2 #include <omp.h> |
1271 | 3 int get_fib_num (int num) |
1272 | 4 { |
1273 | 5 int t1, t2; |
1274 | 6 if (num < 2) |
1275 | 7 return num; |
1276 | 8 else { |
1277 | 9 #pragma omp task shared(t1) |
1278 | 10 t1 = get_fib_num(num-1); |
1279 | 11 #pragma omp task shared(t2) |
1280 | 12 t2 = get_fib_num(num-2); |
1281 | 13 #pragma omp taskwait |
1282 | 14 return t1+t2; |
1283 | 15 } |
1284 | 16 } |
1285 | 17 |
1286 | 18 int main () { |
1287 | 19 int ret = 0; |
1288 | 20 omp_set_num_threads(2); |
1289 | 21 #pragma omp parallel |
1290 | 22 { |
1291 | 23 ret = get_fib_num(10); |
1292 | 24 } |
1293 | 25 printf ("Fib of 10 is %d", ret); |
1294 | 26 return 0; |
1295 | 27 } |
1296 | |
1297 | GDB Commands: |
1298 | ompd init |
1299 | b 10 |
1300 | c |
1301 | ompdtestapi ompd_get_curr_task_handle |
1302 | */ |
1303 | |
1304 | PyObject *test_ompd_get_curr_task_handle(PyObject *self, PyObject *args) { |
1305 | printf(format: "Testing \"ompd_get_curr_task_handle\"...\n" ); |
1306 | |
1307 | PyObject *threadHandlePy = PyTuple_GetItem(args, 0); |
1308 | ompd_thread_handle_t *thread_handle = |
1309 | (ompd_thread_handle_t *)(PyCapsule_GetPointer(capsule: threadHandlePy, |
1310 | name: "ThreadHandle" )); |
1311 | |
1312 | ompd_task_handle_t *task_handle; |
1313 | |
1314 | printf(format: "Test: With Correct Arguments.\n" ); |
1315 | ompd_rc_t rc = ompd_get_curr_task_handle(thread_handle, task_handle: &task_handle); |
1316 | if (rc == ompd_rc_unavailable) { |
1317 | // ompd_rc_unavailable if the thread is not currently executing a task |
1318 | |
1319 | printf( |
1320 | format: "Success. Return code is ompd_rc_unavailable, Not executing a task.\n" ); |
1321 | printf(format: "No more testing is possible.\n" ); |
1322 | return Py_None; |
1323 | } else if (rc == ompd_rc_stale_handle) { |
1324 | printf(format: "Return code is stale_handle, may be in non parallel region.\n" ); |
1325 | printf(format: "No more testing is possible.\n" ); |
1326 | return Py_None; |
1327 | } else if (rc != ompd_rc_ok) |
1328 | printf(format: "Failed. with return code = %d\n" , rc); |
1329 | else |
1330 | printf(format: "Success.\n" ); |
1331 | |
1332 | // Random checks with null and invalid args. |
1333 | /* |
1334 | ompd_rc_stale_handle: is returned when the specified handle is no |
1335 | longer valid; |
1336 | ompd_rc_bad_input: is returned when the input parameters |
1337 | (other than handle) are invalid; |
1338 | ompd_rc_error: is returned when a fatal error occurred; |
1339 | */ |
1340 | |
1341 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL parallel_handle.\n" ); |
1342 | rc = ompd_get_curr_task_handle(thread_handle, NULL); |
1343 | if (rc != ompd_rc_bad_input) |
1344 | printf(format: "Failed. with return code = %d\n" , rc); |
1345 | else |
1346 | printf(format: "Success.\n" ); |
1347 | |
1348 | printf(format: "Test: Expecting ompd_rc_error or stale_handle for NULL " |
1349 | "thread_handle.\n" ); |
1350 | rc = ompd_get_curr_task_handle(NULL, task_handle: &task_handle); |
1351 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
1352 | printf(format: "Failed. with return code = %d\n" , rc); |
1353 | else |
1354 | printf(format: "Success.\n" ); |
1355 | |
1356 | return Py_None; |
1357 | } |
1358 | |
1359 | /* |
1360 | Test API: ompd_get_task_parallel_handle |
1361 | |
1362 | Program: |
1363 | 1 #include <stdio.h> |
1364 | 2 #include <omp.h> |
1365 | 3 int get_fib_num (int num) |
1366 | 4 { |
1367 | 5 int t1, t2; |
1368 | 6 if (num < 2) |
1369 | 7 return num; |
1370 | 8 else { |
1371 | 9 #pragma omp task shared(t1) |
1372 | 10 t1 = get_fib_num(num-1); |
1373 | 11 #pragma omp task shared(t2) |
1374 | 12 t2 = get_fib_num(num-2); |
1375 | 13 #pragma omp taskwait |
1376 | 14 return t1+t2; |
1377 | 15 } |
1378 | 16 } |
1379 | 17 |
1380 | 18 int main () { |
1381 | 19 int ret = 0; |
1382 | 20 omp_set_num_threads(2); |
1383 | 21 #pragma omp parallel |
1384 | 22 { |
1385 | 23 ret = get_fib_num(10); |
1386 | 24 } |
1387 | 25 printf ("Fib of 10 is %d", ret); |
1388 | 26 return 0; |
1389 | 27 } |
1390 | |
1391 | GDB Commands: |
1392 | ompd init |
1393 | b 10 |
1394 | c |
1395 | ompdtestapi ompd_get_task_parallel_handle |
1396 | */ |
1397 | PyObject *test_ompd_get_task_parallel_handle(PyObject *self, PyObject *args) { |
1398 | |
1399 | printf(format: "Testing \"ompd_get_task_parallel_handle\"...\n" ); |
1400 | |
1401 | PyObject *taskHandlePy = PyTuple_GetItem(args, 0); |
1402 | ompd_task_handle_t *task_handle = |
1403 | PyCapsule_GetPointer(capsule: taskHandlePy, name: "TaskHandle" ); |
1404 | |
1405 | ompd_parallel_handle_t *task_parallel_handle; |
1406 | |
1407 | printf(format: "Test: With Correct Arguments.\n" ); |
1408 | ompd_rc_t rc = |
1409 | ompd_get_task_parallel_handle(task_handle, task_parallel_handle: &task_parallel_handle); |
1410 | if (rc != ompd_rc_ok) { |
1411 | printf(format: "Failed. with return code = %d\n" , rc); |
1412 | return Py_None; |
1413 | } else |
1414 | printf(format: "Success.\n" ); |
1415 | |
1416 | // Random checks with null and invalid args. |
1417 | /* |
1418 | ompd_rc_stale_handle: is returned when the specified handle is no |
1419 | longer valid; |
1420 | ompd_rc_bad_input: is returned when the input parameters |
1421 | (other than handle) are invalid; |
1422 | ompd_rc_error: is returned when a fatal error occurred; |
1423 | */ |
1424 | |
1425 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL task_parallel_handle.\n" ); |
1426 | rc = ompd_get_task_parallel_handle(task_handle, NULL); |
1427 | if (rc != ompd_rc_bad_input) |
1428 | printf(format: "Failed. with return code = %d\n" , rc); |
1429 | else |
1430 | printf(format: "Success.\n" ); |
1431 | |
1432 | printf( |
1433 | format: "Test: Expecting ompd_rc_error or stale_handle for NULL task_handle.\n" ); |
1434 | rc = ompd_get_task_parallel_handle(NULL, task_parallel_handle: &task_parallel_handle); |
1435 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
1436 | printf(format: "Failed. with return code = %d\n" , rc); |
1437 | else |
1438 | printf(format: "Success.\n" ); |
1439 | |
1440 | return Py_None; |
1441 | } |
1442 | |
1443 | /* |
1444 | Test API: ompd_get_generating_task_handle |
1445 | |
1446 | Program: |
1447 | 1 #include <stdio.h> |
1448 | 2 #include <omp.h> |
1449 | 3 int get_fib_num (int num) |
1450 | 4 { |
1451 | 5 int t1, t2; |
1452 | 6 if (num < 2) |
1453 | 7 return num; |
1454 | 8 else { |
1455 | 9 #pragma omp task shared(t1) |
1456 | 10 t1 = get_fib_num(num-1); |
1457 | 11 #pragma omp task shared(t2) |
1458 | 12 t2 = get_fib_num(num-2); |
1459 | 13 #pragma omp taskwait |
1460 | 14 return t1+t2; |
1461 | 15 } |
1462 | 16 } |
1463 | 17 |
1464 | 18 int main () { |
1465 | 19 int ret = 0; |
1466 | 20 omp_set_num_threads(2); |
1467 | 21 #pragma omp parallel |
1468 | 22 { |
1469 | 23 ret = get_fib_num(10); |
1470 | 24 } |
1471 | 25 printf ("Fib of 10 is %d", ret); |
1472 | 26 return 0; |
1473 | 27 } |
1474 | |
1475 | GDB Commands: |
1476 | ompd init |
1477 | b 10 |
1478 | c |
1479 | c // may or may not be needed |
1480 | ompdtestapi ompd_get_generating_task_handle |
1481 | */ |
1482 | PyObject *test_ompd_get_generating_task_handle(PyObject *self, PyObject *args) { |
1483 | printf(format: "Testing \"ompd_get_generating_task_handle\"...\n" ); |
1484 | |
1485 | PyObject *taskHandlePy = PyTuple_GetItem(args, 0); |
1486 | ompd_task_handle_t *task_handle = |
1487 | (ompd_task_handle_t *)(PyCapsule_GetPointer(capsule: taskHandlePy, name: "TaskHandle" )); |
1488 | ompd_task_handle_t *generating_task_handle; |
1489 | |
1490 | printf(format: "Test: With Correct Arguments.\n" ); |
1491 | ompd_rc_t rc = |
1492 | ompd_get_generating_task_handle(task_handle, generating_task_handle: &generating_task_handle); |
1493 | if (rc == ompd_rc_unavailable) { |
1494 | // ompd_rc_unavailable if no generating task handle exists. |
1495 | printf(format: "Success. Return code is ompd_rc_unavailable\n" ); |
1496 | printf(format: "No more testing is possible.\n" ); |
1497 | return Py_None; |
1498 | } else if (rc != ompd_rc_ok) { |
1499 | printf(format: "Failed. with return code = %d\n" , rc); |
1500 | return Py_None; |
1501 | } else |
1502 | printf(format: "Success.\n" ); |
1503 | |
1504 | // Random checks with null and invalid args. |
1505 | /* |
1506 | ompd_rc_stale_handle: is returned when the specified handle is no |
1507 | longer valid; |
1508 | ompd_rc_bad_input: is returned when the input parameters |
1509 | (other than handle) are invalid; |
1510 | ompd_rc_error: is returned when a fatal error occurred; |
1511 | */ |
1512 | |
1513 | printf( |
1514 | format: "Test: Expecting ompd_rc_bad_input for NULL generating_task_handle.\n" ); |
1515 | rc = ompd_get_generating_task_handle(task_handle, NULL); |
1516 | if (rc != ompd_rc_bad_input) |
1517 | printf(format: "Failed. with return code = %d\n" , rc); |
1518 | else |
1519 | printf(format: "Success.\n" ); |
1520 | |
1521 | printf( |
1522 | format: "Test: Expecting ompd_rc_error or stale_handle for NULL task_handle.\n" ); |
1523 | rc = ompd_get_generating_task_handle(NULL, generating_task_handle: &generating_task_handle); |
1524 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
1525 | printf(format: "Failed. with return code = %d\n" , rc); |
1526 | else |
1527 | printf(format: "Success.\n" ); |
1528 | |
1529 | return Py_None; |
1530 | } |
1531 | |
1532 | /* |
1533 | Test API: ompd_get_scheduling_task_handle |
1534 | |
1535 | Program: |
1536 | 1 #include <stdio.h> |
1537 | 2 #include <omp.h> |
1538 | 3 int get_fib_num (int num) |
1539 | 4 { |
1540 | 5 int t1, t2; |
1541 | 6 if (num < 2) |
1542 | 7 return num; |
1543 | 8 else { |
1544 | 9 #pragma omp task shared(t1) |
1545 | 10 t1 = get_fib_num(num-1); |
1546 | 11 #pragma omp task shared(t2) |
1547 | 12 t2 = get_fib_num(num-2); |
1548 | 13 #pragma omp taskwait |
1549 | 14 return t1+t2; |
1550 | 15 } |
1551 | 16 } |
1552 | 17 |
1553 | 18 int main () { |
1554 | 19 int ret = 0; |
1555 | 20 omp_set_num_threads(2); |
1556 | 21 #pragma omp parallel |
1557 | 22 { |
1558 | 23 ret = get_fib_num(10); |
1559 | 24 } |
1560 | 25 printf ("Fib of 10 is %d", ret); |
1561 | 26 return 0; |
1562 | 27 } |
1563 | |
1564 | GDB Commands: |
1565 | ompd init |
1566 | b 10 |
1567 | c |
1568 | ompdtestapi ompd_get_scheduling_task_handle |
1569 | */ |
1570 | PyObject *test_ompd_get_scheduling_task_handle(PyObject *self, PyObject *args) { |
1571 | printf(format: "Testing \"ompd_get_scheduling_task_handle\"...\n" ); |
1572 | |
1573 | PyObject *taskHandlePy = PyTuple_GetItem(args, 0); |
1574 | ompd_task_handle_t *task_handle = |
1575 | (ompd_task_handle_t *)(PyCapsule_GetPointer(capsule: taskHandlePy, name: "TaskHandle" )); |
1576 | ompd_task_handle_t *scheduling_task_handle; |
1577 | |
1578 | printf(format: "Test: With Correct Arguments.\n" ); |
1579 | ompd_rc_t rc = |
1580 | ompd_get_scheduling_task_handle(task_handle, scheduling_task_handle: &scheduling_task_handle); |
1581 | if (rc == ompd_rc_unavailable) { |
1582 | // ompd_rc_unavailable if no generating task handle exists. |
1583 | printf( |
1584 | format: "Success. Return code is ompd_rc_unavailable, No scheduling task.\n" ); |
1585 | printf(format: "No more testing is possible.\n" ); |
1586 | return Py_None; |
1587 | } else if (rc != ompd_rc_ok) { |
1588 | printf(format: "Failed. with return code = %d\n" , rc); |
1589 | return Py_None; |
1590 | } else |
1591 | printf(format: "Success.\n" ); |
1592 | |
1593 | // Random checks with null and invalid args. |
1594 | /* |
1595 | ompd_rc_stale_handle: is returned when the specified handle is no |
1596 | longer valid; |
1597 | ompd_rc_bad_input: is returned when the input parameters |
1598 | (other than handle) are invalid; |
1599 | ompd_rc_error: is returned when a fatal error occurred; |
1600 | */ |
1601 | |
1602 | printf( |
1603 | format: "Test: Expecting ompd_rc_bad_input for NULL scheduling_task_handle.\n" ); |
1604 | rc = ompd_get_scheduling_task_handle(task_handle, NULL); |
1605 | if (rc != ompd_rc_bad_input) |
1606 | printf(format: "Failed. with return code = %d\n" , rc); |
1607 | else |
1608 | printf(format: "Success.\n" ); |
1609 | |
1610 | printf( |
1611 | format: "Test: Expecting ompd_rc_error or stale_handle for NULL task_handle.\n" ); |
1612 | rc = ompd_get_scheduling_task_handle(NULL, scheduling_task_handle: &scheduling_task_handle); |
1613 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
1614 | printf(format: "Failed. with return code = %d\n" , rc); |
1615 | else |
1616 | printf(format: "Success.\n" ); |
1617 | |
1618 | return Py_None; |
1619 | } |
1620 | |
1621 | /* |
1622 | Test API: ompd_get_task_in_parallel |
1623 | |
1624 | Program: |
1625 | Program: |
1626 | 1. #include <stdio.h> |
1627 | 2. #include <omp.h> |
1628 | 3. int main () { |
1629 | 4. omp_set_num_threads(4); |
1630 | 5. #pragma omp parallel |
1631 | 6. { |
1632 | 7. printf("Parallel level 1, thread num = %d", |
1633 | omp_get_thread_num()); |
1634 | 8. } |
1635 | 9. return 0; |
1636 | 10. } |
1637 | |
1638 | GDB Commands: |
1639 | ompd init |
1640 | b 7 |
1641 | c |
1642 | ompdtestapi ompd_get_task_in_parallel |
1643 | */ |
1644 | PyObject *test_ompd_get_task_in_parallel(PyObject *self, PyObject *args) { |
1645 | printf(format: "Testing \"ompd_get_task_in_parallel\"...\n" ); |
1646 | |
1647 | PyObject *parallelHandlePy = PyTuple_GetItem(args, 0); |
1648 | ompd_parallel_handle_t *parallel_handle = |
1649 | (ompd_parallel_handle_t *)(PyCapsule_GetPointer(capsule: parallelHandlePy, |
1650 | name: "ParallelHandle" )); |
1651 | ompd_task_handle_t *task_handle; |
1652 | |
1653 | printf(format: "Test: With Correct Arguments.\n" ); |
1654 | ompd_rc_t rc = ompd_get_task_in_parallel( |
1655 | parallel_handle, thread_num: 1 /* lesser than team-size-var*/, task_handle: &task_handle); |
1656 | if (rc != ompd_rc_ok) { |
1657 | printf(format: "Failed. with return code = %d\n" , rc); |
1658 | return Py_None; |
1659 | } else |
1660 | printf(format: "Success.\n" ); |
1661 | |
1662 | // ompd_rc_bad_input if the thread_num argument is greater than or equal to |
1663 | // the team-size-var ICV or negative |
1664 | printf(format: "Test: Invalid thread num (199).\n" ); |
1665 | rc = ompd_get_task_in_parallel(parallel_handle, thread_num: 199, task_handle: &task_handle); |
1666 | if (rc != ompd_rc_bad_input) |
1667 | printf(format: "Failed. with return code = %d\n" , rc); |
1668 | else |
1669 | printf(format: "Success.\n" ); |
1670 | |
1671 | printf(format: "Test: Invalid thread num (-5).\n" ); |
1672 | rc = ompd_get_task_in_parallel(parallel_handle, thread_num: -5, task_handle: &task_handle); |
1673 | if (rc != ompd_rc_bad_input) |
1674 | printf(format: "Failed. with return code = %d\n" , rc); |
1675 | else |
1676 | printf(format: "Success.\n" ); |
1677 | |
1678 | // Random checks with null and invalid args. |
1679 | /* |
1680 | ompd_rc_stale_handle: is returned when the specified handle is no |
1681 | longer valid; |
1682 | ompd_rc_bad_input: is returned when the input parameters |
1683 | (other than handle) are invalid; |
1684 | ompd_rc_error: is returned when a fatal error occurred; |
1685 | */ |
1686 | |
1687 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL task_handle.\n" ); |
1688 | rc = ompd_get_task_in_parallel(parallel_handle, thread_num: 1, NULL); |
1689 | if (rc != ompd_rc_bad_input) |
1690 | printf(format: "Failed. with return code = %d\n" , rc); |
1691 | else |
1692 | printf(format: "Success.\n" ); |
1693 | |
1694 | printf(format: "Test: Expecting ompd_rc_error or stale_handle for NULL " |
1695 | "parallel_handle.\n" ); |
1696 | rc = ompd_get_task_in_parallel(NULL, thread_num: 1, task_handle: &task_handle); |
1697 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
1698 | printf(format: "Failed. with return code = %d\n" , rc); |
1699 | else |
1700 | printf(format: "Success.\n" ); |
1701 | |
1702 | return Py_None; |
1703 | } |
1704 | |
1705 | /* |
1706 | Test API: ompd_rel_task_handle |
1707 | |
1708 | Program: |
1709 | 1 #include <stdio.h> |
1710 | 2 #include <omp.h> |
1711 | 3 int get_fib_num (int num) |
1712 | 4 { |
1713 | 5 int t1, t2; |
1714 | 6 if (num < 2) |
1715 | 7 return num; |
1716 | 8 else { |
1717 | 9 #pragma omp task shared(t1) |
1718 | 10 t1 = get_fib_num(num-1); |
1719 | 11 #pragma omp task shared(t2) |
1720 | 12 t2 = get_fib_num(num-2); |
1721 | 13 #pragma omp taskwait |
1722 | 14 return t1+t2; |
1723 | 15 } |
1724 | 16 } |
1725 | 17 |
1726 | 18 int main () { |
1727 | 19 int ret = 0; |
1728 | 20 omp_set_num_threads(2); |
1729 | 21 #pragma omp parallel |
1730 | 22 { |
1731 | 23 ret = get_fib_num(10); |
1732 | 24 } |
1733 | 25 printf ("Fib of 10 is %d", ret); |
1734 | 26 return 0; |
1735 | 27 } |
1736 | |
1737 | GDB Commands: |
1738 | ompd init |
1739 | b 10 |
1740 | c |
1741 | ompdtestapi ompd_rel_task_handle |
1742 | */ |
1743 | PyObject *test_ompd_rel_task_handle(PyObject *self, PyObject *noargs) { |
1744 | printf(format: "Testing Not enabled for \"ompd_rel_task_handle\".\n" ); |
1745 | printf(format: "Disabled.\n" ); |
1746 | |
1747 | return Py_None; |
1748 | } |
1749 | |
1750 | /* |
1751 | Test API: ompd_task_handle_compare |
1752 | |
1753 | Program: |
1754 | 1 #include <stdio.h> |
1755 | 2 #include <omp.h> |
1756 | 3 int get_fib_num (int num) |
1757 | 4 { |
1758 | 5 int t1, t2; |
1759 | 6 if (num < 2) |
1760 | 7 return num; |
1761 | 8 else { |
1762 | 9 #pragma omp task shared(t1) |
1763 | 10 t1 = get_fib_num(num-1); |
1764 | 11 #pragma omp task shared(t2) |
1765 | 12 t2 = get_fib_num(num-2); |
1766 | 13 #pragma omp taskwait |
1767 | 14 return t1+t2; |
1768 | 15 } |
1769 | 16 } |
1770 | 17 |
1771 | 18 int main () { |
1772 | 19 int ret = 0; |
1773 | 20 omp_set_num_threads(2); |
1774 | 21 #pragma omp parallel |
1775 | 22 { |
1776 | 23 ret = get_fib_num(10); |
1777 | 24 } |
1778 | 25 printf ("Fib of 10 is %d", ret); |
1779 | 26 return 0; |
1780 | 27 } |
1781 | |
1782 | GDB Commands: |
1783 | ompd init |
1784 | b 10 |
1785 | c |
1786 | c |
1787 | ompdtestapi ompd_task_handle_compare |
1788 | */ |
1789 | PyObject *test_ompd_task_handle_compare(PyObject *self, PyObject *args) { |
1790 | printf(format: "Testing \"ompd_task_handle_compare\"...\n" ); |
1791 | |
1792 | PyObject *taskHandlePy1 = PyTuple_GetItem(args, 0); |
1793 | ompd_task_handle_t *task_handle1 = |
1794 | (ompd_task_handle_t *)(PyCapsule_GetPointer(capsule: taskHandlePy1, name: "TaskHandle" )); |
1795 | PyObject *taskHandlePy2 = PyTuple_GetItem(args, 1); |
1796 | ompd_task_handle_t *task_handle2 = |
1797 | (ompd_task_handle_t *)(PyCapsule_GetPointer(capsule: taskHandlePy2, name: "TaskHandle" )); |
1798 | |
1799 | int cmp_value; |
1800 | |
1801 | printf(format: "Test: With Correct Arguments.\n" ); |
1802 | ompd_rc_t rc = |
1803 | ompd_task_handle_compare(task_handle_1: task_handle1, task_handle_2: task_handle2, cmp_value: &cmp_value); |
1804 | if (rc != ompd_rc_ok) { |
1805 | printf(format: "Failed. with return code = %d\n" , rc); |
1806 | return Py_None; |
1807 | } else |
1808 | printf(format: "Success.\n" ); |
1809 | |
1810 | if (cmp_value == 0) { |
1811 | printf(format: "Task Handles are Same.\n" ); |
1812 | } else { |
1813 | // a value less than, equal to, or greater than 0 indicates that the task |
1814 | // that corresponds to task_handle_1 is, respectively, less than, equal to, |
1815 | // or greater than the task that corresponds to task_handle_2. |
1816 | if (cmp_value <= 0) { |
1817 | printf(format: "Task handle 1 is lesser than handle 2, cmp_val = %d\n" , |
1818 | cmp_value); |
1819 | printf(format: "Test: Changing the order.\n" ); |
1820 | rc = ompd_task_handle_compare(task_handle_1: task_handle2, task_handle_2: task_handle1, cmp_value: &cmp_value); |
1821 | if (rc != ompd_rc_ok) { |
1822 | printf(format: "Failed. with return code = %d\n" , rc); |
1823 | return Py_None; |
1824 | } |
1825 | if (cmp_value >= 0) |
1826 | printf(format: "Success now cmp_value is greater, %d.\n" , cmp_value); |
1827 | else |
1828 | printf(format: "Failed.\n" ); |
1829 | } else { |
1830 | printf(format: "Task 1 is greater than handle 2.\n" ); |
1831 | printf(format: "Test: Changing the order.\n" ); |
1832 | rc = ompd_task_handle_compare(task_handle_1: task_handle2, task_handle_2: task_handle1, cmp_value: &cmp_value); |
1833 | if (rc != ompd_rc_ok) { |
1834 | printf(format: "Failed. with return code = %d\n" , rc); |
1835 | return Py_None; |
1836 | } |
1837 | if (cmp_value <= 0) |
1838 | printf(format: "Success now cmp_value is lesser, %d.\n" , cmp_value); |
1839 | else |
1840 | printf(format: "Failed.\n" ); |
1841 | } |
1842 | |
1843 | // Random checks with null and invalid args. |
1844 | /* |
1845 | ompd_rc_stale_handle: is returned when the specified handle is no |
1846 | longer valid; |
1847 | ompd_rc_bad_input: is returned when the input parameters |
1848 | (other than handle) are invalid; |
1849 | ompd_rc_error: is returned when a fatal error occurred; |
1850 | */ |
1851 | |
1852 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL cmp_value.\n" ); |
1853 | rc = ompd_task_handle_compare(task_handle_1: task_handle2, task_handle_2: task_handle1, NULL); |
1854 | if (rc != ompd_rc_bad_input) |
1855 | printf(format: "Failed. with return code = %d\n" , rc); |
1856 | else |
1857 | printf(format: "Success.\n" ); |
1858 | |
1859 | printf(format: "Test: Expecting ompd_rc_error or stale_handle for NULL " |
1860 | "task_handle.\n" ); |
1861 | rc = ompd_task_handle_compare(NULL, task_handle_2: task_handle1, cmp_value: &cmp_value); |
1862 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
1863 | printf(format: "Failed. with return code = %d\n" , rc); |
1864 | else |
1865 | printf(format: "Success.\n" ); |
1866 | } |
1867 | |
1868 | return Py_None; |
1869 | } |
1870 | |
1871 | /* |
1872 | Test API: ompd_get_task_function |
1873 | |
1874 | Program: |
1875 | 1 #include <stdio.h> |
1876 | 2 #include <omp.h> |
1877 | 3 int get_fib_num (int num) |
1878 | 4 { |
1879 | 5 int t1, t2; |
1880 | 6 if (num < 2) |
1881 | 7 return num; |
1882 | 8 else { |
1883 | 9 #pragma omp task shared(t1) |
1884 | 10 t1 = get_fib_num(num-1); |
1885 | 11 #pragma omp task shared(t2) |
1886 | 12 t2 = get_fib_num(num-2); |
1887 | 13 #pragma omp taskwait |
1888 | 14 return t1+t2; |
1889 | 15 } |
1890 | 16 } |
1891 | 17 |
1892 | 18 int main () { |
1893 | 19 int ret = 0; |
1894 | 20 omp_set_num_threads(2); |
1895 | 21 #pragma omp parallel |
1896 | 22 { |
1897 | 23 ret = get_fib_num(10); |
1898 | 24 } |
1899 | 25 printf ("Fib of 10 is %d", ret); |
1900 | 26 return 0; |
1901 | 27 } |
1902 | |
1903 | GDB Commands: |
1904 | ompd init |
1905 | b 10 |
1906 | c |
1907 | ompdtestapi ompd_get_task_function |
1908 | */ |
1909 | PyObject *test_ompd_get_task_function(PyObject *self, PyObject *args) { |
1910 | printf(format: "Testing \"ompd_get_task_function\"...\n" ); |
1911 | |
1912 | PyObject *taskHandlePy = PyTuple_GetItem(args, 0); |
1913 | ompd_task_handle_t *task_handle = |
1914 | (ompd_task_handle_t *)(PyCapsule_GetPointer(capsule: taskHandlePy, name: "TaskHandle" )); |
1915 | |
1916 | ompd_address_t entry_point; |
1917 | |
1918 | printf(format: "Test: With Correct Arguments.\n" ); |
1919 | ompd_rc_t rc = ompd_get_task_function(task_handle, entry_point: &entry_point); |
1920 | if (rc != ompd_rc_ok) { |
1921 | printf(format: "Failed. with return code = %d\n" , rc); |
1922 | return Py_None; |
1923 | } else |
1924 | printf(format: "Success. Entry point is %lx.\n" , entry_point.address); |
1925 | |
1926 | // Random checks with null and invalid args. |
1927 | /* |
1928 | ompd_rc_stale_handle: is returned when the specified handle is no |
1929 | longer valid; |
1930 | ompd_rc_bad_input: is returned when the input parameters |
1931 | (other than handle) are invalid; |
1932 | ompd_rc_error: is returned when a fatal error occurred; |
1933 | */ |
1934 | |
1935 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL entry_point.\n" ); |
1936 | rc = ompd_get_task_function(task_handle, NULL); |
1937 | if (rc != ompd_rc_bad_input) |
1938 | printf(format: "Failed. with return code = %d\n" , rc); |
1939 | else |
1940 | printf(format: "Success.\n" ); |
1941 | |
1942 | printf( |
1943 | format: "Test: Expecting ompd_rc_error or stale_handle for NULL task_handle.\n" ); |
1944 | rc = ompd_get_task_function(NULL, entry_point: &entry_point); |
1945 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
1946 | printf(format: "Failed. with return code = %d\n" , rc); |
1947 | else |
1948 | printf(format: "Success.\n" ); |
1949 | |
1950 | return Py_None; |
1951 | } |
1952 | |
1953 | /* |
1954 | Test API: ompd_get_task_frame |
1955 | |
1956 | Program: |
1957 | 1 #include <stdio.h> |
1958 | 2 #include <omp.h> |
1959 | 3 int get_fib_num (int num) |
1960 | 4 { |
1961 | 5 int t1, t2; |
1962 | 6 if (num < 2) |
1963 | 7 return num; |
1964 | 8 else { |
1965 | 9 #pragma omp task shared(t1) |
1966 | 10 t1 = get_fib_num(num-1); |
1967 | 11 #pragma omp task shared(t2) |
1968 | 12 t2 = get_fib_num(num-2); |
1969 | 13 #pragma omp taskwait |
1970 | 14 return t1+t2; |
1971 | 15 } |
1972 | 16 } |
1973 | 17 |
1974 | 18 int main () { |
1975 | 19 int ret = 0; |
1976 | 20 omp_set_num_threads(2); |
1977 | 21 #pragma omp parallel |
1978 | 22 { |
1979 | 23 ret = get_fib_num(10); |
1980 | 24 } |
1981 | 25 printf ("Fib of 10 is %d", ret); |
1982 | 26 return 0; |
1983 | 27 } |
1984 | |
1985 | GDB Commands: |
1986 | ompd init |
1987 | b 10 |
1988 | c |
1989 | ompdtestapi ompd_get_task_frame |
1990 | */ |
1991 | PyObject *test_ompd_get_task_frame(PyObject *self, PyObject *args) { |
1992 | printf(format: "Testing \"ompd_get_task_frame\"...\n" ); |
1993 | |
1994 | PyObject *taskHandlePy = PyTuple_GetItem(args, 0); |
1995 | ompd_task_handle_t *task_handle = |
1996 | (ompd_task_handle_t *)(PyCapsule_GetPointer(capsule: taskHandlePy, name: "TaskHandle" )); |
1997 | |
1998 | ompd_frame_info_t exit_frame; |
1999 | ompd_frame_info_t enter_frame; |
2000 | |
2001 | printf(format: "Test: With Correct Arguments.\n" ); |
2002 | ompd_rc_t rc = ompd_get_task_frame(task_handle, exit_frame: &exit_frame, enter_frame: &enter_frame); |
2003 | if (rc != ompd_rc_ok) { |
2004 | printf(format: "Failed. with return code = %d\n" , rc); |
2005 | return Py_None; |
2006 | } else |
2007 | printf(format: "Success.\n" ); |
2008 | |
2009 | // Random checks with null and invalid args. |
2010 | /* |
2011 | ompd_rc_stale_handle: is returned when the specified handle is no |
2012 | longer valid; |
2013 | ompd_rc_bad_input: is returned when the input parameters |
2014 | (other than handle) are invalid; |
2015 | ompd_rc_error: is returned when a fatal error occurred; |
2016 | */ |
2017 | |
2018 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL exit and enter frame.\n" ); |
2019 | rc = ompd_get_task_frame(task_handle, NULL, NULL); |
2020 | if (rc != ompd_rc_bad_input) |
2021 | printf(format: "Failed. with return code = %d\n" , rc); |
2022 | else |
2023 | printf(format: "Success.\n" ); |
2024 | |
2025 | printf( |
2026 | format: "Test: Expecting ompd_rc_error or stale handle for NULL task_handle.\n" ); |
2027 | rc = ompd_get_task_frame(NULL, exit_frame: &exit_frame, enter_frame: &enter_frame); |
2028 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
2029 | printf(format: "Failed. with return code = %d\n" , rc); |
2030 | else |
2031 | printf(format: "Success.\n" ); |
2032 | |
2033 | return Py_None; |
2034 | } |
2035 | |
2036 | /* |
2037 | Test API: ompd_get_state |
2038 | |
2039 | Program: |
2040 | Program: |
2041 | 1. #include <stdio.h> |
2042 | 2. #include <omp.h> |
2043 | 3. int main () { |
2044 | 4. omp_set_num_threads(4); |
2045 | 5. #pragma omp parallel |
2046 | 6. { |
2047 | 7. printf("Parallel level 1, thread num = %d", |
2048 | omp_get_thread_num()); |
2049 | 8. } |
2050 | 9. return 0; |
2051 | 10. } |
2052 | |
2053 | GDB Commands: |
2054 | ompd init |
2055 | b 7 |
2056 | c |
2057 | ompdtestapi ompd_get_state |
2058 | */ |
2059 | PyObject *test_ompd_get_state(PyObject *self, PyObject *args) { |
2060 | printf(format: "Testing \"ompd_get_state\"...\n" ); |
2061 | |
2062 | PyObject *threadHandlePy = PyTuple_GetItem(args, 0); |
2063 | ompd_thread_handle_t *thread_handle = |
2064 | (ompd_thread_handle_t *)(PyCapsule_GetPointer(capsule: threadHandlePy, |
2065 | name: "ThreadHandle" )); |
2066 | |
2067 | ompd_word_t state; |
2068 | ompt_wait_id_t wait_id; |
2069 | |
2070 | printf(format: "Test: With Correct Arguments.\n" ); |
2071 | ompd_rc_t rc = ompd_get_state(thread_handle, state: &state, wait_id: &wait_id); |
2072 | if (rc != ompd_rc_ok) { |
2073 | printf(format: "Failed. with return code = %d\n" , rc); |
2074 | return Py_None; |
2075 | } else |
2076 | printf(format: "Success.\n" ); |
2077 | |
2078 | // Random checks with null and invalid args. |
2079 | /* |
2080 | ompd_rc_stale_handle: is returned when the specified handle is no |
2081 | longer valid; |
2082 | ompd_rc_bad_input: is returned when the input parameters |
2083 | (other than handle) are invalid; |
2084 | ompd_rc_error: is returned when a fatal error occurred; |
2085 | */ |
2086 | |
2087 | printf(format: "Test: Expecting ompd_rc_error or stale handle for NULL " |
2088 | "thread_handle.\n" ); |
2089 | rc = ompd_get_state(NULL, state: &state, wait_id: &wait_id); |
2090 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
2091 | printf(format: "Failed. with return code = %d\n" , rc); |
2092 | else |
2093 | printf(format: "Success.\n" ); |
2094 | |
2095 | return Py_None; |
2096 | } |
2097 | |
2098 | /* |
2099 | Test API: ompd_get_display_control_vars |
2100 | |
2101 | Program: |
2102 | 1 #include <stdio.h> |
2103 | 2 #include <omp.h> |
2104 | 3 int get_fib_num (int num) |
2105 | 4 { |
2106 | 5 int t1, t2; |
2107 | 6 if (num < 2) |
2108 | 7 return num; |
2109 | 8 else { |
2110 | 9 #pragma omp task shared(t1) |
2111 | 10 t1 = get_fib_num(num-1); |
2112 | 11 #pragma omp task shared(t2) |
2113 | 12 t2 = get_fib_num(num-2); |
2114 | 13 #pragma omp taskwait |
2115 | 14 return t1+t2; |
2116 | 15 } |
2117 | 16 } |
2118 | 17 |
2119 | 18 int main () { |
2120 | 19 int ret = 0; |
2121 | 20 omp_set_num_threads(2); |
2122 | 21 #pragma omp parallel |
2123 | 22 { |
2124 | 23 ret = get_fib_num(10); |
2125 | 24 } |
2126 | 25 printf ("Fib of 10 is %d", ret); |
2127 | 26 return 0; |
2128 | 27 } |
2129 | |
2130 | GDB Commands: |
2131 | ompd init |
2132 | b 10 |
2133 | c |
2134 | ompdtestapi ompd_get_display_control_vars |
2135 | */ |
2136 | PyObject *test_ompd_get_display_control_vars(PyObject *self, PyObject *args) { |
2137 | printf(format: "Testing \"ompd_get_display_control_vars\" ...\n" ); |
2138 | |
2139 | PyObject *addrSpaceTup = PyTuple_GetItem(args, 0); |
2140 | ompd_address_space_handle_t *addr_handle = |
2141 | (ompd_address_space_handle_t *)PyCapsule_GetPointer(capsule: addrSpaceTup, |
2142 | name: "AddressSpace" ); |
2143 | |
2144 | const char *const *control_vars; |
2145 | |
2146 | printf(format: "Test: With Correct Arguments.\n" ); |
2147 | ompd_rc_t rc = ompd_get_display_control_vars(address_space_handle: addr_handle, control_vars: &control_vars); |
2148 | if (rc != ompd_rc_ok) { |
2149 | printf(format: "Failed. with return code = %d\n" , rc); |
2150 | return Py_None; |
2151 | } else |
2152 | printf(format: "Success.\n" ); |
2153 | |
2154 | // Random checks with null and invalid args. |
2155 | /* |
2156 | ompd_rc_stale_handle: is returned when the specified handle is no |
2157 | longer valid; |
2158 | ompd_rc_bad_input: is returned when the input parameters |
2159 | (other than handle) are invalid; |
2160 | ompd_rc_error: is returned when a fatal error occurred; |
2161 | */ |
2162 | |
2163 | printf(format: "Test: Expecting stale handle or bad_input for NULL addr_handle.\n" ); |
2164 | rc = ompd_get_display_control_vars(NULL, control_vars: &control_vars); |
2165 | if ((rc != ompd_rc_bad_input) && (rc != ompd_rc_stale_handle)) |
2166 | printf(format: "Failed. with return code = %d\n" , rc); |
2167 | else |
2168 | printf(format: "Success.\n" ); |
2169 | |
2170 | printf(format: "Test: Expecting ompd_rc_error or bad_input for NULL control_vars.\n" ); |
2171 | rc = ompd_get_display_control_vars(address_space_handle: addr_handle, NULL); |
2172 | if (rc != ompd_rc_error && rc != ompd_rc_bad_input) |
2173 | printf(format: "Failed. with return code = %d\n" , rc); |
2174 | else |
2175 | printf(format: "Success.\n" ); |
2176 | |
2177 | return Py_None; |
2178 | } |
2179 | |
2180 | /* |
2181 | Test API: ompd_rel_display_control_vars |
2182 | |
2183 | Program: |
2184 | 1 #include <stdio.h> |
2185 | 2 #include <omp.h> |
2186 | 3 int get_fib_num (int num) |
2187 | 4 { |
2188 | 5 int t1, t2; |
2189 | 6 if (num < 2) |
2190 | 7 return num; |
2191 | 8 else { |
2192 | 9 #pragma omp task shared(t1) |
2193 | 10 t1 = get_fib_num(num-1); |
2194 | 11 #pragma omp task shared(t2) |
2195 | 12 t2 = get_fib_num(num-2); |
2196 | 13 #pragma omp taskwait |
2197 | 14 return t1+t2; |
2198 | 15 } |
2199 | 16 } |
2200 | 17 |
2201 | 18 int main () { |
2202 | 19 int ret = 0; |
2203 | 20 omp_set_num_threads(2); |
2204 | 21 #pragma omp parallel |
2205 | 22 { |
2206 | 23 ret = get_fib_num(10); |
2207 | 24 } |
2208 | 25 printf ("Fib of 10 is %d", ret); |
2209 | 26 return 0; |
2210 | 27 } |
2211 | |
2212 | GDB Commands: |
2213 | ompd init |
2214 | b 10 |
2215 | c |
2216 | ompdtestapi ompd_rel_display_control_vars |
2217 | */ |
2218 | PyObject *test_ompd_rel_display_control_vars(PyObject *self, PyObject *noargs) { |
2219 | printf(format: "Testing Not enabled for \"ompd_rel_display_control_vars\".\n" ); |
2220 | printf(format: "Disabled.\n" ); |
2221 | |
2222 | return Py_None; |
2223 | } |
2224 | |
2225 | /* |
2226 | Test API: ompd_enumerate_icvs |
2227 | |
2228 | Program: |
2229 | Program: |
2230 | 1. #include <stdio.h> |
2231 | 2. #include <omp.h> |
2232 | 3. int main () { |
2233 | 4. omp_set_num_threads(2); |
2234 | 5. #pragma omp parallel |
2235 | 6. { |
2236 | 7. printf("Parallel level 1, thread num = %d", |
2237 | omp_get_thread_num()); |
2238 | 8. } |
2239 | 9. return 0; |
2240 | 10. } |
2241 | |
2242 | GDB Commands: |
2243 | ompd init |
2244 | b 7 |
2245 | c |
2246 | ompdtestapi ompd_enumerate_icvs |
2247 | */ |
2248 | |
2249 | PyObject *test_ompd_enumerate_icvs(PyObject *self, PyObject *args) { |
2250 | printf(format: "Testing \"ompd_enumerate_icvs\"...\n" ); |
2251 | |
2252 | PyObject *addrSpaceTup = PyTuple_GetItem(args, 0); |
2253 | ompd_address_space_handle_t *addr_handle = |
2254 | (ompd_address_space_handle_t *)PyCapsule_GetPointer(capsule: addrSpaceTup, |
2255 | name: "AddressSpace" ); |
2256 | |
2257 | ompd_icv_id_t current = 0; // To begin enumerating the ICVs, a tool should |
2258 | // pass ompd_icv_undefined as the value of current |
2259 | ompd_icv_id_t next_id; |
2260 | const char *next_icv_name; |
2261 | ompd_scope_t next_scope; |
2262 | int more; |
2263 | |
2264 | printf(format: "Test: With Correct Arguments.\n" ); |
2265 | ompd_rc_t rc = ompd_enumerate_icvs(handle: addr_handle, current, next_id: &next_id, |
2266 | next_icv_name: &next_icv_name, next_scope: &next_scope, more: &more); |
2267 | if (rc != ompd_rc_ok) { |
2268 | printf(format: "Failed. with return code = %d\n" , rc); |
2269 | return Py_None; |
2270 | } else |
2271 | printf(format: "Success.\n" ); |
2272 | |
2273 | // ompd_rc_bad_input if an unknown value is provided in current |
2274 | printf(format: "Test: Unknown current value.\n" ); |
2275 | rc = ompd_enumerate_icvs( |
2276 | handle: addr_handle, |
2277 | current: 99 /*unknown current value: greater than enum "ompd_icvompd_icv" */, |
2278 | next_id: &next_id, next_icv_name: &next_icv_name, next_scope: &next_scope, more: &more); |
2279 | if (rc != ompd_rc_bad_input) |
2280 | printf(format: "Failed. with return code = %d\n" , rc); |
2281 | else |
2282 | printf(format: "Success.\n" ); |
2283 | |
2284 | // Random checks with null and invalid args. |
2285 | /* |
2286 | ompd_rc_stale_handle: is returned when the specified handle is no |
2287 | longer valid; |
2288 | ompd_rc_bad_input: is returned when the input parameters |
2289 | (other than handle) are invalid; |
2290 | ompd_rc_error: is returned when a fatal error occurred; |
2291 | */ |
2292 | |
2293 | printf( |
2294 | format: "Test: Expecting ompd_rc_bad_input for NULL next_id and next_icv_name\n" ); |
2295 | rc = |
2296 | ompd_enumerate_icvs(handle: addr_handle, current, NULL, NULL, next_scope: &next_scope, more: &more); |
2297 | if (rc != ompd_rc_bad_input) |
2298 | printf(format: "Failed. with return code = %d\n" , rc); |
2299 | else |
2300 | printf(format: "Success.\n" ); |
2301 | |
2302 | printf( |
2303 | format: "Test: Expecting ompd_rc_error or stale_handle for NULL addr_handle.\n" ); |
2304 | rc = ompd_enumerate_icvs(NULL, current, next_id: &next_id, next_icv_name: &next_icv_name, next_scope: &next_scope, |
2305 | more: &more); |
2306 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
2307 | printf(format: "Failed. with return code = %d\n" , rc); |
2308 | else |
2309 | printf(format: "Success.\n" ); |
2310 | |
2311 | return Py_None; |
2312 | } |
2313 | |
2314 | /* |
2315 | Test API: ompd_get_icv_from_scope |
2316 | |
2317 | Program: |
2318 | 1 #include <stdio.h> |
2319 | 2 #include <omp.h> |
2320 | 3 int get_fib_num (int num) |
2321 | 4 { |
2322 | 5 int t1, t2; |
2323 | 6 if (num < 2) |
2324 | 7 return num; |
2325 | 8 else { |
2326 | 9 #pragma omp task shared(t1) |
2327 | 10 t1 = get_fib_num(num-1); |
2328 | 11 #pragma omp task shared(t2) |
2329 | 12 t2 = get_fib_num(num-2); |
2330 | 13 #pragma omp taskwait |
2331 | 14 return t1+t2; |
2332 | 15 } |
2333 | 16 } |
2334 | 17 |
2335 | 18 int main () { |
2336 | 19 int ret = 0; |
2337 | 20 omp_set_num_threads(2); |
2338 | 21 #pragma omp parallel |
2339 | 22 { |
2340 | 23 ret = get_fib_num(10); |
2341 | 24 } |
2342 | 25 printf ("Fib of 10 is %d", ret); |
2343 | 26 return 0; |
2344 | 27 } |
2345 | |
2346 | GDB Commands: |
2347 | ompd init |
2348 | b 10 |
2349 | c |
2350 | ompdtestapi ompd_get_icv_from_scope |
2351 | */ |
2352 | PyObject *test_ompd_get_icv_from_scope_with_addr_handle(PyObject *self, |
2353 | PyObject *args) { |
2354 | printf(format: "Testing \"ompd_get_icv_from_scope with addr_handle\"...\n" ); |
2355 | |
2356 | PyObject *addrSpaceTup = PyTuple_GetItem(args, 0); |
2357 | ompd_address_space_handle_t *addr_handle = |
2358 | (ompd_address_space_handle_t *)PyCapsule_GetPointer(capsule: addrSpaceTup, |
2359 | name: "AddressSpace" ); |
2360 | |
2361 | ompd_word_t icv_value; |
2362 | |
2363 | printf(format: "Test: With Correct Arguments.\n" ); |
2364 | // cannot import enum ompd_icv from omp-icv.cpp, hardcoding as of now, if enum |
2365 | // changes it also requires modification |
2366 | ompd_rc_t rc = ompd_get_icv_from_scope( |
2367 | handle: addr_handle, scope: ompd_scope_address_space, |
2368 | icv_id: 19 /* ompd_icv_num_procs_var: check enum ompd_icv in omp-icv.cpp */, |
2369 | icv_value: &icv_value); |
2370 | if (rc != ompd_rc_ok) { |
2371 | printf(format: "Failed. with return code = %d\n" , rc); |
2372 | return Py_None; |
2373 | } else |
2374 | printf(format: "Success.\n" ); |
2375 | |
2376 | // ompd_rc_bad_input if an unknown value is provided in icv_id. |
2377 | printf(format: "Test: bad_input for unknown icv_id.\n" ); |
2378 | rc = ompd_get_icv_from_scope(handle: addr_handle, scope: ompd_scope_address_space, |
2379 | icv_id: 99 /*wrong value*/, icv_value: &icv_value); |
2380 | if (rc != ompd_rc_bad_input) |
2381 | printf(format: "Failed. with return code = %d\n" , rc); |
2382 | else |
2383 | printf(format: "Success.\n" ); |
2384 | |
2385 | // ompd_rc_incompatible if the ICV cannot be represented as an integer; |
2386 | printf(format: "Test: rc_incompatible for ICV that cant be represented as an " |
2387 | "integer.\n" ); |
2388 | rc = ompd_get_icv_from_scope(handle: addr_handle, scope: ompd_scope_address_space, |
2389 | icv_id: 12 /*ompd_icv_tool_libraries_var*/, icv_value: &icv_value); |
2390 | if (rc != ompd_rc_incompatible) |
2391 | printf(format: "Failed. with return code = %d\n" , rc); |
2392 | else |
2393 | printf(format: "Success.\n" ); |
2394 | |
2395 | // Random checks with null and invalid args. |
2396 | /* |
2397 | ompd_rc_stale_handle: is returned when the specified handle is no |
2398 | longer valid; |
2399 | ompd_rc_bad_input: is returned when the input parameters |
2400 | (other than handle) are invalid; |
2401 | ompd_rc_error: is returned when a fatal error occurred; |
2402 | */ |
2403 | |
2404 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL icv_value.\n" ); |
2405 | rc = ompd_get_icv_from_scope(handle: addr_handle, scope: ompd_scope_address_space, |
2406 | icv_id: 19 /*ompd_icv_num_procs_var*/, NULL); |
2407 | if (rc != ompd_rc_bad_input) |
2408 | printf(format: "Failed. with return code = %d\n" , rc); |
2409 | else |
2410 | printf(format: "Success.\n" ); |
2411 | |
2412 | printf(format: "Test: Expecting ompd_rc_error for NULL handle.\n" ); |
2413 | rc = ompd_get_icv_from_scope(NULL, scope: ompd_scope_address_space, |
2414 | icv_id: 19 /*ompd_icv_num_procs_var*/, icv_value: &icv_value); |
2415 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
2416 | printf(format: "Failed. with return code = %d\n" , rc); |
2417 | else |
2418 | printf(format: "Success.\n" ); |
2419 | |
2420 | return Py_None; |
2421 | } |
2422 | |
2423 | PyObject *test_ompd_get_icv_from_scope_with_thread_handle(PyObject *self, |
2424 | PyObject *args) { |
2425 | printf(format: "Testing \"ompd_get_icv_from_scope with thread_handle\"...\n" ); |
2426 | |
2427 | PyObject *threadHandlePy = PyTuple_GetItem(args, 0); |
2428 | ompd_thread_handle_t *thread_handle = |
2429 | (ompd_thread_handle_t *)(PyCapsule_GetPointer(capsule: threadHandlePy, |
2430 | name: "ThreadHandle" )); |
2431 | |
2432 | ompd_word_t icv_value; |
2433 | |
2434 | printf(format: "Test: With Correct Arguments.\n" ); |
2435 | ompd_rc_t rc = ompd_get_icv_from_scope( |
2436 | handle: thread_handle, scope: ompd_scope_thread, |
2437 | icv_id: 22 /* ompd_icv_thread_num_var check enum ompd_icv in omp-icv.cpp */, |
2438 | icv_value: &icv_value); |
2439 | if (rc != ompd_rc_ok) { |
2440 | printf(format: "Failed. with return code = %d\n" , rc); |
2441 | return Py_None; |
2442 | } else |
2443 | printf(format: "Success.\n" ); |
2444 | |
2445 | printf(format: "Test: with nthreads_var for ompd_rc_incomplete.\n" ); |
2446 | rc = ompd_get_icv_from_scope(handle: thread_handle, scope: ompd_scope_thread, |
2447 | icv_id: 7 /*ompd_icv_nthreads_var*/, icv_value: &icv_value); |
2448 | if (rc != ompd_rc_incomplete) { |
2449 | printf(format: "Failed. with return code = %d\n" , rc); |
2450 | return Py_None; |
2451 | } else |
2452 | printf(format: "Success.\n" ); |
2453 | |
2454 | return Py_None; |
2455 | } |
2456 | |
2457 | PyObject *test_ompd_get_icv_from_scope_with_parallel_handle(PyObject *self, |
2458 | PyObject *args) { |
2459 | printf(format: "Testing \"ompd_get_icv_from_scope with parallel_handle\"...\n" ); |
2460 | |
2461 | PyObject *parallelHandlePy = PyTuple_GetItem(args, 0); |
2462 | ompd_parallel_handle_t *parallel_handle = |
2463 | (ompd_parallel_handle_t *)(PyCapsule_GetPointer(capsule: parallelHandlePy, |
2464 | name: "ParallelHandle" )); |
2465 | |
2466 | ompd_word_t icv_value; |
2467 | |
2468 | printf(format: "Test: With Correct Arguments.\n" ); |
2469 | ompd_rc_t rc = ompd_get_icv_from_scope( |
2470 | handle: parallel_handle, scope: ompd_scope_parallel, |
2471 | icv_id: 15 /*ompd_icv_active_levels_var:check enum ompd_icv in omp-icv.cpp */, |
2472 | icv_value: &icv_value); |
2473 | if (rc != ompd_rc_ok) { |
2474 | printf(format: "Failed. with return code = %d\n" , rc); |
2475 | return Py_None; |
2476 | } else |
2477 | printf(format: "Success.\n" ); |
2478 | |
2479 | return Py_None; |
2480 | } |
2481 | |
2482 | PyObject *test_ompd_get_icv_from_scope_with_task_handle(PyObject *self, |
2483 | PyObject *args) { |
2484 | printf(format: "Testing \"ompd_get_icv_from_scope with task_handle\"...\n" ); |
2485 | |
2486 | PyObject *taskHandlePy = PyTuple_GetItem(args, 0); |
2487 | ompd_task_handle_t *task_handle = |
2488 | (ompd_task_handle_t *)(PyCapsule_GetPointer(capsule: taskHandlePy, name: "TaskHandle" )); |
2489 | |
2490 | ompd_word_t icv_value; |
2491 | |
2492 | printf(format: "Test: With Correct Arguments.\n" ); |
2493 | ompd_rc_t rc = ompd_get_icv_from_scope( |
2494 | handle: task_handle, scope: ompd_scope_task, |
2495 | icv_id: 16 /*ompd_icv_thread_limit_var: check enum ompd_icv in omp-icv.cpp */, |
2496 | icv_value: &icv_value); |
2497 | if (rc != ompd_rc_ok) { |
2498 | printf(format: "Failed. with return code = %d\n" , rc); |
2499 | return Py_None; |
2500 | } else |
2501 | printf(format: "Success.\n" ); |
2502 | |
2503 | return Py_None; |
2504 | } |
2505 | /* |
2506 | Test API: ompd_get_icv_string_from_scope |
2507 | |
2508 | Program: |
2509 | 1. #include <stdio.h> |
2510 | 2. #include <omp.h> |
2511 | 3. int main () { |
2512 | 4. omp_set_num_threads(4); |
2513 | 5. #pragma omp parallel |
2514 | 6. { |
2515 | 7. printf("Parallel level 1, thread num = %d", |
2516 | omp_get_thread_num()); |
2517 | 8. } |
2518 | 9. return 0; |
2519 | 10. } |
2520 | |
2521 | GDB Commands: |
2522 | ompd init |
2523 | b 7 |
2524 | c |
2525 | ompdtestapi ompd_get_icv_string_from_scope |
2526 | */ |
2527 | PyObject *test_ompd_get_icv_string_from_scope(PyObject *self, PyObject *args) { |
2528 | printf(format: "Testing \"ompd_get_icv_string_from_scope\"...\n" ); |
2529 | |
2530 | PyObject *addrSpaceTup = PyTuple_GetItem(args, 0); |
2531 | ompd_address_space_handle_t *addr_handle = |
2532 | (ompd_address_space_handle_t *)PyCapsule_GetPointer(capsule: addrSpaceTup, |
2533 | name: "AddressSpace" ); |
2534 | |
2535 | const char *icv_string; |
2536 | |
2537 | printf(format: "Test: With Correct Arguments.\n" ); |
2538 | ompd_rc_t rc = ompd_get_icv_string_from_scope( |
2539 | handle: addr_handle, scope: ompd_scope_address_space, |
2540 | icv_id: 12 /*ompd_icv_tool_libraries_var: check enum ompd_icv in omp-icv.cpp */, |
2541 | icv_string: &icv_string); |
2542 | if (rc != ompd_rc_ok) { |
2543 | printf(format: "Failed. with return code = %d\n" , rc); |
2544 | return Py_None; |
2545 | } else |
2546 | printf(format: "Success.\n" ); |
2547 | |
2548 | // ompd_rc_bad_input if an unknown value is provided in icv_id. |
2549 | printf(format: "Test: bad_input for unknown icv_id.\n" ); |
2550 | rc = ompd_get_icv_string_from_scope(handle: addr_handle, scope: ompd_scope_address_space, |
2551 | icv_id: 99 /*wrong value*/, icv_string: &icv_string); |
2552 | if (rc != ompd_rc_bad_input) |
2553 | printf(format: "Failed. with return code = %d\n" , rc); |
2554 | else |
2555 | printf(format: "Success.\n" ); |
2556 | |
2557 | // Random checks with null and invalid args. |
2558 | /* |
2559 | ompd_rc_stale_handle: is returned when the specified handle is no |
2560 | longer valid; |
2561 | ompd_rc_bad_input: is returned when the input parameters |
2562 | (other than handle) are invalid; |
2563 | ompd_rc_error: is returned when a fatal error occurred; |
2564 | */ |
2565 | |
2566 | printf(format: "Test: Expecting ompd_rc_bad_input for NULL icv_string.\n" ); |
2567 | rc = ompd_get_icv_string_from_scope(handle: addr_handle, scope: ompd_scope_address_space, |
2568 | icv_id: 12 /*ompd_icv_tool_libraries_var*/, NULL); |
2569 | if (rc != ompd_rc_bad_input) |
2570 | printf(format: "Failed. with return code = %d\n" , rc); |
2571 | else |
2572 | printf(format: "Success.\n" ); |
2573 | |
2574 | printf(format: "Test: Expecting ompd_rc_error for NULL handle.\n" ); |
2575 | rc = ompd_get_icv_string_from_scope(NULL, scope: ompd_scope_address_space, |
2576 | icv_id: 12 /*ompd_icv_tool_libraries_var*/, |
2577 | icv_string: &icv_string); |
2578 | if (rc != ompd_rc_error && rc != ompd_rc_stale_handle) |
2579 | printf(format: "Failed. with return code = %d\n" , rc); |
2580 | else |
2581 | printf(format: "Success.\n" ); |
2582 | |
2583 | return Py_None; |
2584 | } |
2585 | |
2586 | PyObject *test_ompd_get_tool_data(PyObject *self, PyObject *args) { |
2587 | printf(format: "Disabled: Testing Not enabled for \"ompd_get_tool_data\".\n" ); |
2588 | |
2589 | return Py_None; |
2590 | } |
2591 | PyObject *test_ompd_enumerate_states(PyObject *self, PyObject *args) { |
2592 | printf(format: "Disabled: Testing Not enabled for \"ompd_enumerate_states\".\n" ); |
2593 | |
2594 | return Py_None; |
2595 | } |
2596 | |