| 1 |
import ompdModule |
| 2 |
|
| 3 |
|
| 4 |
class ompd_parallel(object): |
| 5 |
def __init__(self, parallel_handle): |
| 6 |
"""Initializes an ompd_parallel object with the pointer |
| 7 |
to a handle of a parallel region.""" |
| 8 |
self.parallel_handle = parallel_handle |
| 9 |
self.threads = {} |
| 10 |
self.itasks = {} |
| 11 |
self.enclosing_parallel_handle = None |
| 12 |
self.enclosing_parallel = False |
| 13 |
self.task_handle = None |
| 14 |
|
| 15 |
def get_thread_in_parallel(self, thread_num): |
| 16 |
"""Obtains thread handles for the threads associated with the |
| 17 |
parallel region specified by parallel_handle.""" |
| 18 |
if not thread_num in self.threads: |
| 19 |
thread_handle = ompdModule.call_ompd_get_thread_in_parallel( |
| 20 |
self.parallel_handle, thread_num |
| 21 |
) |
| 22 |
self.threads[thread_num] = ompd_thread(thread_handle) |
| 23 |
return self.threads[thread_num] |
| 24 |
|
| 25 |
def get_enclosing_parallel_handle(self): |
| 26 |
"""Obtains a parallel handle for the parallel region enclosing |
| 27 |
the parallel region specified by parallel_handle.""" |
| 28 |
if not self.enclosing_parallel_handle: |
| 29 |
self.enclosing_parallel_handle = ( |
| 30 |
ompdModule.call_ompd_get_enclosing_parallel_handle(self.parallel_handle) |
| 31 |
) |
| 32 |
return self.enclosing_parallel_handle |
| 33 |
|
| 34 |
def get_enclosing_parallel(self): |
| 35 |
if not self.enclosing_parallel: |
| 36 |
self.enclosing_parallel = ompd_parallel( |
| 37 |
self.get_enclosing_parallel_handle() |
| 38 |
) |
| 39 |
return self.enclosing_parallel |
| 40 |
|
| 41 |
def get_task_in_parallel(self, thread_num): |
| 42 |
"""Obtains handles for the implicit tasks associated with the |
| 43 |
parallel region specified by parallel_handle.""" |
| 44 |
if not thread_num in self.itasks: |
| 45 |
task_handle = ompdModule.call_ompd_get_task_in_parallel( |
| 46 |
self.parallel_handle, thread_num |
| 47 |
) |
| 48 |
self.itasks[thread_num] = ompd_task(task_handle) |
| 49 |
return self.itasks[thread_num] |
| 50 |
|
| 51 |
def __del__(self): |
| 52 |
"""Releases the parallel handle.""" |
| 53 |
pass # let capsule destructors do the job |
| 54 |
|
| 55 |
|
| 56 |
class ompd_task(object): |
| 57 |
def __init__(self, task_handle): |
| 58 |
"""Initializes a new ompd_task_handle object and sets the attribute |
| 59 |
to the task handle specified.""" |
| 60 |
self.task_handle = task_handle |
| 61 |
self.task_parallel_handle = False |
| 62 |
self.generating_task_handle = False |
| 63 |
self.scheduling_task_handle = False |
| 64 |
self.task_parallel = False |
| 65 |
self.generating_task = False |
| 66 |
self.scheduling_task = False |
| 67 |
self.task_frames = None |
| 68 |
self.task_frame_flags = None |
| 69 |
|
| 70 |
def get_task_parallel_handle(self): |
| 71 |
"""Obtains a task parallel handle for the parallel region enclosing |
| 72 |
the task region specified.""" |
| 73 |
if not self.task_parallel_handle: |
| 74 |
self.task_parallel_handle = ompdModule.call_ompd_get_task_parallel_handle( |
| 75 |
self.task_handle |
| 76 |
) |
| 77 |
return self.task_parallel_handle |
| 78 |
|
| 79 |
def get_task_parallel(self): |
| 80 |
if not self.task_parallel: |
| 81 |
self.task_parallel = ompd_parallel(self.get_task_parallel_handle()) |
| 82 |
return self.task_parallel |
| 83 |
|
| 84 |
def get_generating_task_handle(self): |
| 85 |
"""Obtains the task handle for the task that created the task specified |
| 86 |
by the task handle.""" |
| 87 |
if not self.generating_task_handle: |
| 88 |
self.generating_task_handle = ( |
| 89 |
ompdModule.call_ompd_get_generating_task_handle(self.task_handle) |
| 90 |
) |
| 91 |
return self.generating_task_handle |
| 92 |
|
| 93 |
def get_generating_task(self): |
| 94 |
if not self.generating_task: |
| 95 |
self.generating_task = ompd_task( |
| 96 |
ompdModule.call_ompd_get_generating_task_handle(self.task_handle) |
| 97 |
) |
| 98 |
return self.generating_task |
| 99 |
|
| 100 |
def get_scheduling_task_handle(self): |
| 101 |
"""Obtains the task handle for the task that scheduled the task specified.""" |
| 102 |
if not self.scheduling_task_handle: |
| 103 |
self.scheduling_task_handle = ( |
| 104 |
ompdModule.call_ompd_get_scheduling_task_handle(self.task_handle) |
| 105 |
) |
| 106 |
return self.scheduling_task_handle |
| 107 |
|
| 108 |
def get_scheduling_task(self): |
| 109 |
"""Returns ompd_task object for the task that scheduled the current task.""" |
| 110 |
if not self.scheduling_task: |
| 111 |
self.scheduling_task = ompd_task(self.get_scheduling_task_handle()) |
| 112 |
return self.scheduling_task |
| 113 |
|
| 114 |
def get_task_function(self): |
| 115 |
"""Returns long with address of function entry point.""" |
| 116 |
return ompdModule.call_ompd_get_task_function(self.task_handle) |
| 117 |
|
| 118 |
def get_task_frame_with_flags(self): |
| 119 |
"""Returns enter frame address and flag, exit frame address and flag for current task handle.""" |
| 120 |
if self.task_frames is None or self.task_frame_flags is None: |
| 121 |
ret_value = ompdModule.call_ompd_get_task_frame(self.task_handle) |
| 122 |
if isinstance(ret_value, tuple): |
| 123 |
self.task_frames = (ret_value[0], ret_value[2]) |
| 124 |
self.task_frame_flags = (ret_value[1], ret_value[3]) |
| 125 |
else: |
| 126 |
return ret_value |
| 127 |
return ( |
| 128 |
self.task_frames[0], |
| 129 |
self.task_frame_flags[0], |
| 130 |
self.task_frames[1], |
| 131 |
self.task_frame_flags[1], |
| 132 |
) |
| 133 |
|
| 134 |
def get_task_frame(self): |
| 135 |
"""Returns enter and exit frame address for current task handle.""" |
| 136 |
if self.task_frames is None: |
| 137 |
ret_value = ompdModule.call_ompd_get_task_frame(self.task_handle) |
| 138 |
if isinstance(ret_value, tuple): |
| 139 |
self.task_frames = (ret_value[0], ret_value[2]) |
| 140 |
else: |
| 141 |
return ret_value |
| 142 |
return self.task_frames |
| 143 |
|
| 144 |
def __del__(self): |
| 145 |
"""Releases the task handle.""" |
| 146 |
pass # let capsule destructors do the job |
| 147 |
|
| 148 |
|
| 149 |
class ompd_thread(object): |
| 150 |
def __init__(self, thread_handle): |
| 151 |
"""Initializes an ompd_thread with the data received from |
| 152 |
GDB.""" |
| 153 |
self.thread_handle = thread_handle |
| 154 |
self.parallel_handle = None |
| 155 |
self.task_handle = None |
| 156 |
self.current_task = False |
| 157 |
self.current_parallel = False |
| 158 |
self.thread_id = False |
| 159 |
|
| 160 |
def get_current_parallel_handle(self): |
| 161 |
"""Obtains the parallel handle for the parallel region associated with |
| 162 |
the given thread handle.""" |
| 163 |
# TODO: invalidate thread objects based on `gdb.event.cont`. This should invalidate all internal state. |
| 164 |
self.parallel_handle = ompdModule.call_ompd_get_curr_parallel_handle( |
| 165 |
self.thread_handle |
| 166 |
) |
| 167 |
return self.parallel_handle |
| 168 |
|
| 169 |
def get_current_parallel(self): |
| 170 |
"""Returns parallel object for parallel handle of the parallel region |
| 171 |
associated with the current thread handle.""" |
| 172 |
if not self.current_parallel: |
| 173 |
self.current_parallel = ompd_parallel(self.get_current_parallel_handle()) |
| 174 |
return self.current_parallel |
| 175 |
|
| 176 |
def get_current_task_handle(self): |
| 177 |
"""Obtains the task handle for the current task region of the |
| 178 |
given thread.""" |
| 179 |
return ompdModule.call_ompd_get_curr_task_handle(self.thread_handle) |
| 180 |
|
| 181 |
def get_thread_id(self): |
| 182 |
"""Obtains the ID for the given thread.""" |
| 183 |
if not self.thread_id: |
| 184 |
self.thread_id = ompdModule.call_ompd_get_thread_id(self.thread_handle) |
| 185 |
return self.thread_id |
| 186 |
|
| 187 |
def get_current_task(self): |
| 188 |
"""Returns task object for task handle of the current task region.""" |
| 189 |
return ompd_task(self.get_current_task_handle()) |
| 190 |
|
| 191 |
def get_state(self): |
| 192 |
"""Returns tuple with OMPD state (long) and wait_id, in case the thread is in a |
| 193 |
waiting state. Helper function for 'ompd threads' command.""" |
| 194 |
(state, wait_id) = ompdModule.call_ompd_get_state(self.thread_handle) |
| 195 |
return (state, wait_id) |
| 196 |
|
| 197 |
def __del__(self): |
| 198 |
"""Releases the given thread handle.""" |
| 199 |
pass # let capsule destructors do the job |