#include <Python.h> #include <dlfcn.h> #include <errno.h> #include <omp-tools.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <string.h> extern void *ompd_library; struct _ompd_aspace_cont { … }; struct _ompd_thread_cont { … }; ompd_address_space_context_t context = …; ompd_address_space_context_t invalidcontext = …; // call back functions for ompd_initialize ompd_rc_t _alloc(ompd_size_t bytes, void **ptr); ompd_rc_t _free(void *ptr); ompd_rc_t _sizes(ompd_address_space_context_t *_acontext, ompd_device_type_sizes_t *sizes); ompd_rc_t _sym_addr(ompd_address_space_context_t *context, ompd_thread_context_t *tcontext, const char *symbol_name, ompd_address_t *symbol_addr, const char *file_name); ompd_rc_t _read(ompd_address_space_context_t *context, ompd_thread_context_t *tcontext, const ompd_address_t *addr, ompd_size_t nbytes, void *buffer); ompd_rc_t _read_string(ompd_address_space_context_t *context, ompd_thread_context_t *tcontext, const ompd_address_t *addr, ompd_size_t nbytes, void *buffer); ompd_rc_t _endianess(ompd_address_space_context_t *address_space_context, const void *input, ompd_size_t unit_size, ompd_size_t count, void *output); ompd_rc_t _thread_context(ompd_address_space_context_t *context, ompd_thread_id_t kind, ompd_size_t sizeof_thread_id, const void *thread_id, ompd_thread_context_t **thread_context); ompd_rc_t _print(const char *str, int category); /* Test API: ompd_get_thread_handle ompdtestapi threadandparallel Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 c ompdtestapi ompd_get_thread_handle for ompd_rc_unavailable: ompd init ompdtestapi ompd_get_thread_handle */ PyObject *test_ompd_get_thread_handle(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_curr_parallel_handle. Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 omptestapi ompd_get_curr_parallel_handle for ompd_rc_unavailable ompd init omptestapi ompd_get_curr_parallel_handle (or break at line 4 before this) */ PyObject *test_ompd_get_curr_parallel_handle(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_thread_in_parallel. Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(3); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 omptestapi ompd_get_thread_in_parallel */ PyObject *test_ompd_get_thread_in_parallel(PyObject *self, PyObject *args) { … } /* Test API: ompd_thread_handle_compare. Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(4); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 omptestapi ompd_thread_handle_compare */ PyObject *test_ompd_thread_handle_compare(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_thread_id. Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 omptestapi ompd_get_thread_id */ PyObject *test_ompd_get_thread_id(PyObject *self, PyObject *args) { … } /* Test API: ompd_rel_thread_handle Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 omptestapi ompd_rel_thread_handle */ // TODO: This might not be the right way to do,as this handle comes from // python not generated by ompd API PyObject *test_ompd_rel_thread_handle(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_enclosing_parallel_handle. Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. omp_set_num_threads(3); 9. #pragma omp parallel 10. { 11. printf ("Parallel level 2, thread num = %d", omp_get_thread_num()); 12. } 13. } 14. return 0; 15. } GDB Commands: ompd init b 11 ompdtestapi ompd_get_enclosing_parallel_handle for "ompd_rc_unavailable": ompd init omptestapi ompd_get_enclosing_parallel_handle (or break at line 4 before this) */ PyObject *test_ompd_get_enclosing_parallel_handle(PyObject *self, PyObject *args) { … } /* Test API: ompd_parallel_handle_compare. Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. omp_set_num_threads(3); 9. #pragma omp parallel 10. { 11. printf ("Parallel level 2, thread num = %d", omp_get_thread_num()); 12. } 13. } 14. return 0; 15. } GDB Commands: ompd init b 11 ompdtestapi ompd_parallel_handle_compare */ PyObject *test_ompd_parallel_handle_compare(PyObject *self, PyObject *args) { … } /* Test API: ompd_rel_parallel_handle Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 omptestapi ompd_rel_parallel_handle */ // TODO: Same as thread_rel_handle, might not be a right way to test // What released should be provided by ompd API, this address is actually from // python PyObject *test_ompd_rel_parallel_handle(PyObject *self, PyObject *args) { … } /* Test API: ompd_initialize Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: b 4 ompdtestapi ompd_initialize\ */ PyObject *test_ompd_initialize(PyObject *self, PyObject *noargs) { … } /* Test API: ompd_get_api_version Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 ompdtestapi ompd_get_version */ PyObject *test_ompd_get_api_version(PyObject *self, PyObject *noargs) { … } /* Test API: ompd_get_version_string Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 omptestapi ompd_get_version_string */ PyObject *test_ompd_get_version_string(PyObject *self, PyObject *noargs) { … } /* Test API: ompd_finalize Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 ompdtestapi ompd_finalize b 4 r ompdtestapi ompd_finalize */ PyObject *test_ompd_finalize(PyObject *self, PyObject *noargs) { … } /* Test API: ompd_process_initialize Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: */ PyObject *test_ompd_process_initialize(PyObject *self, PyObject *noargs) { … } /* Test API: ompd_device_initialize Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: */ PyObject *test_ompd_device_initialize(PyObject *self, PyObject *noargs) { … } /* Test API: ompd_rel_address_space_handle Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: */ PyObject *test_ompd_rel_address_space_handle(PyObject *self, PyObject *noargs) { … } /* Test API: ompd_get_omp_version Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 10 c ompdtestapi ompd_get_omp_version */ PyObject *test_ompd_get_omp_version(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_omp_version_string Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 ompdtestapi ompd_get_omp_version_string */ PyObject *test_ompd_get_omp_version_string(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_curr_task_handle Program: 1 #include <stdio.h> 2 #include <omp.h> 3 int get_fib_num (int num) 4 { 5 int t1, t2; 6 if (num < 2) 7 return num; 8 else { 9 #pragma omp task shared(t1) 10 t1 = get_fib_num(num-1); 11 #pragma omp task shared(t2) 12 t2 = get_fib_num(num-2); 13 #pragma omp taskwait 14 return t1+t2; 15 } 16 } 17 18 int main () { 19 int ret = 0; 20 omp_set_num_threads(2); 21 #pragma omp parallel 22 { 23 ret = get_fib_num(10); 24 } 25 printf ("Fib of 10 is %d", ret); 26 return 0; 27 } GDB Commands: ompd init b 10 c ompdtestapi ompd_get_curr_task_handle */ PyObject *test_ompd_get_curr_task_handle(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_task_parallel_handle Program: 1 #include <stdio.h> 2 #include <omp.h> 3 int get_fib_num (int num) 4 { 5 int t1, t2; 6 if (num < 2) 7 return num; 8 else { 9 #pragma omp task shared(t1) 10 t1 = get_fib_num(num-1); 11 #pragma omp task shared(t2) 12 t2 = get_fib_num(num-2); 13 #pragma omp taskwait 14 return t1+t2; 15 } 16 } 17 18 int main () { 19 int ret = 0; 20 omp_set_num_threads(2); 21 #pragma omp parallel 22 { 23 ret = get_fib_num(10); 24 } 25 printf ("Fib of 10 is %d", ret); 26 return 0; 27 } GDB Commands: ompd init b 10 c ompdtestapi ompd_get_task_parallel_handle */ PyObject *test_ompd_get_task_parallel_handle(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_generating_task_handle Program: 1 #include <stdio.h> 2 #include <omp.h> 3 int get_fib_num (int num) 4 { 5 int t1, t2; 6 if (num < 2) 7 return num; 8 else { 9 #pragma omp task shared(t1) 10 t1 = get_fib_num(num-1); 11 #pragma omp task shared(t2) 12 t2 = get_fib_num(num-2); 13 #pragma omp taskwait 14 return t1+t2; 15 } 16 } 17 18 int main () { 19 int ret = 0; 20 omp_set_num_threads(2); 21 #pragma omp parallel 22 { 23 ret = get_fib_num(10); 24 } 25 printf ("Fib of 10 is %d", ret); 26 return 0; 27 } GDB Commands: ompd init b 10 c c // may or may not be needed ompdtestapi ompd_get_generating_task_handle */ PyObject *test_ompd_get_generating_task_handle(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_scheduling_task_handle Program: 1 #include <stdio.h> 2 #include <omp.h> 3 int get_fib_num (int num) 4 { 5 int t1, t2; 6 if (num < 2) 7 return num; 8 else { 9 #pragma omp task shared(t1) 10 t1 = get_fib_num(num-1); 11 #pragma omp task shared(t2) 12 t2 = get_fib_num(num-2); 13 #pragma omp taskwait 14 return t1+t2; 15 } 16 } 17 18 int main () { 19 int ret = 0; 20 omp_set_num_threads(2); 21 #pragma omp parallel 22 { 23 ret = get_fib_num(10); 24 } 25 printf ("Fib of 10 is %d", ret); 26 return 0; 27 } GDB Commands: ompd init b 10 c ompdtestapi ompd_get_scheduling_task_handle */ PyObject *test_ompd_get_scheduling_task_handle(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_task_in_parallel Program: Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(4); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 c ompdtestapi ompd_get_task_in_parallel */ PyObject *test_ompd_get_task_in_parallel(PyObject *self, PyObject *args) { … } /* Test API: ompd_rel_task_handle Program: 1 #include <stdio.h> 2 #include <omp.h> 3 int get_fib_num (int num) 4 { 5 int t1, t2; 6 if (num < 2) 7 return num; 8 else { 9 #pragma omp task shared(t1) 10 t1 = get_fib_num(num-1); 11 #pragma omp task shared(t2) 12 t2 = get_fib_num(num-2); 13 #pragma omp taskwait 14 return t1+t2; 15 } 16 } 17 18 int main () { 19 int ret = 0; 20 omp_set_num_threads(2); 21 #pragma omp parallel 22 { 23 ret = get_fib_num(10); 24 } 25 printf ("Fib of 10 is %d", ret); 26 return 0; 27 } GDB Commands: ompd init b 10 c ompdtestapi ompd_rel_task_handle */ PyObject *test_ompd_rel_task_handle(PyObject *self, PyObject *noargs) { … } /* Test API: ompd_task_handle_compare Program: 1 #include <stdio.h> 2 #include <omp.h> 3 int get_fib_num (int num) 4 { 5 int t1, t2; 6 if (num < 2) 7 return num; 8 else { 9 #pragma omp task shared(t1) 10 t1 = get_fib_num(num-1); 11 #pragma omp task shared(t2) 12 t2 = get_fib_num(num-2); 13 #pragma omp taskwait 14 return t1+t2; 15 } 16 } 17 18 int main () { 19 int ret = 0; 20 omp_set_num_threads(2); 21 #pragma omp parallel 22 { 23 ret = get_fib_num(10); 24 } 25 printf ("Fib of 10 is %d", ret); 26 return 0; 27 } GDB Commands: ompd init b 10 c c ompdtestapi ompd_task_handle_compare */ PyObject *test_ompd_task_handle_compare(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_task_function Program: 1 #include <stdio.h> 2 #include <omp.h> 3 int get_fib_num (int num) 4 { 5 int t1, t2; 6 if (num < 2) 7 return num; 8 else { 9 #pragma omp task shared(t1) 10 t1 = get_fib_num(num-1); 11 #pragma omp task shared(t2) 12 t2 = get_fib_num(num-2); 13 #pragma omp taskwait 14 return t1+t2; 15 } 16 } 17 18 int main () { 19 int ret = 0; 20 omp_set_num_threads(2); 21 #pragma omp parallel 22 { 23 ret = get_fib_num(10); 24 } 25 printf ("Fib of 10 is %d", ret); 26 return 0; 27 } GDB Commands: ompd init b 10 c ompdtestapi ompd_get_task_function */ PyObject *test_ompd_get_task_function(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_task_frame Program: 1 #include <stdio.h> 2 #include <omp.h> 3 int get_fib_num (int num) 4 { 5 int t1, t2; 6 if (num < 2) 7 return num; 8 else { 9 #pragma omp task shared(t1) 10 t1 = get_fib_num(num-1); 11 #pragma omp task shared(t2) 12 t2 = get_fib_num(num-2); 13 #pragma omp taskwait 14 return t1+t2; 15 } 16 } 17 18 int main () { 19 int ret = 0; 20 omp_set_num_threads(2); 21 #pragma omp parallel 22 { 23 ret = get_fib_num(10); 24 } 25 printf ("Fib of 10 is %d", ret); 26 return 0; 27 } GDB Commands: ompd init b 10 c ompdtestapi ompd_get_task_frame */ PyObject *test_ompd_get_task_frame(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_state Program: Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(4); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 c ompdtestapi ompd_get_state */ PyObject *test_ompd_get_state(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_display_control_vars Program: 1 #include <stdio.h> 2 #include <omp.h> 3 int get_fib_num (int num) 4 { 5 int t1, t2; 6 if (num < 2) 7 return num; 8 else { 9 #pragma omp task shared(t1) 10 t1 = get_fib_num(num-1); 11 #pragma omp task shared(t2) 12 t2 = get_fib_num(num-2); 13 #pragma omp taskwait 14 return t1+t2; 15 } 16 } 17 18 int main () { 19 int ret = 0; 20 omp_set_num_threads(2); 21 #pragma omp parallel 22 { 23 ret = get_fib_num(10); 24 } 25 printf ("Fib of 10 is %d", ret); 26 return 0; 27 } GDB Commands: ompd init b 10 c ompdtestapi ompd_get_display_control_vars */ PyObject *test_ompd_get_display_control_vars(PyObject *self, PyObject *args) { … } /* Test API: ompd_rel_display_control_vars Program: 1 #include <stdio.h> 2 #include <omp.h> 3 int get_fib_num (int num) 4 { 5 int t1, t2; 6 if (num < 2) 7 return num; 8 else { 9 #pragma omp task shared(t1) 10 t1 = get_fib_num(num-1); 11 #pragma omp task shared(t2) 12 t2 = get_fib_num(num-2); 13 #pragma omp taskwait 14 return t1+t2; 15 } 16 } 17 18 int main () { 19 int ret = 0; 20 omp_set_num_threads(2); 21 #pragma omp parallel 22 { 23 ret = get_fib_num(10); 24 } 25 printf ("Fib of 10 is %d", ret); 26 return 0; 27 } GDB Commands: ompd init b 10 c ompdtestapi ompd_rel_display_control_vars */ PyObject *test_ompd_rel_display_control_vars(PyObject *self, PyObject *noargs) { … } /* Test API: ompd_enumerate_icvs Program: Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(2); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 c ompdtestapi ompd_enumerate_icvs */ PyObject *test_ompd_enumerate_icvs(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_icv_from_scope Program: 1 #include <stdio.h> 2 #include <omp.h> 3 int get_fib_num (int num) 4 { 5 int t1, t2; 6 if (num < 2) 7 return num; 8 else { 9 #pragma omp task shared(t1) 10 t1 = get_fib_num(num-1); 11 #pragma omp task shared(t2) 12 t2 = get_fib_num(num-2); 13 #pragma omp taskwait 14 return t1+t2; 15 } 16 } 17 18 int main () { 19 int ret = 0; 20 omp_set_num_threads(2); 21 #pragma omp parallel 22 { 23 ret = get_fib_num(10); 24 } 25 printf ("Fib of 10 is %d", ret); 26 return 0; 27 } GDB Commands: ompd init b 10 c ompdtestapi ompd_get_icv_from_scope */ PyObject *test_ompd_get_icv_from_scope_with_addr_handle(PyObject *self, PyObject *args) { … } PyObject *test_ompd_get_icv_from_scope_with_thread_handle(PyObject *self, PyObject *args) { … } PyObject *test_ompd_get_icv_from_scope_with_parallel_handle(PyObject *self, PyObject *args) { … } PyObject *test_ompd_get_icv_from_scope_with_task_handle(PyObject *self, PyObject *args) { … } /* Test API: ompd_get_icv_string_from_scope Program: 1. #include <stdio.h> 2. #include <omp.h> 3. int main () { 4. omp_set_num_threads(4); 5. #pragma omp parallel 6. { 7. printf("Parallel level 1, thread num = %d", omp_get_thread_num()); 8. } 9. return 0; 10. } GDB Commands: ompd init b 7 c ompdtestapi ompd_get_icv_string_from_scope */ PyObject *test_ompd_get_icv_string_from_scope(PyObject *self, PyObject *args) { … } PyObject *test_ompd_get_tool_data(PyObject *self, PyObject *args) { … } PyObject *test_ompd_enumerate_states(PyObject *self, PyObject *args) { … }