ARGOBOTS
self.c
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  * See COPYRIGHT in top-level directory.
4  */
5 
6 #include "abti.h"
7 
32 {
33  int abt_errno = ABT_SUCCESS;
34  /* If Argobots has not been initialized, set type to ABT_UNIT_TYPE_EXIT. */
35  if (gp_ABTI_global == NULL) {
36  abt_errno = ABT_ERR_UNINITIALIZED;
37  *type = ABT_UNIT_TYPE_EXT;
38  goto fn_exit;
39  }
40 
41  ABTI_local *p_local = ABTI_local_get_local();
42  *type = ABTI_self_get_type(p_local);
43 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD
44  /* This is when an external thread called this routine. */
45  if (*type == ABT_UNIT_TYPE_EXT) {
46  abt_errno = ABT_ERR_INV_XSTREAM;
47  goto fn_exit;
48  }
49 #endif
50 
51 fn_exit:
52  return abt_errno;
53 }
54 
73 {
74  int abt_errno = ABT_SUCCESS;
75  ABTI_local *p_local = ABTI_local_get_local();
76  ABTI_thread *p_thread;
77 
78  /* If Argobots has not been initialized, set flag to ABT_FALSE. */
79  if (gp_ABTI_global == NULL) {
80  abt_errno = ABT_ERR_UNINITIALIZED;
81  *flag = ABT_FALSE;
82  goto fn_exit;
83  }
84 
85 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD
86  /* This is when an external thread called this routine. */
87  if (p_local == NULL) {
88  abt_errno = ABT_ERR_INV_XSTREAM;
89  *flag = ABT_FALSE;
90  goto fn_exit;
91  }
92 #endif
93 
94  p_thread = p_local->p_thread;
95  if (p_thread) {
96  *flag =
97  (p_thread->type == ABTI_THREAD_TYPE_MAIN) ? ABT_TRUE : ABT_FALSE;
98  } else {
99  abt_errno = ABT_ERR_INV_THREAD;
100  *flag = ABT_FALSE;
101  }
102 
103 fn_exit:
104  return abt_errno;
105 }
106 
123 {
124  int abt_errno = ABT_SUCCESS;
125  ABTI_local *p_local = ABTI_local_get_local();
126  ABTI_xstream *p_xstream;
127 
128  /* If Argobots has not been initialized, set flag to ABT_FALSE. */
129  if (gp_ABTI_global == NULL) {
130  abt_errno = ABT_ERR_UNINITIALIZED;
131  *flag = ABT_FALSE;
132  goto fn_exit;
133  }
134 
135 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD
136  /* This is when an external thread called this routine. */
137  if (p_local == NULL) {
138  abt_errno = ABT_ERR_INV_XSTREAM;
139  *flag = ABT_FALSE;
140  goto fn_exit;
141  }
142 #endif
143 
144  p_xstream = p_local->p_xstream;
145  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
146 
147  /* Return value */
148  *flag =
149  (p_xstream->type == ABTI_XSTREAM_TYPE_PRIMARY) ? ABT_TRUE : ABT_FALSE;
150 
151 fn_exit:
152  return abt_errno;
153 
154 fn_fail:
155  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
156  goto fn_exit;
157 }
158 
177 int ABT_self_get_last_pool_id(int *pool_id)
178 {
179  int abt_errno = ABT_SUCCESS;
180  ABTI_local *p_local = ABTI_local_get_local();
181  ABTI_thread *p_thread;
182  ABTI_task *p_task;
183 
184  /* If Argobots has not been initialized, set type to ABT_UNIT_TYPE_EXIT. */
185  if (gp_ABTI_global == NULL) {
186  abt_errno = ABT_ERR_UNINITIALIZED;
187  *pool_id = -1;
188  goto fn_exit;
189  }
190 
191 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD
192  /* This is when an external thread called this routine. */
193  if (p_local == NULL) {
194  abt_errno = ABT_ERR_INV_XSTREAM;
195  *pool_id = -1;
196  goto fn_exit;
197  }
198 #endif
199 
200  if ((p_thread = p_local->p_thread)) {
201  ABTI_ASSERT(p_thread->p_pool);
202  *pool_id = (int)(p_thread->p_pool->id);
203  } else if ((p_task = p_local->p_task)) {
204  ABTI_ASSERT(p_task->p_pool);
205  *pool_id = (int)(p_task->p_pool->id);
206  } else {
207  abt_errno = ABT_ERR_OTHER;
208  *pool_id = -1;
209  }
210 
211 fn_exit:
212  return abt_errno;
213 }
214 
232 {
233  int abt_errno = ABT_SUCCESS;
234  ABTI_local *p_local = ABTI_local_get_local();
235 #ifdef ABT_CONFIG_DISABLE_EXT_THREAD
236  ABTI_thread *p_thread = p_local->p_thread;
237 #else
238  ABTI_thread *p_thread = NULL;
239 
240  /* If this routine is called by non-ULT, just return. */
241  if (p_local != NULL) {
242  p_thread = p_local->p_thread;
243  }
244 #endif
245  if (p_thread == NULL) {
246  abt_errno = ABT_ERR_INV_THREAD;
247  goto fn_fail;
248  }
249 
250  abt_errno = ABTI_thread_set_blocked(p_thread);
251  ABTI_CHECK_ERROR(abt_errno);
252 
253  ABTI_thread_suspend(&p_local, p_thread);
254 
255 fn_exit:
256  return abt_errno;
257 
258 fn_fail:
259  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
260  goto fn_exit;
261 }
262 
274 int ABT_self_set_arg(void *arg)
275 {
276  int abt_errno = ABT_SUCCESS;
277  ABTI_local *p_local = ABTI_local_get_local();
278  ABTI_thread *p_thread;
279  ABTI_task *p_task;
280 
281  /* When Argobots has not been initialized */
282  if (gp_ABTI_global == NULL) {
283  abt_errno = ABT_ERR_UNINITIALIZED;
284  goto fn_exit;
285  }
286 
287  /* When an external thread called this routine */
288  if (p_local == NULL) {
289  abt_errno = ABT_ERR_INV_XSTREAM;
290  goto fn_exit;
291  }
292 
293  if ((p_thread = p_local->p_thread)) {
294  ABTD_thread_context_set_arg(&p_thread->ctx, arg);
295  } else if ((p_task = p_local->p_task)) {
296  p_task->p_arg = arg;
297  } else {
298  abt_errno = ABT_ERR_OTHER;
299  goto fn_fail;
300  }
301 
302 fn_exit:
303  return abt_errno;
304 
305 fn_fail:
306  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
307  goto fn_exit;
308 }
309 
324 int ABT_self_get_arg(void **arg)
325 {
326  int abt_errno = ABT_SUCCESS;
327  ABTI_local *p_local = ABTI_local_get_local();
328  ABTI_thread *p_thread;
329  ABTI_task *p_task;
330 
331  /* When Argobots has not been initialized */
332  if (gp_ABTI_global == NULL) {
333  abt_errno = ABT_ERR_UNINITIALIZED;
334  *arg = NULL;
335  goto fn_exit;
336  }
337 
338 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD
339  /* When an external thread called this routine */
340  if (p_local == NULL) {
341  abt_errno = ABT_ERR_INV_XSTREAM;
342  *arg = NULL;
343  goto fn_exit;
344  }
345 #endif
346 
347  if ((p_thread = p_local->p_thread)) {
348  *arg = ABTD_thread_context_get_arg(&p_thread->ctx);
349  } else if ((p_task = p_local->p_task)) {
350  *arg = p_task->p_arg;
351  } else {
352  *arg = NULL;
353  abt_errno = ABT_ERR_OTHER;
354  goto fn_fail;
355  }
356 
357 fn_exit:
358  return abt_errno;
359 
360 fn_fail:
361  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
362  goto fn_exit;
363 }
int ABT_self_set_arg(void *arg)
Set the argument for the work unit function.
Definition: self.c:274
#define ABT_ERR_INV_THREAD
Definition: abt.h:80
int ABT_bool
Definition: abt.h:309
#define ABT_ERR_OTHER
Definition: abt.h:67
int ABT_self_get_type(ABT_unit_type *type)
Return the type of calling work unit.
Definition: self.c:31
#define ABT_FALSE
Definition: abt.h:224
#define HANDLE_ERROR_FUNC_WITH_CODE(n)
Definition: abti_error.h:241
ABTI_global * gp_ABTI_global
Definition: global.c:14
#define ABT_SUCCESS
Definition: abt.h:64
#define ABT_TRUE
Definition: abt.h:223
ABT_unit_type
Definition: abt.h:170
int ABT_self_suspend(void)
Suspend the current ULT.
Definition: self.c:231
#define ABT_ERR_UNINITIALIZED
Definition: abt.h:65
int ABT_self_get_arg(void **arg)
Retrieve the argument for the work unit function.
Definition: self.c:324
int ABT_self_get_last_pool_id(int *pool_id)
Get the last pool's ID of calling work unit.
Definition: self.c:177
int ABT_self_is_primary(ABT_bool *flag)
Check if the caller is the primary ULT.
Definition: self.c:72
#define ABT_ERR_INV_XSTREAM
Definition: abt.h:68
int ABT_self_on_primary_xstream(ABT_bool *flag)
Check if the caller's ES is the primary ES.
Definition: self.c:122