ARGOBOTS  1.1
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 
34 {
35  ABTI_xstream *p_local_xstream;
36  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
37 
38  /* Return value */
39  *xstream = ABTI_xstream_get_handle(p_local_xstream);
40  return ABT_SUCCESS;
41 }
42 
66 {
67  ABTI_xstream *p_local_xstream;
68  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
69  /* Return value */
70  *rank = (int)p_local_xstream->rank;
71  return ABT_SUCCESS;
72 }
73 
96 {
97  ABTI_xstream *p_local_xstream;
98  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
99  *thread = ABTI_thread_get_handle(p_local_xstream->p_thread);
100  return ABT_SUCCESS;
101 }
102 
125 {
126  ABTI_xstream *p_local_xstream;
127  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
128  *id = ABTI_thread_get_id(p_local_xstream->p_thread);
129  return ABT_SUCCESS;
130 }
131 
132 #ifdef ABT_CONFIG_USE_DOXYGEN
133 
139 int ABT_self_get_task(ABT_thread *thread);
140 #endif
141 
142 #ifdef ABT_CONFIG_USE_DOXYGEN
143 
150 #endif
151 
179 int ABT_self_set_specific(ABT_key key, void *value)
180 {
181  ABTI_key *p_key = ABTI_key_get_ptr(key);
183 
184  ABTI_global *p_global;
185  ABTI_SETUP_GLOBAL(&p_global);
186 
187  ABTI_xstream *p_local_xstream;
188  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
189 
190  /* Obtain the key-value table pointer. */
191  int abt_errno =
192  ABTI_ktable_set(p_global, ABTI_xstream_get_local(p_local_xstream),
193  &p_local_xstream->p_thread->p_keytable, p_key, value);
194  ABTI_CHECK_ERROR(abt_errno);
195  return ABT_SUCCESS;
196 }
197 
226 int ABT_self_get_specific(ABT_key key, void **value)
227 {
228  ABTI_key *p_key = ABTI_key_get_ptr(key);
230 
231  /* We don't allow an external thread to call this routine. */
232  ABTI_xstream *p_local_xstream;
233  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
234 
235  /* Obtain the key-value table pointer */
236  *value = ABTI_ktable_get(&p_local_xstream->p_thread->p_keytable, p_key);
237  return ABT_SUCCESS;
238 }
239 
275 {
276 #ifndef ABT_CONFIG_ENABLE_VER_20_API
277  /* By default, type is ABT_UNIT_TYPE_EXT in Argobots 1.x */
278  *type = ABT_UNIT_TYPE_EXT;
279  ABTI_SETUP_GLOBAL(NULL);
280  ABTI_xstream *p_local_xstream;
281  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
282  *type = ABTI_thread_type_get_type(p_local_xstream->p_thread->type);
283 #else
284  ABTI_xstream *p_local_xstream =
286  if (p_local_xstream) {
287  *type = ABTI_thread_type_get_type(p_local_xstream->p_thread->type);
288  } else {
289  *type = ABT_UNIT_TYPE_EXT;
290  }
291 #endif
292  return ABT_SUCCESS;
293 }
294 
332 {
333 #ifndef ABT_CONFIG_ENABLE_VER_20_API
334  *is_primary = ABT_FALSE;
335  ABTI_SETUP_GLOBAL(NULL);
336  ABTI_ythread *p_ythread;
337  ABTI_SETUP_LOCAL_YTHREAD(NULL, &p_ythread);
338  *is_primary = (p_ythread->thread.type & ABTI_THREAD_TYPE_PRIMARY)
339  ? ABT_TRUE
340  : ABT_FALSE;
341 #else
342  ABTI_xstream *p_local_xstream =
344  if (p_local_xstream) {
345  *is_primary =
346  (p_local_xstream->p_thread->type & ABTI_THREAD_TYPE_PRIMARY)
347  ? ABT_TRUE
348  : ABT_FALSE;
349  } else {
350  *is_primary = ABT_FALSE;
351  }
352 #endif
353  return ABT_SUCCESS;
354 }
355 
392 {
393 #ifndef ABT_CONFIG_ENABLE_VER_20_API
394  *on_primary = ABT_FALSE;
395  ABTI_SETUP_GLOBAL(NULL);
396  ABTI_xstream *p_local_xstream;
397  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
398  *on_primary = (p_local_xstream->type == ABTI_XSTREAM_TYPE_PRIMARY)
399  ? ABT_TRUE
400  : ABT_FALSE;
401 #else
402  ABTI_xstream *p_local_xstream =
404  if (p_local_xstream) {
405  *on_primary = (p_local_xstream->type == ABTI_XSTREAM_TYPE_PRIMARY)
406  ? ABT_TRUE
407  : ABT_FALSE;
408  } else {
409  *on_primary = ABT_FALSE;
410  }
411 #endif
412  return ABT_SUCCESS;
413 }
414 
437 {
438  ABTI_xstream *p_local_xstream;
439  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
440  ABTI_thread *p_self = p_local_xstream->p_thread;
441  ABTI_ASSERT(p_self->p_pool);
442  *pool = ABTI_pool_get_handle(p_self->p_pool);
443  return ABT_SUCCESS;
444 }
445 
474 int ABT_self_get_last_pool_id(int *pool_id)
475 {
476  ABTI_xstream *p_local_xstream;
477 #ifndef ABT_CONFIG_ENABLE_VER_20_API
478  *pool_id = -1;
479  ABTI_SETUP_GLOBAL(NULL);
480  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
481  ABTI_thread *p_self = p_local_xstream->p_thread;
482  ABTI_ASSERT(p_self->p_pool);
483  *pool_id = p_self->p_pool->id;
484 #else
485  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
486  ABTI_thread *p_self = p_local_xstream->p_thread;
487  ABTI_ASSERT(p_self->p_pool);
488  *pool_id = p_self->p_pool->id;
489 #endif
490  return ABT_SUCCESS;
491 }
492 
519 {
520  ABTI_global *p_global = ABTI_global_get_global();
521  ABTI_xstream *p_local_xstream;
522  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
523  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
524  ABTI_CHECK_NULL_POOL_PTR(p_pool);
525  ABTI_thread *p_self = p_local_xstream->p_thread;
526 
527  int abt_errno = ABTI_thread_set_associated_pool(p_global, p_self, p_pool);
528  ABTI_CHECK_ERROR(abt_errno);
529  return ABT_SUCCESS;
530 }
531 
554 {
555  /* We don't allow an external thread to call this routine. */
556  ABTI_xstream *p_local_xstream;
557  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
558  *unit = p_local_xstream->p_thread->unit;
559  return ABT_SUCCESS;
560 }
561 
583 int ABT_self_yield(void)
584 {
585  ABTI_xstream *p_local_xstream;
586  ABTI_ythread *p_ythread;
587  ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, &p_ythread);
588 
589  ABTI_ythread_yield(&p_local_xstream, p_ythread, ABT_SYNC_EVENT_TYPE_USER,
590  NULL);
591  return ABT_SUCCESS;
592 }
593 
623 int ABT_self_suspend(void)
624 {
625  ABTI_xstream *p_local_xstream;
626  ABTI_ythread *p_self;
627  ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, &p_self);
628 
629  ABTI_ythread_set_blocked(p_self);
630  ABTI_ythread_suspend(&p_local_xstream, p_self, ABT_SYNC_EVENT_TYPE_USER,
631  NULL);
632  return ABT_SUCCESS;
633 }
634 
655 int ABT_self_exit(void)
656 {
657  ABTI_xstream *p_local_xstream;
658  ABTI_ythread *p_ythread;
659  ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, &p_ythread);
662 
663  ABTI_ythread_exit(p_local_xstream, p_ythread);
664  return ABT_SUCCESS;
665 }
666 
696 int ABT_self_set_arg(void *arg)
697 {
698  ABTI_xstream *p_local_xstream;
699 #ifndef ABT_CONFIG_ENABLE_VER_20_API
700  ABTI_SETUP_GLOBAL(NULL);
701 #endif
702  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
703 
704  p_local_xstream->p_thread->p_arg = arg;
705  return ABT_SUCCESS;
706 }
707 
737 int ABT_self_get_arg(void **arg)
738 {
739  ABTI_xstream *p_local_xstream;
740 #ifndef ABT_CONFIG_ENABLE_VER_20_API
741  *arg = NULL;
742  ABTI_SETUP_GLOBAL(NULL);
743 #endif
744  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
745 
746  *arg = p_local_xstream->p_thread->p_arg;
747  return ABT_SUCCESS;
748 }
749 
771 int ABT_self_get_thread_func(void (**thread_func)(void *))
772 {
773  ABTI_xstream *p_local_xstream;
774  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
775 
776  *thread_func = p_local_xstream->p_thread->f_thread;
777  return ABT_SUCCESS;
778 }
779 
803 int ABT_self_is_unnamed(ABT_bool *is_unnamed)
804 {
805  ABTI_xstream *p_local_xstream;
806  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
807 
808  *is_unnamed = (p_local_xstream->p_thread->type & ABTI_THREAD_TYPE_NAMED)
809  ? ABT_FALSE
810  : ABT_TRUE;
811  return ABT_SUCCESS;
812 }
ABTI_key
Definition: abti.h:413
ABT_SYNC_EVENT_TYPE_USER
@ ABT_SYNC_EVENT_TYPE_USER
Definition: abt.h:664
ABT_key
struct ABT_key_opaque * ABT_key
Work-unit-specific data key handle type.
Definition: abt.h:938
ABT_ERR_INV_THREAD
#define ABT_ERR_INV_THREAD
Error code: invalid work unit.
Definition: abt.h:176
ABT_bool
int ABT_bool
Boolean type.
Definition: abt.h:1001
ABTI_XSTREAM_TYPE_PRIMARY
@ ABTI_XSTREAM_TYPE_PRIMARY
Definition: abti.h:71
ABTI_SETUP_LOCAL_XSTREAM
#define ABTI_SETUP_LOCAL_XSTREAM(pp_local_xstream)
Definition: abti_error.h:73
ABTI_ktable_get
static void * ABTI_ktable_get(ABTD_atomic_ptr *pp_ktable, ABTI_key *p_key)
Definition: abti_key.h:287
ABT_self_get_arg
int ABT_self_get_arg(void **arg)
Retrieve an argument for a work-unit function of the calling work unit.
Definition: self.c:738
ABT_thread
struct ABT_thread_opaque * ABT_thread
Work unit handle type.
Definition: abt.h:890
ABTI_key_get_ptr
static ABTI_key * ABTI_key_get_ptr(ABT_key key)
Definition: abti_key.h:11
ABTI_SETUP_GLOBAL
#define ABTI_SETUP_GLOBAL(pp_global)
Definition: abti_error.h:59
ABT_self_get_thread_func
int ABT_self_get_thread_func(void(**thread_func)(void *))
Retrieve a work-unit function of the calling work unit.
Definition: self.c:772
ABTI_thread::type
ABTI_thread_type type
Definition: abti.h:375
ABTI_global_get_global
static ABTI_global * ABTI_global_get_global(void)
Definition: abti_global.h:9
ABTI_CHECK_ERROR
#define ABTI_CHECK_ERROR(abt_errno)
Definition: abti_error.h:120
ABTI_xstream::rank
int rank
Definition: abti.h:269
ABTI_xstream::type
ABTI_xstream_type type
Definition: abti.h:270
ABTI_thread_get_id
ABT_unit_id ABTI_thread_get_id(ABTI_thread *p_thread)
Definition: thread.c:2561
ABTI_thread_get_handle
static ABT_thread ABTI_thread_get_handle(ABTI_thread *p_thread)
Definition: abti_thread.h:24
ABTI_thread_set_associated_pool
static ABTU_ret_err int ABTI_thread_set_associated_pool(ABTI_global *p_global, ABTI_thread *p_thread, ABTI_pool *p_pool)
Definition: abti_unit.h:147
ABT_self_get_thread
int ABT_self_get_thread(ABT_thread *thread)
Get the calling work unit.
Definition: self.c:95
ABTI_thread
Definition: abti.h:371
ABT_self_get_last_pool
int ABT_self_get_last_pool(ABT_pool *pool)
Get the last pool of the calling work unit.
Definition: self.c:436
ABT_self_set_specific
int ABT_self_set_specific(ABT_key key, void *value)
Associate a value with a work-unit-specific data key in the calling work unit.
Definition: self.c:179
ABTI_xstream
Definition: abti.h:264
ABT_self_get_task
int ABT_self_get_task(ABT_thread *thread)
Get the calling work unit.
ABT_pool
struct ABT_pool_opaque * ABT_pool
Pool handle type.
Definition: abt.h:841
ABTI_ktable_set
static ABTU_ret_err int ABTI_ktable_set(ABTI_global *p_global, ABTI_local *p_local, ABTD_atomic_ptr *pp_ktable, ABTI_key *p_key, void *value)
Definition: abti_key.h:225
ABTI_thread_type_get_type
static ABT_unit_type ABTI_thread_type_get_type(ABTI_thread_type type)
Definition: abti_thread.h:41
ABTI_pool
Definition: abti.h:327
ABTI_THREAD_TYPE_PRIMARY
#define ABTI_THREAD_TYPE_PRIMARY
Definition: abti.h:84
ABTI_xstream_get_handle
static ABT_xstream ABTI_xstream_get_handle(ABTI_xstream *p_xstream)
Definition: abti_stream.h:26
abti.h
ABTI_ythread_exit
ABTU_noreturn void ABTI_ythread_exit(ABTI_xstream *p_local_xstream, ABTI_ythread *p_ythread)
Definition: thread.c:2425
ABT_self_on_primary_xstream
int ABT_self_on_primary_xstream(ABT_bool *on_primary)
Check if the caller is running on the primary execution stream.
Definition: self.c:391
ABT_unit_id
uint64_t ABT_unit_id
Work unit ID type.
Definition: abt.h:879
ABT_xstream
struct ABT_xstream_opaque * ABT_xstream
Execution stream handle type.
Definition: abt.h:789
ABT_self_suspend
int ABT_self_suspend(void)
Suspend the calling ULT.
Definition: self.c:624
ABT_unit_type
ABT_unit_type
Type of a work unit for scheduling.
Definition: abt.h:548
ABT_self_set_associated_pool
int ABT_self_set_associated_pool(ABT_pool pool)
Set an associated pool for the calling work unit.
Definition: self.c:518
ABT_self_get_last_pool_id
int ABT_self_get_last_pool_id(int *pool_id)
Get ID of the last pool of the calling work unit.
Definition: self.c:474
ABT_self_is_primary
int ABT_self_is_primary(ABT_bool *is_primary)
Check if the caller is the primary ULT.
Definition: self.c:331
ABT_unit
struct ABT_unit_opaque * ABT_unit
Work unit handle type for scheduling.
Definition: abt.h:869
ABTI_ASSERT
#define ABTI_ASSERT(cond)
Definition: abti_error.h:12
ABTI_local_get_local
static ABTI_local * ABTI_local_get_local(void)
Definition: abti_local.h:41
ABT_self_exit
int ABT_self_exit(void)
Terminate a calling ULT.
Definition: self.c:656
ABT_SUCCESS
#define ABT_SUCCESS
Error code: the routine returns successfully.
Definition: abt.h:92
ABTI_SETUP_LOCAL_YTHREAD
#define ABTI_SETUP_LOCAL_YTHREAD(pp_local_xstream, pp_ythread)
Definition: abti_error.h:88
ABTI_ythread_set_blocked
void ABTI_ythread_set_blocked(ABTI_ythread *p_ythread)
Definition: ythread.c:23
ABTI_local_get_xstream_or_null
static ABTI_xstream * ABTI_local_get_xstream_or_null(ABTI_local *p_local)
Definition: abti_local.h:77
ABT_self_get_specific
int ABT_self_get_specific(ABT_key key, void **value)
Get a value associated with a work-unit-specific data key in the calling work unit.
Definition: self.c:226
ABTI_xstream_get_local
static ABTI_local * ABTI_xstream_get_local(ABTI_xstream *p_xstream)
Definition: abti_stream.h:68
ABT_self_set_arg
int ABT_self_set_arg(void *arg)
Set an argument for a work-unit function of the calling work unit.
Definition: self.c:697
ABT_TRUE
#define ABT_TRUE
True constant for ABT_bool.
Definition: abt.h:748
ABTI_pool_get_ptr
static ABTI_pool * ABTI_pool_get_ptr(ABT_pool pool)
Definition: abti_pool.h:11
ABT_FALSE
#define ABT_FALSE
False constant for ABT_bool.
Definition: abt.h:750
ABTI_ythread
Definition: abti.h:406
ABT_self_get_task_id
int ABT_self_get_task_id(ABT_unit_id *id)
Get ID of the calling work unit.
ABTI_ythread_suspend
void ABTI_ythread_suspend(ABTI_xstream **pp_local_xstream, ABTI_ythread *p_ythread, ABT_sync_event_type sync_event_type, void *p_sync)
Definition: ythread.c:45
ABTI_CHECK_NULL_POOL_PTR
#define ABTI_CHECK_NULL_POOL_PTR(p)
Definition: abti_error.h:168
ABTI_THREAD_TYPE_NAMED
#define ABTI_THREAD_TYPE_NAMED
Definition: abti.h:87
ABT_self_yield
int ABT_self_yield(void)
Yield the calling ULT to its parent ULT.
Definition: self.c:583
ABT_self_get_xstream_rank
int ABT_self_get_xstream_rank(int *rank)
Return a rank of an execution stream that is running the calling work unit.
Definition: self.c:65
ABTI_ythread::thread
ABTI_thread thread
Definition: abti.h:407
ABTI_ythread_yield
static void ABTI_ythread_yield(ABTI_xstream **pp_local_xstream, ABTI_ythread *p_ythread, ABT_sync_event_type sync_event_type, void *p_sync)
Definition: abti_ythread.h:372
ABT_self_get_unit
int ABT_self_get_unit(ABT_unit *unit)
Get a unit handle of the calling work unit.
Definition: self.c:553
ABTI_pool::id
uint64_t id
Definition: abti.h:335
ABTI_CHECK_TRUE
#define ABTI_CHECK_TRUE(cond, abt_errno)
Definition: abti_error.h:130
ABT_self_get_type
int ABT_self_get_type(ABT_unit_type *type)
Obtain a type of the caller.
Definition: self.c:274
ABTI_CHECK_NULL_KEY_PTR
#define ABTI_CHECK_NULL_KEY_PTR(p)
Definition: abti_error.h:231
ABTI_global
Definition: abti.h:196
ABT_self_is_unnamed
int ABT_self_is_unnamed(ABT_bool *is_unnamed)
Check if the calling work unit is unnamed.
Definition: self.c:804
ABTI_thread::p_pool
ABTI_pool * p_pool
Definition: abti.h:383
ABTI_pool_get_handle
static ABT_pool ABTI_pool_get_handle(ABTI_pool *p_pool)
Definition: abti_pool.h:26
ABT_UNIT_TYPE_EXT
@ ABT_UNIT_TYPE_EXT
Definition: abt.h:560
ABT_self_get_xstream
int ABT_self_get_xstream(ABT_xstream *xstream)
Get an execution stream that is running the calling work unit.
Definition: self.c:33
ABT_self_get_thread_id
int ABT_self_get_thread_id(ABT_unit_id *id)
Get ID of the calling work unit.
Definition: self.c:124