10 ABTI_xstream_type xstream_type,
int rank,
12 ABTI_xstream **pp_xstream);
14 ABTI_xstream *p_xstream);
16 ABTI_xstream *p_newxstream,
int rank);
18 ABTI_xstream *p_xstream,
int rank);
24 ABTI_xstream **pp_local_xstream,
25 ABTI_xstream *p_xstream, ABTI_sched *p_sched);
78 ABTI_UB_ASSERT(ABTI_initialized());
79 ABTI_UB_ASSERT(newxstream);
81 #ifndef ABT_CONFIG_ENABLE_VER_20_API
86 ABTI_xstream *p_newxstream;
88 ABTI_global *p_global;
89 ABTI_SETUP_GLOBAL(&p_global);
91 ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
95 ABTI_CHECK_ERROR(abt_errno);
97 #ifndef ABT_CONFIG_ENABLE_VER_20_API
98 ABTI_CHECK_TRUE(p_sched->used == ABTI_SCHED_NOT_USED,
101 ABTI_UB_ASSERT(p_sched->used == ABTI_SCHED_NOT_USED);
105 abt_errno =
xstream_create(p_global, p_sched, ABTI_XSTREAM_TYPE_SECONDARY,
108 if (!ABTI_sched_get_ptr(sched)) {
109 ABTI_sched_free(p_global, ABTI_local_get_local_uninlined(), p_sched,
112 ABTI_HANDLE_ERROR(abt_errno);
116 *newxstream = ABTI_xstream_get_handle(p_newxstream);
177 ABTI_UB_ASSERT(ABTI_initialized());
178 ABTI_UB_ASSERT(pools || num_pools <= 0);
179 ABTI_UB_ASSERT(newxstream);
181 #ifndef ABT_CONFIG_ENABLE_VER_20_API
188 ABTI_xstream *p_newxstream;
189 ABTI_sched_config *p_config = ABTI_sched_config_get_ptr(config);
191 ABTI_global *p_global;
192 ABTI_SETUP_GLOBAL(&p_global);
196 ABTI_sched_create_basic(predef, num_pools, pools, p_config, &p_sched);
197 ABTI_CHECK_ERROR(abt_errno);
199 abt_errno =
xstream_create(p_global, p_sched, ABTI_XSTREAM_TYPE_SECONDARY,
203 for (i = 0; i < num_pools; i++) {
206 ABTI_pool_release(ABTI_pool_get_ptr(p_sched->pools[i]));
210 ABTI_sched_free(p_global, ABTI_local_get_local_uninlined(), p_sched,
212 ABTI_HANDLE_ERROR(abt_errno);
215 *newxstream = ABTI_xstream_get_handle(p_newxstream);
273 ABTI_UB_ASSERT(ABTI_initialized());
274 ABTI_UB_ASSERT(newxstream);
276 #ifndef ABT_CONFIG_ENABLE_VER_20_API
281 ABTI_xstream *p_newxstream;
283 ABTI_global *p_global;
284 ABTI_SETUP_GLOBAL(&p_global);
288 ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
292 ABTI_CHECK_ERROR(abt_errno);
294 #ifndef ABT_CONFIG_ENABLE_VER_20_API
295 ABTI_CHECK_TRUE(p_sched->used == ABTI_SCHED_NOT_USED,
298 ABTI_UB_ASSERT(p_sched->used == ABTI_SCHED_NOT_USED);
302 abt_errno =
xstream_create(p_global, p_sched, ABTI_XSTREAM_TYPE_SECONDARY,
304 if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno !=
ABT_SUCCESS) {
305 if (!ABTI_sched_get_ptr(sched)) {
306 ABTI_sched_free(p_global, ABTI_local_get_local_uninlined(), p_sched,
309 ABTI_HANDLE_ERROR(abt_errno);
313 *newxstream = ABTI_xstream_get_handle(p_newxstream);
349 ABTI_UB_ASSERT(ABTI_initialized());
351 ABTI_global *p_global = ABTI_global_get_global();
352 ABTI_local *p_local = ABTI_local_get_local();
353 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
354 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
357 ABTI_sched *p_main_sched = p_xstream->p_main_sched;
358 ABTI_ythread *p_main_sched_ythread = p_main_sched->p_ythread;
360 ABTI_CHECK_TRUE(ABTD_atomic_relaxed_load_int(
361 &p_main_sched_ythread->thread.state) ==
365 ABTD_atomic_relaxed_store_uint32(&p_main_sched->request, 0);
366 ABTI_event_thread_join(p_local, &p_main_sched_ythread->thread,
367 ABTI_local_get_xstream_or_null(p_local)
368 ? ABTI_local_get_xstream(p_local)->p_thread
372 ABTI_thread_revive(p_global, p_local, p_xstream->p_root_pool,
373 p_main_sched_ythread->thread.f_thread,
374 p_main_sched_ythread->thread.p_arg,
375 &p_main_sched_ythread->thread);
381 ABTD_xstream_context_revive(&p_xstream->ctx);
428 ABTI_UB_ASSERT(ABTI_initialized());
429 ABTI_UB_ASSERT(xstream);
431 ABTI_global *p_global;
432 ABTI_SETUP_GLOBAL(&p_global);
434 ABTI_local *p_local = ABTI_local_get_local();
437 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(h_xstream);
438 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
442 ABTI_CHECK_TRUE_MSG(p_xstream != ABTI_local_get_xstream_or_null(p_local),
444 "The current xstream cannot be freed.");
446 ABTI_CHECK_TRUE_MSG(p_xstream->type != ABTI_XSTREAM_TYPE_PRIMARY,
448 "The primary xstream cannot be freed explicitly.");
452 ABTI_CHECK_ERROR(abt_errno);
455 ABTI_xstream_free(p_global, p_local, p_xstream,
ABT_FALSE);
495 ABTI_UB_ASSERT(ABTI_initialized());
497 ABTI_local *p_local = ABTI_local_get_local();
498 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
499 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
502 ABTI_CHECK_ERROR(abt_errno);
542 ABTI_xstream *p_local_xstream;
543 ABTI_ythread *p_ythread;
544 #ifndef ABT_CONFIG_ENABLE_VER_20_API
545 ABTI_SETUP_GLOBAL(NULL);
547 ABTI_UB_ASSERT(ABTI_initialized());
549 ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, &p_ythread);
551 ABTI_CHECK_TRUE(p_local_xstream->type != ABTI_XSTREAM_TYPE_PRIMARY,
555 ABTD_atomic_fetch_or_uint32(&p_local_xstream->p_main_sched->p_ythread
557 ABTI_THREAD_REQ_CANCEL);
559 ABTI_ythread_exit(p_local_xstream, p_ythread);
594 ABTI_UB_ASSERT(ABTI_initialized());
596 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
597 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
598 ABTI_CHECK_TRUE(p_xstream->type != ABTI_XSTREAM_TYPE_PRIMARY,
602 ABTD_atomic_fetch_or_uint32(&p_xstream->p_main_sched->p_ythread->thread
604 ABTI_THREAD_REQ_CANCEL);
641 ABTI_UB_ASSERT(xstream);
643 ABTI_xstream *p_local_xstream;
644 #ifndef ABT_CONFIG_ENABLE_VER_20_API
646 ABTI_SETUP_GLOBAL(NULL);
648 ABTI_UB_ASSERT(ABTI_initialized());
650 ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
653 *xstream = ABTI_xstream_get_handle(p_local_xstream);
688 ABTI_UB_ASSERT(rank);
690 ABTI_xstream *p_local_xstream;
691 #ifndef ABT_CONFIG_ENABLE_VER_20_API
692 ABTI_SETUP_GLOBAL(NULL);
694 ABTI_UB_ASSERT(ABTI_initialized());
696 ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
698 *rank = (int)p_local_xstream->rank;
739 ABTI_UB_ASSERT(ABTI_initialized());
741 ABTI_global *p_global;
742 ABTI_SETUP_GLOBAL(&p_global);
744 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
745 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
746 ABTI_CHECK_TRUE(p_xstream->type != ABTI_XSTREAM_TYPE_PRIMARY,
754 if (p_global->set_affinity ==
ABT_TRUE) {
755 ABTD_affinity_cpuset_apply_default(&p_xstream->ctx, p_xstream->rank);
786 ABTI_UB_ASSERT(ABTI_initialized());
787 ABTI_UB_ASSERT(rank);
789 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
790 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
792 *rank = (int)p_xstream->rank;
876 ABTI_UB_ASSERT(ABTI_initialized());
878 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
879 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
881 ABTI_global *p_global;
882 ABTI_SETUP_GLOBAL(&p_global);
884 ABTI_xstream *p_local_xstream;
885 ABTI_ythread *p_self;
886 ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, &p_self);
888 #ifndef ABT_CONFIG_ENABLE_VER_20_API
889 ABTI_CHECK_TRUE(ABTD_atomic_acquire_load_int(&p_xstream->state) !=
891 p_local_xstream == p_xstream,
894 ABTI_CHECK_TRUE(ABTD_atomic_acquire_load_int(&p_xstream->state) !=
896 p_local_xstream == p_xstream,
900 ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
904 ABTI_CHECK_ERROR(abt_errno);
906 #ifndef ABT_CONFIG_ENABLE_VER_20_API
907 ABTI_CHECK_TRUE(p_sched->used == ABTI_SCHED_NOT_USED,
910 ABTI_UB_ASSERT(p_sched->used == ABTI_SCHED_NOT_USED);
916 if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno !=
ABT_SUCCESS) {
917 if (!ABTI_sched_get_ptr(sched)) {
918 ABTI_sched_free(p_global, ABTI_local_get_local_uninlined(), p_sched,
921 ABTI_HANDLE_ERROR(abt_errno);
983 ABTI_UB_ASSERT(ABTI_initialized());
984 ABTI_UB_ASSERT(pools || num_pools <= 0);
987 ABTI_global *p_global;
988 ABTI_SETUP_GLOBAL(&p_global);
990 ABTI_xstream *p_local_xstream;
991 ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, NULL);
993 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
994 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
998 ABTI_sched_create_basic(predef, num_pools, pools, NULL, &p_sched);
999 ABTI_CHECK_ERROR(abt_errno);
1003 if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno !=
ABT_SUCCESS) {
1005 for (i = 0; i < num_pools; i++) {
1008 ABTI_pool_release(ABTI_pool_get_ptr(p_sched->pools[i]));
1012 ABTI_sched_free(p_global, ABTI_local_get_local_uninlined(), p_sched,
1014 ABTI_HANDLE_ERROR(abt_errno);
1043 ABTI_UB_ASSERT(ABTI_initialized());
1044 ABTI_UB_ASSERT(sched);
1046 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1047 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1049 *sched = ABTI_sched_get_handle(p_xstream->p_main_sched);
1084 ABTI_UB_ASSERT(ABTI_initialized());
1085 ABTI_UB_ASSERT(pools || max_pools <= 0);
1087 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1088 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1090 ABTI_sched *p_sched = p_xstream->p_main_sched;
1091 max_pools =
ABTU_min_int(p_sched->num_pools, max_pools);
1092 memcpy(pools, p_sched->pools,
sizeof(
ABT_pool) * max_pools);
1122 ABTI_UB_ASSERT(ABTI_initialized());
1123 ABTI_UB_ASSERT(state);
1125 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1126 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1162 ABTI_UB_ASSERT(result);
1164 ABTI_xstream *p_xstream1 = ABTI_xstream_get_ptr(xstream1);
1165 ABTI_xstream *p_xstream2 = ABTI_xstream_get_ptr(xstream2);
1200 ABTI_UB_ASSERT(num_xstreams);
1201 #ifdef ABT_CONFIG_ENABLE_VER_20_API
1202 ABTI_UB_ASSERT(ABTI_initialized());
1205 ABTI_global *p_global;
1206 ABTI_SETUP_GLOBAL(&p_global);
1208 *num_xstreams = p_global->num_xstreams;
1238 ABTI_UB_ASSERT(ABTI_initialized());
1239 ABTI_UB_ASSERT(is_primary);
1241 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1242 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1280 ABTI_UB_ASSERT(ABTI_initialized());
1282 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1283 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1285 ABTI_global *p_global;
1286 ABTI_SETUP_GLOBAL(&p_global);
1288 ABTI_xstream *p_local_xstream;
1289 ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, NULL);
1291 ABTI_thread *p_thread;
1293 ABTI_unit_set_associated_pool(p_global, unit, p_pool, &p_thread);
1294 ABTI_CHECK_ERROR(abt_errno);
1295 ABTI_ythread_schedule(p_global, &p_local_xstream, p_thread);
1333 ABTI_xstream *p_local_xstream;
1334 #ifndef ABT_CONFIG_ENABLE_VER_20_API
1335 ABTI_SETUP_GLOBAL(NULL);
1337 ABTI_UB_ASSERT(ABTI_initialized());
1339 ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
1341 ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
1342 ABTI_CHECK_NULL_SCHED_PTR(p_sched);
1343 ABTI_CHECK_TRUE(p_local_xstream->p_thread == &p_sched->p_ythread->thread,
1346 ABTI_xstream_check_events(p_local_xstream, p_sched);
1380 ABTI_UB_ASSERT(ABTI_initialized());
1382 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1383 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1385 ABTD_affinity_cpuset cpuset;
1386 cpuset.num_cpuids = 1;
1387 cpuset.cpuids = &cpuid;
1388 int abt_errno = ABTD_affinity_cpuset_apply(&p_xstream->ctx, &cpuset);
1390 ABTI_CHECK_ERROR(abt_errno);
1431 ABTI_UB_ASSERT(ABTI_initialized());
1432 ABTI_UB_ASSERT(cpuid);
1434 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1435 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1440 ABTD_affinity_cpuset_read(&p_xstream->ctx, 1, cpuids, &num_cpuid);
1441 ABTI_CHECK_ERROR(abt_errno);
1483 ABTI_UB_ASSERT(ABTI_initialized());
1484 ABTI_UB_ASSERT(cpuids || num_cpuids <= 0);
1486 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1487 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1490 ABTD_affinity_cpuset affinity;
1491 affinity.num_cpuids = num_cpuids;
1492 affinity.cpuids = cpuids;
1493 int abt_errno = ABTD_affinity_cpuset_apply(&p_xstream->ctx, &affinity);
1495 ABTI_CHECK_ERROR(abt_errno);
1550 ABTI_UB_ASSERT(ABTI_initialized());
1551 ABTI_UB_ASSERT(cpuids || max_cpuids <= 0);
1553 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1554 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1557 int abt_errno = ABTD_affinity_cpuset_read(&p_xstream->ctx, max_cpuids,
1558 cpuids, num_cpuids);
1559 ABTI_CHECK_ERROR(abt_errno);
1567 ABTU_ret_err int ABTI_xstream_create_primary(ABTI_global *p_global,
1568 ABTI_xstream **pp_xstream)
1571 ABTI_xstream *p_newxstream;
1572 ABTI_sched *p_sched;
1577 ABTI_CHECK_ERROR(abt_errno);
1579 abt_errno =
xstream_create(p_global, p_sched, ABTI_XSTREAM_TYPE_PRIMARY, -1,
1582 ABTI_sched_free(p_global, ABTI_local_get_local_uninlined(), p_sched,
1584 ABTI_HANDLE_ERROR(abt_errno);
1587 *pp_xstream = p_newxstream;
1592 void ABTI_xstream_start_primary(ABTI_global *p_global,
1593 ABTI_xstream **pp_local_xstream,
1594 ABTI_xstream *p_xstream,
1595 ABTI_ythread *p_ythread)
1598 ABTI_ASSERT(p_ythread->thread.type & ABTI_THREAD_TYPE_PRIMARY);
1600 ABTI_ASSERT(ABTD_atomic_relaxed_load_int(&p_xstream->state) ==
1603 ABTD_xstream_context_set_self(&p_xstream->ctx);
1606 if (p_global->set_affinity ==
ABT_TRUE) {
1607 ABTD_affinity_cpuset_apply_default(&p_xstream->ctx, p_xstream->rank);
1611 p_xstream->p_root_ythread->thread.p_last_xstream = p_xstream;
1612 ABTI_ythread_context_switch(*pp_local_xstream, p_ythread,
1613 p_xstream->p_root_ythread);
1616 (*pp_local_xstream)->p_thread = &p_ythread->thread;
1619 void ABTI_xstream_check_events(ABTI_xstream *p_xstream, ABTI_sched *p_sched)
1621 ABTI_info_check_print_all_thread_stacks();
1623 uint32_t request = ABTD_atomic_acquire_load_uint32(
1624 &p_xstream->p_main_sched->p_ythread->thread.request);
1625 if (request & ABTI_THREAD_REQ_JOIN) {
1626 ABTI_sched_finish(p_sched);
1629 if (request & ABTI_THREAD_REQ_CANCEL) {
1630 ABTI_sched_exit(p_sched);
1634 void ABTI_xstream_free(ABTI_global *p_global, ABTI_local *p_local,
1635 ABTI_xstream *p_xstream,
ABT_bool force_free)
1638 ABTI_mem_finalize_local(p_xstream);
1644 ABTI_sched *p_cursched = p_xstream->p_main_sched;
1645 if (p_cursched != NULL) {
1647 ABTI_event_thread_join(p_local, &p_cursched->p_ythread->thread,
1648 ABTI_local_get_xstream_or_null(p_local)
1649 ? ABTI_local_get_xstream(p_local)->p_thread
1651 ABTI_sched_discard_and_free(p_global, p_local, p_cursched, force_free);
1656 ABTI_ythread_free_root(p_global, p_local, p_xstream->p_root_ythread);
1657 ABTI_pool_free(p_xstream->p_root_pool);
1660 if (p_xstream->type == ABTI_XSTREAM_TYPE_SECONDARY) {
1661 ABTD_xstream_context_free(&p_xstream->ctx);
1667 void ABTI_xstream_print(ABTI_xstream *p_xstream, FILE *p_os,
int indent,
1670 if (p_xstream == NULL) {
1671 fprintf(p_os,
"%*s== NULL ES ==\n", indent,
"");
1673 const char *type, *state;
1674 switch (p_xstream->type) {
1675 case ABTI_XSTREAM_TYPE_PRIMARY:
1678 case ABTI_XSTREAM_TYPE_SECONDARY:
1685 switch (ABTD_atomic_acquire_load_int(&p_xstream->state)) {
1690 state =
"TERMINATED";
1698 "%*s== ES (%p) ==\n"
1702 "%*sroot_ythread : %p\n"
1703 "%*sroot_pool : %p\n"
1705 "%*smain_sched : %p\n",
1706 indent,
"", (
void *)p_xstream, indent,
"", p_xstream->rank,
1707 indent,
"", type, indent,
"", state, indent,
"",
1708 (
void *)p_xstream->p_root_ythread, indent,
"",
1709 (
void *)p_xstream->p_root_pool, indent,
"",
1710 (
void *)p_xstream->p_thread, indent,
"",
1711 (
void *)p_xstream->p_main_sched);
1714 ABTI_sched_print(p_xstream->p_main_sched, p_os,
1717 fprintf(p_os,
"%*sctx :\n", indent,
"");
1718 ABTD_xstream_context_print(&p_xstream->ctx, p_os, indent + ABTI_INDENT);
1725 ABTI_xstream *p_local_xstream = (ABTI_xstream *)p_xstream;
1728 ABTI_local_set_xstream(p_local_xstream);
1731 ABTI_ythread *p_root_ythread = p_local_xstream->p_root_ythread;
1732 p_local_xstream->p_thread = &p_local_xstream->p_root_ythread->thread;
1733 p_root_ythread->thread.p_last_xstream = p_local_xstream;
1736 p_root_ythread->thread.f_thread(p_root_ythread->thread.p_arg);
1737 ABTI_thread_terminate(ABTI_global_get_global(), p_local_xstream,
1738 &p_root_ythread->thread);
1741 ABTI_local_set_xstream(NULL);
1750 ABTI_sched *p_sched,
1751 ABTI_xstream_type xstream_type,
int rank,
1753 ABTI_xstream **pp_xstream)
1755 int abt_errno, init_stage = 0;
1756 ABTI_xstream *p_newxstream;
1758 abt_errno =
ABTU_malloc(
sizeof(ABTI_xstream), (
void **)&p_newxstream);
1759 ABTI_CHECK_ERROR(abt_errno);
1761 p_newxstream->p_prev = NULL;
1762 p_newxstream->p_next = NULL;
1770 p_newxstream->type = xstream_type;
1771 ABTD_atomic_relaxed_store_int(&p_newxstream->state,
1773 p_newxstream->p_main_sched = NULL;
1774 p_newxstream->p_thread = NULL;
1775 abt_errno = ABTI_mem_init_local(p_global, p_newxstream);
1785 ABTI_ythread_create_root(p_global, ABTI_xstream_get_local(p_newxstream),
1786 p_newxstream, &p_newxstream->p_root_ythread);
1800 ABTI_ythread_create_main_sched(p_global,
1801 ABTI_xstream_get_local(p_newxstream),
1803 p_newxstream->p_main_sched);
1810 ABTI_ASSERT(ABTD_atomic_relaxed_load_int(&p_newxstream->state) ==
1812 ABTI_ASSERT(p_newxstream->type != ABTI_XSTREAM_TYPE_PRIMARY);
1815 (
void *)p_newxstream,
1816 &p_newxstream->ctx);
1822 if (p_global->set_affinity ==
ABT_TRUE) {
1823 ABTD_affinity_cpuset_apply_default(&p_newxstream->ctx,
1824 p_newxstream->rank);
1829 *pp_xstream = p_newxstream;
1832 if (init_stage >= 5) {
1833 ABTI_thread_free(p_global, ABTI_xstream_get_local(p_newxstream),
1834 &p_newxstream->p_main_sched->p_ythread->thread);
1835 p_newxstream->p_main_sched->p_ythread = NULL;
1837 if (init_stage >= 4) {
1838 ABTI_pool_free(p_newxstream->p_root_pool);
1840 if (init_stage >= 3) {
1841 ABTI_ythread_free_root(p_global, ABTI_xstream_get_local(p_newxstream),
1842 p_newxstream->p_root_ythread);
1844 if (init_stage >= 2) {
1845 p_sched->used = ABTI_SCHED_NOT_USED;
1846 ABTI_mem_finalize_local(p_newxstream);
1848 if (init_stage >= 1) {
1856 ABTI_xstream *p_xstream)
1859 ABTI_CHECK_TRUE(p_xstream->type != ABTI_XSTREAM_TYPE_PRIMARY,
1862 ABTI_CHECK_TRUE(!ABTI_local_get_xstream_or_null(*pp_local) ||
1863 &p_xstream->p_main_sched->p_ythread->thread !=
1864 ABTI_local_get_xstream(*pp_local)->p_thread,
1868 ABTI_sched_finish(p_xstream->p_main_sched);
1869 ABTI_thread_join(pp_local, &p_xstream->p_main_sched->p_ythread->thread);
1872 ABTD_xstream_context_join(&p_xstream->ctx);
1874 ABTI_ASSERT(ABTD_atomic_acquire_load_int(&p_xstream->state) ==
1880 ABTI_sched *p_sched)
1882 ABTI_ASSERT(p_xstream->p_main_sched == NULL);
1884 p_sched->used = ABTI_SCHED_MAIN;
1886 p_xstream->p_main_sched = p_sched;
1890 ABTI_xstream **pp_local_xstream,
1891 ABTI_xstream *p_xstream,
1892 ABTI_sched *p_sched)
1894 ABTI_sched *p_main_sched = p_xstream->p_main_sched;
1895 if (p_main_sched == NULL) {
1897 p_sched->used = ABTI_SCHED_MAIN;
1899 p_xstream->p_main_sched = p_sched;
1901 }
else if (*pp_local_xstream != p_xstream) {
1903 ABTI_ASSERT(p_xstream->ctx.state == ABTD_XSTREAM_CONTEXT_STATE_WAITING);
1906 ABTI_pool *p_tar_pool = ABTI_pool_get_ptr(p_sched->pools[0]);
1908 ABTI_thread_set_associated_pool(p_global,
1909 &p_main_sched->p_ythread->thread,
1911 ABTI_CHECK_ERROR(abt_errno);
1914 p_sched->used = ABTI_SCHED_MAIN;
1915 p_sched->p_ythread = p_main_sched->p_ythread;
1916 p_main_sched->p_ythread = NULL;
1918 p_xstream->p_main_sched->used = ABTI_SCHED_NOT_USED;
1919 if (p_xstream->p_main_sched->automatic) {
1921 ABTI_sched_free(p_global, ABTI_xstream_get_local(*pp_local_xstream),
1924 p_xstream->p_main_sched = p_sched;
1928 ABTI_thread *p_thread = (*pp_local_xstream)->p_thread;
1929 ABTI_ASSERT(p_thread->type & ABTI_THREAD_TYPE_YIELDABLE);
1930 ABTI_ythread *p_ythread = ABTI_thread_get_ythread(p_thread);
1931 ABTI_pool *p_tar_pool = ABTI_pool_get_ptr(p_sched->pools[0]);
1936 for (p = 0; p < p_main_sched->num_pools; p++) {
1937 if (p_ythread->thread.p_pool ==
1938 ABTI_pool_get_ptr(p_main_sched->pools[p])) {
1941 ABTI_thread_set_associated_pool(p_global,
1944 ABTI_CHECK_ERROR(abt_errno);
1948 if (p_main_sched->p_replace_sched) {
1950 ABTI_ythread *p_waiter = p_main_sched->p_replace_waiter;
1951 ABTI_sched_discard_and_free(p_global,
1952 ABTI_xstream_get_local(
1954 p_main_sched->p_replace_sched,
1956 p_main_sched->p_replace_sched = NULL;
1957 p_main_sched->p_replace_waiter = NULL;
1960 ABTI_ythread_resume_and_push(ABTI_xstream_get_local(
1965 p_main_sched->p_replace_sched = p_sched;
1966 p_main_sched->p_replace_waiter = p_ythread;
1972 ABTI_ythread_suspend_replace_sched(pp_local_xstream, p_ythread,
1982 if (newrank >= p_global->max_xstreams) {
1983 static int max_xstreams_warning_once = 0;
1984 if (max_xstreams_warning_once == 0) {
1992 char *warning_message;
1994 ABTU_malloc(
sizeof(
char) * 1024, (
void **)&warning_message);
1995 if (!ABTI_IS_ERROR_CHECK_ENABLED || abt_errno ==
ABT_SUCCESS) {
1996 snprintf(warning_message, 1024,
1997 "Warning: the number of execution streams exceeds "
1998 "ABT_MAX_NUM_XSTREAMS (=%d). This may cause an error.",
1999 p_global->max_xstreams);
2002 max_xstreams_warning_once = 1;
2006 p_global->max_xstreams = newrank + 1;
2012 ABTI_xstream *p_newxstream)
2014 int rank = p_newxstream->rank;
2015 ABTI_xstream *p_prev_xstream = p_global->p_xstream_head;
2016 ABTI_xstream *p_xstream = p_prev_xstream;
2019 ABTI_ASSERT(p_xstream->rank != rank);
2020 if (p_xstream->rank > rank) {
2024 p_prev_xstream = p_xstream;
2025 p_xstream = p_xstream->p_next;
2030 if (p_prev_xstream) {
2031 p_prev_xstream->p_next = p_newxstream;
2032 p_newxstream->p_prev = p_prev_xstream;
2033 p_newxstream->p_next = NULL;
2035 ABTI_ASSERT(p_global->p_xstream_head == NULL);
2036 p_newxstream->p_prev = NULL;
2037 p_newxstream->p_next = NULL;
2038 p_global->p_xstream_head = p_newxstream;
2043 if (p_xstream->p_prev) {
2044 p_xstream->p_prev->p_next = p_newxstream;
2045 p_newxstream->p_prev = p_xstream->p_prev;
2048 ABTI_ASSERT(p_global->p_xstream_head == p_xstream);
2049 p_global->p_xstream_head = p_newxstream;
2051 p_xstream->p_prev = p_newxstream;
2052 p_newxstream->p_next = p_xstream;
2058 ABTI_xstream *p_xstream)
2060 if (!p_xstream->p_prev) {
2061 ABTI_ASSERT(p_global->p_xstream_head == p_xstream);
2062 p_global->p_xstream_head = p_xstream->p_next;
2064 p_xstream->p_prev->p_next = p_xstream->p_next;
2066 if (p_xstream->p_next) {
2067 p_xstream->p_next->p_prev = p_xstream->p_prev;
2073 ABTI_xstream *p_newxstream,
int rank)
2075 ABTD_spinlock_acquire(&p_global->xstream_list_lock);
2080 ABTI_xstream *p_xstream = p_global->p_xstream_head;
2082 if (p_xstream->rank == rank) {
2088 p_xstream = p_xstream->p_next;
2092 ABTI_xstream *p_xstream = p_global->p_xstream_head;
2094 if (p_xstream->rank == rank) {
2095 ABTD_spinlock_release(&p_global->xstream_list_lock);
2097 }
else if (p_xstream->rank > rank) {
2100 p_xstream = p_xstream->p_next;
2104 p_newxstream->rank = rank;
2107 p_global->num_xstreams++;
2109 ABTD_spinlock_release(&p_global->xstream_list_lock);
2115 ABTI_xstream *p_xstream,
int rank)
2117 if (p_xstream->rank == rank) {
2122 ABTD_spinlock_acquire(&p_global->xstream_list_lock);
2124 ABTI_xstream *p_next = p_global->p_xstream_head;
2127 if (p_next->rank == rank) {
2128 ABTD_spinlock_release(&p_global->xstream_list_lock);
2130 }
else if (p_next->rank > rank) {
2133 p_next = p_next->p_next;
2138 p_xstream->rank = rank;
2142 ABTD_spinlock_release(&p_global->xstream_list_lock);
2149 ABTD_spinlock_acquire(&p_global->xstream_list_lock);
2152 p_global->num_xstreams--;
2154 ABTD_spinlock_release(&p_global->xstream_list_lock);