ARGOBOTS  140a356fc09a44696eb3487150e459266f9b5405
stream.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 
8 ABTU_ret_err static int xstream_create(ABTI_sched *p_sched,
9  ABTI_xstream_type xstream_type, int rank,
10  ABTI_xstream **pp_xstream);
11 ABTU_ret_err static int xstream_start(ABTI_xstream *p_xstream);
12 ABTU_ret_err static int xstream_join(ABTI_local **pp_local,
13  ABTI_xstream *p_xstream);
14 static ABT_bool xstream_set_new_rank(ABTI_xstream *p_newxstream, int rank);
15 static ABT_bool xstream_change_rank(ABTI_xstream *p_xstream, int rank);
16 static void xstream_return_rank(ABTI_xstream *p_xstream);
17 static inline void xstream_schedule_ythread(ABTI_xstream **pp_local_xstream,
18  ABTI_ythread *p_ythread);
19 static inline void xstream_schedule_task(ABTI_xstream *p_local_xstream,
20  ABTI_thread *p_task);
21 static void xstream_init_main_sched(ABTI_xstream *p_xstream,
22  ABTI_sched *p_sched);
23 static void xstream_update_main_sched(ABTI_xstream **pp_local_xstream,
24  ABTI_xstream *p_xstream,
25  ABTI_sched *p_sched);
26 static void *xstream_launch_root_ythread(void *p_xstream);
27 #ifndef ABT_CONFIG_DISABLE_MIGRATION
29  ABTI_thread *p_thread);
30 #endif
31 
80 int ABT_xstream_create(ABT_sched sched, ABT_xstream *newxstream)
81 {
82 #ifndef ABT_CONFIG_ENABLE_VER_20_API
83  /* Argobots 1.x sets newxstream to NULL on error. */
84  *newxstream = ABT_XSTREAM_NULL;
85 #endif
86  int abt_errno;
87  ABTI_sched *p_sched;
88  ABTI_xstream *p_newxstream;
89 
90  if (sched == ABT_SCHED_NULL) {
91  abt_errno =
92  ABTI_sched_create_basic(ABT_SCHED_DEFAULT, 0, NULL, NULL, &p_sched);
93  ABTI_CHECK_ERROR(abt_errno);
94  } else {
95  p_sched = ABTI_sched_get_ptr(sched);
96 #ifndef ABT_CONFIG_ENABLE_VER_20_API
99 #endif
100  }
101 
102  abt_errno =
103  xstream_create(p_sched, ABTI_XSTREAM_TYPE_SECONDARY, -1, &p_newxstream);
104  ABTI_CHECK_ERROR(abt_errno);
105 
106  /* Start this ES */
107  abt_errno = xstream_start(p_newxstream);
108  ABTI_CHECK_ERROR(abt_errno);
109 
110  /* Return value */
111  *newxstream = ABTI_xstream_get_handle(p_newxstream);
112  return ABT_SUCCESS;
113 }
114 
168 int ABT_xstream_create_basic(ABT_sched_predef predef, int num_pools,
169  ABT_pool *pools, ABT_sched_config config,
170  ABT_xstream *newxstream)
171 {
172 #ifndef ABT_CONFIG_ENABLE_VER_20_API
173  /* Argobots 1.x sets newxstream to NULL on error. */
174  *newxstream = ABT_XSTREAM_NULL;
175 #endif
176  ABTI_CHECK_TRUE(num_pools >= 0, ABT_ERR_INV_ARG);
177 
178  int abt_errno;
179  ABTI_xstream *p_newxstream;
180  ABTI_sched_config *p_config = ABTI_sched_config_get_ptr(config);
181 
182  ABTI_sched *p_sched;
183  abt_errno =
184  ABTI_sched_create_basic(predef, num_pools, pools, p_config, &p_sched);
185  ABTI_CHECK_ERROR(abt_errno);
186 
187  abt_errno =
188  xstream_create(p_sched, ABTI_XSTREAM_TYPE_SECONDARY, -1, &p_newxstream);
189  ABTI_CHECK_ERROR(abt_errno);
190 
191  /* Start this ES */
192  abt_errno = xstream_start(p_newxstream);
193  ABTI_CHECK_ERROR(abt_errno);
194 
195  *newxstream = ABTI_xstream_get_handle(p_newxstream);
196  return ABT_SUCCESS;
197 }
198 
251  ABT_xstream *newxstream)
252 {
253 #ifndef ABT_CONFIG_ENABLE_VER_20_API
254  /* Argobots 1.x sets newxstream to NULL on error. */
255  *newxstream = ABT_XSTREAM_NULL;
256 #endif
257  int abt_errno;
258  ABTI_sched *p_sched;
259  ABTI_xstream *p_newxstream;
260 
262 
263  if (sched == ABT_SCHED_NULL) {
264  abt_errno =
265  ABTI_sched_create_basic(ABT_SCHED_DEFAULT, 0, NULL, NULL, &p_sched);
266  ABTI_CHECK_ERROR(abt_errno);
267  } else {
268  p_sched = ABTI_sched_get_ptr(sched);
269 #ifndef ABT_CONFIG_ENABLE_VER_20_API
272 #endif
273  }
274 
275  abt_errno = xstream_create(p_sched, ABTI_XSTREAM_TYPE_SECONDARY, rank,
276  &p_newxstream);
277  if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno != ABT_SUCCESS) {
278  if (sched == ABT_SCHED_NULL)
280  ABT_FALSE);
281  ABTI_HANDLE_ERROR(abt_errno);
282  }
283 
284  /* Start this ES */
285  abt_errno = xstream_start(p_newxstream);
286  ABTI_CHECK_ERROR(abt_errno);
287 
288  /* Return value */
289  *newxstream = ABTI_xstream_get_handle(p_newxstream);
290  return ABT_SUCCESS;
291 }
292 
324 {
325  ABTI_local *p_local = ABTI_local_get_local();
326  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
327  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
328 
329  /* Revives the main scheduler thread. */
330  ABTI_sched *p_main_sched = p_xstream->p_main_sched;
331  ABTI_ythread *p_main_sched_ythread = p_main_sched->p_ythread;
332  /* TODO: should we check the thread state instead of the xstream state? */
334  &p_main_sched_ythread->thread.state) ==
337 
338  ABTD_atomic_relaxed_store_uint32(&p_main_sched->request, 0);
339  ABTI_tool_event_thread_join(p_local, &p_main_sched_ythread->thread,
341  ? ABTI_local_get_xstream(p_local)->p_thread
342  : NULL);
343 
344  ABTI_thread_revive(p_local, p_xstream->p_root_pool,
345  p_main_sched_ythread->thread.f_thread,
346  p_main_sched_ythread->thread.p_arg,
347  &p_main_sched_ythread->thread);
348 
350  ABTD_xstream_context_revive(&p_xstream->ctx);
351  return ABT_SUCCESS;
352 }
353 
395 int ABT_xstream_free(ABT_xstream *xstream)
396 {
397  ABTI_local *p_local = ABTI_local_get_local();
398  ABT_xstream h_xstream = *xstream;
399 
400  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(h_xstream);
401  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
402 
403  /* We first need to check whether p_local_xstream is NULL because this
404  * routine might be called by external threads. */
407  "The current xstream cannot be freed.");
408 
411  "The primary xstream cannot be freed explicitly.");
412 
413  /* Wait until xstream terminates */
414  int abt_errno = xstream_join(&p_local, p_xstream);
415  ABTI_CHECK_ERROR(abt_errno);
416 
417  /* Free the xstream object */
418  ABTI_xstream_free(p_local, p_xstream, ABT_FALSE);
419 
420  /* Return value */
421  *xstream = ABT_XSTREAM_NULL;
422  return ABT_SUCCESS;
423 }
424 
456 int ABT_xstream_join(ABT_xstream xstream)
457 {
458  ABTI_local *p_local = ABTI_local_get_local();
459  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
460  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
461 
462  int abt_errno = xstream_join(&p_local, p_xstream);
463  ABTI_CHECK_ERROR(abt_errno);
464  return ABT_SUCCESS;
465 }
466 
500 int ABT_xstream_exit(void)
501 {
502  ABTI_xstream *p_local_xstream;
503  ABTI_ythread *p_ythread;
504 #ifndef ABT_CONFIG_ENABLE_VER_20_API
505  ABTI_SETUP_LOCAL_YTHREAD_WITH_INIT_CHECK(&p_local_xstream, &p_ythread);
506 #else
507  ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, &p_ythread);
508 #endif
509  /* Check if the target is the primary executions stream. */
510  ABTI_CHECK_TRUE(p_local_xstream->type != ABTI_XSTREAM_TYPE_PRIMARY,
512 
513  /* Terminate the main scheduler. */
515  ->thread.request,
517  /* Terminate this ULT */
518  ABTI_ythread_exit(p_local_xstream, p_ythread);
520  return ABT_SUCCESS;
521 }
522 
551 int ABT_xstream_cancel(ABT_xstream xstream)
552 {
553  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
554  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
557 
558  /* Terminate the main scheduler of the target xstream. */
560  .request,
562  return ABT_SUCCESS;
563 }
564 
594 int ABT_xstream_self(ABT_xstream *xstream)
595 {
596  ABTI_xstream *p_local_xstream;
597 #ifndef ABT_CONFIG_ENABLE_VER_20_API
598  *xstream = ABT_XSTREAM_NULL;
600 #else
601  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
602 #endif
603 
604  /* Return value */
605  *xstream = ABTI_xstream_get_handle(p_local_xstream);
606  return ABT_SUCCESS;
607 }
608 
636 int ABT_xstream_self_rank(int *rank)
637 {
638  ABTI_xstream *p_local_xstream;
639 #ifndef ABT_CONFIG_ENABLE_VER_20_API
641 #else
642  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
643 #endif
644  /* Return value */
645  *rank = (int)p_local_xstream->rank;
646  return ABT_SUCCESS;
647 }
648 
684 int ABT_xstream_set_rank(ABT_xstream xstream, int rank)
685 {
686  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
687  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
691  ABT_bool is_changed = xstream_change_rank(p_xstream, rank);
693 
694  /* Set the CPU affinity for the ES */
696  ABTD_affinity_cpuset_apply_default(&p_xstream->ctx, p_xstream->rank);
697  }
698  return ABT_SUCCESS;
699 }
700 
725 int ABT_xstream_get_rank(ABT_xstream xstream, int *rank)
726 {
727  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
728  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
729 
730  *rank = (int)p_xstream->rank;
731  return ABT_SUCCESS;
732 }
733 
813 {
814  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
816 
817  ABTI_xstream *p_local_xstream;
818  ABTI_ythread *p_self;
819  ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, &p_self);
820 
821 #ifndef ABT_CONFIG_ENABLE_VER_20_API
824  p_local_xstream == p_xstream,
826 #else
829  p_local_xstream == p_xstream,
831 #endif
832 
833  ABTI_sched *p_sched;
834  if (sched == ABT_SCHED_NULL) {
835  int abt_errno =
836  ABTI_sched_create_basic(ABT_SCHED_DEFAULT, 0, NULL, NULL, &p_sched);
837  ABTI_CHECK_ERROR(abt_errno);
838  } else {
839  p_sched = ABTI_sched_get_ptr(sched);
840 #ifndef ABT_CONFIG_ENABLE_VER_20_API
843 #endif
844  }
845 
846  xstream_update_main_sched(&p_local_xstream, p_xstream, p_sched);
847  return ABT_SUCCESS;
848 }
849 
908  ABT_sched_predef predef, int num_pools,
909  ABT_pool *pools)
910 {
911  ABTI_xstream *p_local_xstream;
912  ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, NULL);
913 
914  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
915  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
916 
917  ABTI_sched *p_sched;
918  int abt_errno =
919  ABTI_sched_create_basic(predef, num_pools, pools, NULL, &p_sched);
920  ABTI_CHECK_ERROR(abt_errno);
921 
922  xstream_update_main_sched(&p_local_xstream, p_xstream, p_sched);
923  return ABT_SUCCESS;
924 }
925 
949 {
950  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
952 
953  *sched = ABTI_sched_get_handle(p_xstream->p_main_sched);
954  return ABT_SUCCESS;
955 }
956 
985 int ABT_xstream_get_main_pools(ABT_xstream xstream, int max_pools,
986  ABT_pool *pools)
987 {
988  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
989  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
990 
991  ABTI_sched *p_sched = p_xstream->p_main_sched;
992  max_pools = ABTU_min_int(p_sched->num_pools, max_pools);
993  memcpy(pools, p_sched->pools, sizeof(ABT_pool) * max_pools);
994  return ABT_SUCCESS;
995 }
996 
1022 {
1023  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1025 
1026  *state = (ABT_xstream_state)ABTD_atomic_acquire_load_int(&p_xstream->state);
1027  return ABT_SUCCESS;
1028 }
1029 
1057 int ABT_xstream_equal(ABT_xstream xstream1, ABT_xstream xstream2,
1058  ABT_bool *result)
1059 {
1060  ABTI_xstream *p_xstream1 = ABTI_xstream_get_ptr(xstream1);
1061  ABTI_xstream *p_xstream2 = ABTI_xstream_get_ptr(xstream2);
1062  *result = (p_xstream1 == p_xstream2) ? ABT_TRUE : ABT_FALSE;
1063  return ABT_SUCCESS;
1064 }
1065 
1094 int ABT_xstream_get_num(int *num_xstreams)
1095 {
1096 #ifndef ABT_CONFIG_ENABLE_VER_20_API
1098 #endif
1099 
1100  *num_xstreams = gp_ABTI_global->num_xstreams;
1101  return ABT_SUCCESS;
1102 }
1103 
1128 int ABT_xstream_is_primary(ABT_xstream xstream, ABT_bool *is_primary)
1129 {
1130  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1132 
1133  /* Return value */
1134  *is_primary =
1135  (p_xstream->type == ABTI_XSTREAM_TYPE_PRIMARY) ? ABT_TRUE : ABT_FALSE;
1136  return ABT_SUCCESS;
1137 }
1138 
1166 int ABT_xstream_run_unit(ABT_unit unit, ABT_pool pool)
1167 {
1168  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1171 
1172  ABTI_xstream *p_local_xstream;
1173  ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, NULL);
1174 
1175  ABTI_xstream_run_unit(&p_local_xstream, unit, p_pool);
1176  return ABT_SUCCESS;
1177 }
1178 
1215 {
1216  ABTI_xstream *p_local_xstream;
1217 #ifndef ABT_CONFIG_ENABLE_VER_20_API
1218  ABTI_SETUP_LOCAL_XSTREAM_WITH_INIT_CHECK(&p_local_xstream);
1219 #else
1220  ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
1221 #endif
1222 
1223  ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
1224  ABTI_CHECK_NULL_SCHED_PTR(p_sched);
1225  ABTI_CHECK_TRUE(p_local_xstream->p_thread == &p_sched->p_ythread->thread,
1227 
1228  ABTI_xstream_check_events(p_local_xstream, p_sched);
1229  return ABT_SUCCESS;
1230 }
1231 
1260 int ABT_xstream_set_cpubind(ABT_xstream xstream, int cpuid)
1261 {
1262  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1264 
1265  ABTD_affinity_cpuset cpuset;
1266  cpuset.num_cpuids = 1;
1267  cpuset.cpuids = &cpuid;
1268  int abt_errno = ABTD_affinity_cpuset_apply(&p_xstream->ctx, &cpuset);
1269  /* Do not free cpuset since cpuids points to a user pointer. */
1270  ABTI_CHECK_ERROR(abt_errno);
1271  return ABT_SUCCESS;
1272 }
1273 
1309 int ABT_xstream_get_cpubind(ABT_xstream xstream, int *cpuid)
1310 {
1311  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1312  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1314  int num_cpuid;
1315  int cpuids[1];
1316  int abt_errno =
1317  ABTD_affinity_cpuset_read(&p_xstream->ctx, 1, cpuids, &num_cpuid);
1318  ABTI_CHECK_ERROR(abt_errno);
1319  ABTI_CHECK_TRUE(num_cpuid > 0, ABT_ERR_CPUID);
1320 
1321  *cpuid = cpuids[0];
1322  return ABT_SUCCESS;
1323 }
1324 
1358 int ABT_xstream_set_affinity(ABT_xstream xstream, int num_cpuids, int *cpuids)
1359 {
1360  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1361  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1363 
1364  ABTD_affinity_cpuset affinity;
1365  affinity.num_cpuids = num_cpuids;
1366  affinity.cpuids = cpuids;
1367  int abt_errno = ABTD_affinity_cpuset_apply(&p_xstream->ctx, &affinity);
1368  /* Do not free affinity since cpuids may not be freed. */
1369  ABTI_CHECK_ERROR(abt_errno);
1370  return ABT_SUCCESS;
1371 }
1372 
1421 int ABT_xstream_get_affinity(ABT_xstream xstream, int max_cpuids, int *cpuids,
1422  int *num_cpuids)
1423 {
1424  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1425  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1427 
1428  int abt_errno = ABTD_affinity_cpuset_read(&p_xstream->ctx, max_cpuids,
1429  cpuids, num_cpuids);
1430  ABTI_CHECK_ERROR(abt_errno);
1431  return abt_errno;
1432 }
1433 
1434 /*****************************************************************************/
1435 /* Private APIs */
1436 /*****************************************************************************/
1437 
1439 {
1440  int abt_errno;
1441  ABTI_xstream *p_newxstream;
1442  ABTI_sched *p_sched;
1444  /* For the primary ES, a default scheduler is created. */
1445  abt_errno =
1446  ABTI_sched_create_basic(ABT_SCHED_DEFAULT, 0, NULL, NULL, &p_sched);
1447  ABTI_CHECK_ERROR(abt_errno);
1448 
1449  abt_errno =
1450  xstream_create(p_sched, ABTI_XSTREAM_TYPE_PRIMARY, -1, &p_newxstream);
1451  ABTI_CHECK_ERROR(abt_errno);
1452 
1453  *pp_xstream = p_newxstream;
1454  return ABT_SUCCESS;
1455 }
1456 
1457 /* This routine starts the primary ES. It should be called in ABT_init. */
1458 void ABTI_xstream_start_primary(ABTI_xstream **pp_local_xstream,
1459  ABTI_xstream *p_xstream,
1460  ABTI_ythread *p_ythread)
1461 {
1462  /* p_ythread must be the main thread. */
1464  /* The ES's state must be running here. */
1467 
1468  LOG_DEBUG("[E%d] start\n", p_xstream->rank);
1469 
1470  ABTD_xstream_context_set_self(&p_xstream->ctx);
1471 
1472  /* Set the CPU affinity for the ES */
1474  ABTD_affinity_cpuset_apply_default(&p_xstream->ctx, p_xstream->rank);
1475  }
1476 
1477  /* Context switch to the root thread. */
1478  p_xstream->p_root_ythread->thread.p_last_xstream = p_xstream;
1479  ABTD_ythread_context_switch(&p_ythread->ctx,
1480  &p_xstream->p_root_ythread->ctx);
1481  /* Come back to the primary thread. Now this thread is executed on top of
1482  * the main scheduler, which is running on the root thread. */
1483  (*pp_local_xstream)->p_thread = &p_ythread->thread;
1484 }
1485 
1486 void ABTI_xstream_run_unit(ABTI_xstream **pp_local_xstream, ABT_unit unit,
1487  ABTI_pool *p_pool)
1488 {
1489  ABT_thread thread = p_pool->u_get_thread(unit);
1490  ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1492  if (p_thread->type & ABTI_THREAD_TYPE_YIELDABLE) {
1493  ABTI_ythread *p_ythread = ABTI_thread_get_ythread(p_thread);
1494  /* Execute a ULT */
1495  xstream_schedule_ythread(pp_local_xstream, p_ythread);
1496  } else {
1497  /* Execute a tasklet */
1498  xstream_schedule_task(*pp_local_xstream, p_thread);
1499  }
1500 }
1501 
1502 void ABTI_xstream_check_events(ABTI_xstream *p_xstream, ABTI_sched *p_sched)
1503 {
1505 
1506  uint32_t request = ABTD_atomic_acquire_load_uint32(
1508  if (request & ABTI_THREAD_REQ_JOIN) {
1509  ABTI_sched_finish(p_sched);
1510  }
1511 
1512  if ((request & ABTI_THREAD_REQ_TERMINATE) ||
1513  (request & ABTI_THREAD_REQ_CANCEL)) {
1514  ABTI_sched_exit(p_sched);
1515  }
1516 }
1517 
1518 void ABTI_xstream_free(ABTI_local *p_local, ABTI_xstream *p_xstream,
1519  ABT_bool force_free)
1520 {
1521  LOG_DEBUG("[E%d] freed\n", p_xstream->rank);
1522 
1523  /* Clean up memory pool. */
1524  ABTI_mem_finalize_local(p_xstream);
1525  /* Return rank for reuse. rank must be returned prior to other free
1526  * functions so that other xstreams cannot refer to this xstream. */
1527  xstream_return_rank(p_xstream);
1528 
1529  /* Free the scheduler */
1530  ABTI_sched *p_cursched = p_xstream->p_main_sched;
1531  if (p_cursched != NULL) {
1532  /* Join a scheduler thread. */
1533  ABTI_tool_event_thread_join(p_local, &p_cursched->p_ythread->thread,
1535  ? ABTI_local_get_xstream(p_local)
1536  ->p_thread
1537  : NULL);
1538  ABTI_sched_discard_and_free(p_local, p_cursched, force_free);
1539  /* The main scheduler thread is also freed. */
1540  }
1541 
1542  /* Free the root thread and pool. */
1543  ABTI_ythread_free_root(p_local, p_xstream->p_root_ythread);
1544  ABTI_pool_free(p_xstream->p_root_pool);
1545 
1546  /* Free the context if a given xstream is secondary. */
1547  if (p_xstream->type == ABTI_XSTREAM_TYPE_SECONDARY) {
1548  ABTD_xstream_context_free(&p_xstream->ctx);
1549  }
1550 
1551  ABTU_free(p_xstream);
1552 }
1553 
1554 void ABTI_xstream_print(ABTI_xstream *p_xstream, FILE *p_os, int indent,
1555  ABT_bool print_sub)
1556 {
1557  if (p_xstream == NULL) {
1558  fprintf(p_os, "%*s== NULL ES ==\n", indent, "");
1559  } else {
1560  const char *type, *state;
1561  switch (p_xstream->type) {
1563  type = "PRIMARY";
1564  break;
1566  type = "SECONDARY";
1567  break;
1568  default:
1569  type = "UNKNOWN";
1570  break;
1571  }
1572  switch (ABTD_atomic_acquire_load_int(&p_xstream->state)) {
1574  state = "RUNNING";
1575  break;
1577  state = "TERMINATED";
1578  break;
1579  default:
1580  state = "UNKNOWN";
1581  break;
1582  }
1583 
1584  fprintf(p_os,
1585  "%*s== ES (%p) ==\n"
1586  "%*srank : %d\n"
1587  "%*stype : %s\n"
1588  "%*sstate : %s\n"
1589  "%*sroot_ythread : %p\n"
1590  "%*sroot_pool : %p\n"
1591  "%*sthread : %p\n"
1592  "%*smain_sched : %p\n",
1593  indent, "", (void *)p_xstream, indent, "", p_xstream->rank,
1594  indent, "", type, indent, "", state, indent, "",
1595  (void *)p_xstream->p_root_ythread, indent, "",
1596  (void *)p_xstream->p_root_pool, indent, "",
1597  (void *)p_xstream->p_thread, indent, "",
1598  (void *)p_xstream->p_main_sched);
1599 
1600  if (print_sub == ABT_TRUE) {
1601  ABTI_sched_print(p_xstream->p_main_sched, p_os,
1602  indent + ABTI_INDENT, ABT_TRUE);
1603  }
1604  fprintf(p_os, "%*sctx :\n", indent, "");
1605  ABTD_xstream_context_print(&p_xstream->ctx, p_os, indent + ABTI_INDENT);
1606  }
1607  fflush(p_os);
1608 }
1609 
1610 static void *xstream_launch_root_ythread(void *p_xstream)
1611 {
1612  ABTI_xstream *p_local_xstream = (ABTI_xstream *)p_xstream;
1613 
1614  /* Initialization of the local variables */
1615  ABTI_local_set_xstream(p_local_xstream);
1616 
1617  LOG_DEBUG("[E%d] start\n", p_local_xstream->rank);
1618 
1619  /* Set the root thread as the current thread */
1620  ABTI_ythread *p_root_ythread = p_local_xstream->p_root_ythread;
1621  p_local_xstream->p_thread = &p_local_xstream->p_root_ythread->thread;
1622  p_root_ythread->thread.f_thread(p_root_ythread->thread.p_arg);
1623 
1624  LOG_DEBUG("[E%d] end\n", p_local_xstream->rank);
1625 
1626  /* Reset the current ES and its local info. */
1627  ABTI_local_set_xstream(NULL);
1628  return NULL;
1629 }
1630 
1631 /*****************************************************************************/
1632 /* Internal static functions */
1633 /*****************************************************************************/
1634 
1635 ABTU_ret_err static int xstream_create(ABTI_sched *p_sched,
1636  ABTI_xstream_type xstream_type, int rank,
1637  ABTI_xstream **pp_xstream)
1638 {
1639  int abt_errno;
1640  ABTI_xstream *p_newxstream;
1641 
1642  abt_errno = ABTU_malloc(sizeof(ABTI_xstream), (void **)&p_newxstream);
1643  ABTI_CHECK_ERROR(abt_errno);
1644 
1645  p_newxstream->p_prev = NULL;
1646  p_newxstream->p_next = NULL;
1647 
1648  if (xstream_set_new_rank(p_newxstream, rank) == ABT_FALSE) {
1649  ABTU_free(p_newxstream);
1650  return ABT_ERR_INV_XSTREAM_RANK;
1651  }
1652 
1653  p_newxstream->type = xstream_type;
1654  ABTD_atomic_relaxed_store_int(&p_newxstream->state,
1656  p_newxstream->p_main_sched = NULL;
1657  p_newxstream->p_thread = NULL;
1658  ABTI_mem_init_local(p_newxstream);
1659 
1660  /* Set the main scheduler */
1661  xstream_init_main_sched(p_newxstream, p_sched);
1662 
1663  /* Create the root thread. */
1664  abt_errno =
1666  p_newxstream, &p_newxstream->p_root_ythread);
1667  ABTI_CHECK_ERROR(abt_errno);
1668 
1669  /* Create the root pool. */
1671  ABT_FALSE, &p_newxstream->p_root_pool);
1672  ABTI_CHECK_ERROR(abt_errno);
1673 
1674  /* Create the main scheduler thread. */
1675  abt_errno =
1677  p_newxstream,
1678  p_newxstream->p_main_sched);
1679  ABTI_CHECK_ERROR(abt_errno);
1680 
1681  LOG_DEBUG("[E%d] created\n", p_newxstream->rank);
1682 
1683  /* Return value */
1684  *pp_xstream = p_newxstream;
1685  return ABT_SUCCESS;
1686 }
1687 
1688 ABTU_ret_err static int xstream_start(ABTI_xstream *p_xstream)
1689 {
1690  /* The ES's state must be RUNNING */
1694  /* Start the main scheduler on a different ES */
1695  int abt_errno =
1697  (void *)p_xstream, &p_xstream->ctx);
1698  ABTI_CHECK_ERROR(abt_errno);
1699 
1700  /* Set the CPU affinity for the ES */
1702  ABTD_affinity_cpuset_apply_default(&p_xstream->ctx, p_xstream->rank);
1703  }
1704  return ABT_SUCCESS;
1705 }
1706 
1707 ABTU_ret_err static int xstream_join(ABTI_local **pp_local,
1708  ABTI_xstream *p_xstream)
1709 {
1710  /* The primary ES cannot be joined. */
1713  /* The main scheduler cannot join itself. */
1715  &p_xstream->p_main_sched->p_ythread->thread !=
1716  ABTI_local_get_xstream(*pp_local)->p_thread,
1718 
1719  /* Wait until the target ES terminates */
1720  ABTI_sched_finish(p_xstream->p_main_sched);
1721  ABTI_thread_join(pp_local, &p_xstream->p_main_sched->p_ythread->thread);
1722 
1723  /* Normal join request */
1724  ABTD_xstream_context_join(&p_xstream->ctx);
1725 
1728  return ABT_SUCCESS;
1729 }
1730 
1731 static inline void xstream_schedule_ythread(ABTI_xstream **pp_local_xstream,
1732  ABTI_ythread *p_ythread)
1733 {
1734  ABTI_xstream *p_local_xstream = *pp_local_xstream;
1735 
1736 #ifndef ABT_CONFIG_DISABLE_THREAD_CANCEL
1739  LOG_DEBUG("[U%" PRIu64 ":E%d] canceled\n",
1740  ABTI_thread_get_id(&p_ythread->thread),
1741  p_local_xstream->rank);
1742  ABTD_ythread_cancel(p_local_xstream, p_ythread);
1744  &p_ythread->thread);
1745  return;
1746  }
1747 #endif
1748 
1749 #ifndef ABT_CONFIG_DISABLE_MIGRATION
1752  int abt_errno =
1754  &p_ythread->thread);
1755  if (!ABTI_IS_ERROR_CHECK_ENABLED || abt_errno == ABT_SUCCESS) {
1756  /* Migration succeeded, so we do not need to schedule p_ythread. */
1757  return;
1758  }
1759  }
1760 #endif
1761 
1762  /* Change the last ES */
1763  p_ythread->thread.p_last_xstream = p_local_xstream;
1764 
1765  /* Change the ULT state */
1768 
1769  /* Switch the context */
1770  LOG_DEBUG("[U%" PRIu64 ":E%d] start running\n",
1771  ABTI_thread_get_id(&p_ythread->thread), p_local_xstream->rank);
1772 
1773  /* Since the argument is pp_local_xstream, p_local_xstream->p_thread must be
1774  * yieldable. */
1775  ABTI_ythread *p_self = ABTI_thread_get_ythread(p_local_xstream->p_thread);
1776  p_ythread = ABTI_ythread_context_switch_to_child(pp_local_xstream, p_self,
1777  p_ythread);
1778  /* The previous ULT (p_ythread) may not be the same as one to which the
1779  * context has been switched. */
1780  /* The scheduler continues from here. */
1781  p_local_xstream = *pp_local_xstream;
1782 
1783  LOG_DEBUG("[U%" PRIu64 ":E%d] stopped\n",
1784  ABTI_thread_get_id(&p_ythread->thread), p_local_xstream->rank);
1785 
1786  /* Request handling. */
1787  /* We do not need to acquire-load request since all critical requests
1788  * (BLOCK, ORPHAN, STOP, and NOPUSH) are written by p_ythread. CANCEL might
1789  * be delayed. */
1790  uint32_t request =
1792  if (request & ABTI_THREAD_REQ_TERMINATE) {
1793  /* The ULT has completed its execution or it called the exit request. */
1794  LOG_DEBUG("[U%" PRIu64 ":E%d] finished\n",
1795  ABTI_thread_get_id(&p_ythread->thread),
1796  p_local_xstream->rank);
1798  &p_ythread->thread);
1799 #ifndef ABT_CONFIG_DISABLE_THREAD_CANCEL
1800  } else if (request & ABTI_THREAD_REQ_CANCEL) {
1801  LOG_DEBUG("[U%" PRIu64 ":E%d] canceled\n",
1802  ABTI_thread_get_id(&p_ythread->thread),
1803  p_local_xstream->rank);
1804  ABTD_ythread_cancel(p_local_xstream, p_ythread);
1806  &p_ythread->thread);
1807 #endif
1808  } else if (!(request & ABTI_THREAD_REQ_NON_YIELD)) {
1809  /* The ULT did not finish its execution.
1810  * Change the state of current running ULT and
1811  * add it to the pool again. */
1812  ABTI_pool_add_thread(&p_ythread->thread);
1813  } else if (request & ABTI_THREAD_REQ_BLOCK) {
1814  LOG_DEBUG("[U%" PRIu64 ":E%d] check blocked\n",
1815  ABTI_thread_get_id(&p_ythread->thread),
1816  p_local_xstream->rank);
1818 #ifndef ABT_CONFIG_DISABLE_MIGRATION
1819  } else if (request & ABTI_THREAD_REQ_MIGRATE) {
1820  /* This is the case when the ULT requests migration of itself. */
1821  int abt_errno =
1823  &p_ythread->thread);
1824  /* Migration is optional, so it is okay if it fails. */
1825  (void)abt_errno;
1826 #endif
1827  } else if (request & ABTI_THREAD_REQ_ORPHAN) {
1828  /* The ULT is not pushed back to the pool and is disconnected from any
1829  * pool. */
1830  LOG_DEBUG("[U%" PRIu64 ":E%d] orphaned\n",
1831  ABTI_thread_get_id(&p_ythread->thread),
1832  p_local_xstream->rank);
1834  p_ythread->thread.p_pool->u_free(&p_ythread->thread.unit);
1835  p_ythread->thread.p_pool = NULL;
1836  } else if (request & ABTI_THREAD_REQ_NOPUSH) {
1837  /* The ULT is not pushed back to the pool */
1838  LOG_DEBUG("[U%" PRIu64 ":E%d] not pushed\n",
1839  ABTI_thread_get_id(&p_ythread->thread),
1840  p_local_xstream->rank);
1842  } else {
1843  ABTI_ASSERT(0);
1844  ABTU_unreachable();
1845  }
1846 }
1847 
1848 static inline void xstream_schedule_task(ABTI_xstream *p_local_xstream,
1849  ABTI_thread *p_task)
1850 {
1851 #ifndef ABT_CONFIG_DISABLE_TASK_CANCEL
1854  ABTI_tool_event_thread_cancel(p_local_xstream, p_task);
1856  p_task);
1857  return;
1858  }
1859 #endif
1860 
1861  /* Change the task state */
1863 
1864  /* Set the associated ES */
1865  p_task->p_last_xstream = p_local_xstream;
1866 
1867  /* Execute the task function */
1868  LOG_DEBUG("[T%" PRIu64 ":E%d] running\n", ABTI_thread_get_id(p_task),
1869  p_local_xstream->rank);
1870 
1871  ABTI_thread *p_sched_thread = p_local_xstream->p_thread;
1872  p_local_xstream->p_thread = p_task;
1873  p_task->p_parent = p_sched_thread;
1874 
1875  /* Execute the task function */
1876  ABTI_tool_event_thread_run(p_local_xstream, p_task, p_sched_thread,
1877  p_sched_thread);
1878  LOG_DEBUG("[T%" PRIu64 ":E%d] running\n", ABTI_thread_get_id(p_task),
1879  p_local_xstream->rank);
1880  p_task->f_thread(p_task->p_arg);
1881  ABTI_tool_event_thread_finish(p_local_xstream, p_task, p_sched_thread);
1882  LOG_DEBUG("[T%" PRIu64 ":E%d] stopped\n", ABTI_thread_get_id(p_task),
1883  p_local_xstream->rank);
1884 
1885  /* Set the current running scheduler's thread */
1886  p_local_xstream->p_thread = p_sched_thread;
1887 
1888  /* Terminate the tasklet */
1890  p_task);
1891 }
1892 
1893 #ifndef ABT_CONFIG_DISABLE_MIGRATION
1894 ABTU_ret_err static int xstream_migrate_thread(ABTI_local *p_local,
1895  ABTI_thread *p_thread)
1896 {
1897  int abt_errno;
1898  ABTI_pool *p_pool;
1900  ABTI_thread_mig_data *p_mig_data;
1901  abt_errno = ABTI_thread_get_mig_data(p_local, p_thread, &p_mig_data);
1902  ABTI_CHECK_ERROR(abt_errno);
1903 
1904  /* callback function */
1905  if (p_mig_data->f_migration_cb) {
1906  ABTI_ythread *p_ythread = ABTI_thread_get_ythread_or_null(p_thread);
1907  if (p_ythread) {
1908  ABT_thread thread = ABTI_ythread_get_handle(p_ythread);
1909  p_mig_data->f_migration_cb(thread, p_mig_data->p_migration_cb_arg);
1910  }
1911  }
1912 
1913  /* If request is set, p_migration_pool has a valid pool pointer. */
1916 
1917  /* Extracting argument in migration request. */
1918  p_pool = ABTD_atomic_relaxed_load_ptr(&p_mig_data->p_migration_pool);
1920 
1921  /* Change the associated pool */
1922  p_thread->p_pool = p_pool;
1923 
1924  /* Add the unit to the scheduler's pool */
1925  ABTI_pool_push(p_pool, p_thread->unit);
1926  return ABT_SUCCESS;
1927 }
1928 #endif
1929 
1930 static void xstream_init_main_sched(ABTI_xstream *p_xstream,
1931  ABTI_sched *p_sched)
1932 {
1933  ABTI_ASSERT(p_xstream->p_main_sched == NULL);
1934  /* Set the scheduler as a main scheduler */
1935  p_sched->used = ABTI_SCHED_MAIN;
1936  /* Set the scheduler */
1937  p_xstream->p_main_sched = p_sched;
1938 }
1939 
1940 static void xstream_update_main_sched(ABTI_xstream **pp_local_xstream,
1941  ABTI_xstream *p_xstream,
1942  ABTI_sched *p_sched)
1943 {
1944  /* Set the scheduler as a main scheduler */
1945  p_sched->used = ABTI_SCHED_MAIN;
1946 
1947  ABTI_sched *p_main_sched = p_xstream->p_main_sched;
1948  if (p_main_sched == NULL) {
1949  /* Set the scheduler */
1950  p_xstream->p_main_sched = p_sched;
1951  return;
1952  }
1953 
1954  /* If the ES has a main scheduler, we have to free it */
1955  ABTI_thread *p_thread = (*pp_local_xstream)->p_thread;
1957  ABTI_ythread *p_ythread = ABTI_thread_get_ythread(p_thread);
1958  ABTI_pool *p_tar_pool = ABTI_pool_get_ptr(p_sched->pools[0]);
1959 
1960  /* If the caller ULT is associated with a pool of the current main
1961  * scheduler, it needs to be associated to a pool of new scheduler. */
1962  size_t p;
1963  for (p = 0; p < p_main_sched->num_pools; p++) {
1964  if (p_ythread->thread.p_pool ==
1965  ABTI_pool_get_ptr(p_main_sched->pools[p])) {
1966  /* Associate the work unit to the first pool of new scheduler */
1967  p_ythread->thread.p_pool->u_free(&p_ythread->thread.unit);
1968  ABT_thread h_thread = ABTI_ythread_get_handle(p_ythread);
1969  p_ythread->thread.unit = p_tar_pool->u_create_from_thread(h_thread);
1970  p_ythread->thread.p_pool = p_tar_pool;
1971  break;
1972  }
1973  }
1974  if (p_xstream->type == ABTI_XSTREAM_TYPE_PRIMARY) {
1975  /* Since the primary ES does not finish its execution until ABT_finalize
1976  * is called, its main scheduler needs to be automatically freed when
1977  * it is freed in ABT_finalize. */
1978  p_sched->automatic = ABT_TRUE;
1979  }
1980 
1981  /* Finish the current main scheduler */
1983 
1984  /* If the ES is secondary, we should take the associated ULT of the
1985  * current main scheduler and keep it in the new scheduler. */
1986  p_sched->p_ythread = p_main_sched->p_ythread;
1987  /* The current ULT is pushed to the new scheduler's pool so that when
1988  * the new scheduler starts (see below), it can be scheduled by the new
1989  * scheduler. When the current ULT resumes its execution, it will free
1990  * the current main scheduler (see below). */
1991  ABTI_pool_push(p_tar_pool, p_ythread->thread.unit);
1992 
1993  /* Set the scheduler */
1994  p_xstream->p_main_sched = p_sched;
1995 
1996  /* Switch to the current main scheduler */
1998  ABTI_ythread_context_switch_to_parent(pp_local_xstream, p_ythread,
2000 
2001  /* Now, we free the current main scheduler. p_main_sched->p_ythread must
2002  * be NULL to avoid freeing it in ABTI_sched_discard_and_free(). */
2003  p_main_sched->p_ythread = NULL;
2005  p_main_sched, ABT_FALSE);
2006 }
2007 
2008 static void xstream_update_max_xstreams(int newrank)
2009 {
2010  /* The lock must be taken. */
2011  ABTI_global *p_global = gp_ABTI_global;
2012  if (newrank >= p_global->max_xstreams) {
2013  static int max_xstreams_warning_once = 0;
2014  if (max_xstreams_warning_once == 0) {
2015  /* Because some Argobots functionalities depend on the runtime value
2016  * ABT_MAX_NUM_XSTREAMS (or gp_ABTI_global->max_xstreams), changing
2017  * this value at run-time can cause an error. For example, using
2018  * ABT_mutex created before updating max_xstreams causes an error
2019  * since ABTI_thread_htable's array size depends on
2020  * ABT_MAX_NUM_XSTREAMS. To fix this issue, please set a larger
2021  * number to ABT_MAX_NUM_XSTREAMS in advance. */
2022  char *warning_message;
2023  int abt_errno =
2024  ABTU_malloc(sizeof(char) * 1024, (void **)&warning_message);
2025  if (!ABTI_IS_ERROR_CHECK_ENABLED || abt_errno == ABT_SUCCESS) {
2026  snprintf(warning_message, 1024,
2027  "Warning: the number of execution streams exceeds "
2028  "ABT_MAX_NUM_XSTREAMS (=%d). This may cause an error.",
2029  p_global->max_xstreams);
2030  HANDLE_WARNING(warning_message);
2031  ABTU_free(warning_message);
2032  max_xstreams_warning_once = 1;
2033  }
2034  }
2035  /* Anyway. let's increase max_xstreams. */
2036  p_global->max_xstreams = newrank + 1;
2037  }
2038 }
2039 
2040 /* Add p_newxstream to the list. This does not check the rank duplication. */
2041 static void xstream_add_xstream_list(ABTI_xstream *p_newxstream)
2042 {
2043  int rank = p_newxstream->rank;
2044  ABTI_global *p_global = gp_ABTI_global;
2045  ABTI_xstream *p_prev_xstream = p_global->p_xstream_head;
2046  ABTI_xstream *p_xstream = p_prev_xstream;
2047  /* Check if a certain rank is available */
2048  while (p_xstream) {
2049  ABTI_ASSERT(p_xstream->rank != rank);
2050  if (p_xstream->rank > rank) {
2051  /* Use this p_xstream. */
2052  break;
2053  }
2054  p_prev_xstream = p_xstream;
2055  p_xstream = p_xstream->p_next;
2056  }
2057 
2058  if (!p_xstream) {
2059  /* p_newxstream is appended to p_prev_xstream */
2060  if (p_prev_xstream) {
2061  p_prev_xstream->p_next = p_newxstream;
2062  p_newxstream->p_prev = p_prev_xstream;
2063  p_newxstream->p_next = NULL;
2064  } else {
2065  ABTI_ASSERT(p_global->p_xstream_head == NULL);
2066  p_newxstream->p_prev = NULL;
2067  p_newxstream->p_next = NULL;
2068  p_global->p_xstream_head = p_newxstream;
2069  }
2070  } else {
2071  /* p_newxstream is inserted in the middle.
2072  * (p_xstream->p_prev) -> p_new_xstream -> p_xstream */
2073  if (p_xstream->p_prev) {
2074  p_xstream->p_prev->p_next = p_newxstream;
2075  p_newxstream->p_prev = p_xstream->p_prev;
2076  } else {
2077  /* This p_xstream is the first element */
2078  ABTI_ASSERT(p_global->p_xstream_head == p_xstream);
2079  p_global->p_xstream_head = p_newxstream;
2080  }
2081  p_xstream->p_prev = p_newxstream;
2082  p_newxstream->p_next = p_xstream;
2083  }
2084 }
2085 
2086 /* Remove p_xstream from the list. */
2087 static void xstream_remove_xstream_list(ABTI_xstream *p_xstream)
2088 {
2089  if (!p_xstream->p_prev) {
2090  ABTI_global *p_global = gp_ABTI_global;
2091  ABTI_ASSERT(p_global->p_xstream_head == p_xstream);
2092  p_global->p_xstream_head = p_xstream->p_next;
2093  } else {
2094  p_xstream->p_prev->p_next = p_xstream->p_next;
2095  }
2096  if (p_xstream->p_next) {
2097  p_xstream->p_next->p_prev = p_xstream->p_prev;
2098  }
2099 }
2100 
2101 /* Set a new rank to ES */
2102 static ABT_bool xstream_set_new_rank(ABTI_xstream *p_newxstream, int rank)
2103 {
2104  ABTI_global *p_global = gp_ABTI_global;
2105 
2108  if (rank == -1) {
2109  /* Find an unused rank from 0. */
2110  rank = 0;
2111  ABTI_xstream *p_xstream = p_global->p_xstream_head;
2112  while (p_xstream) {
2113  if (p_xstream->rank == rank) {
2114  rank++;
2115  } else {
2116  /* Use this rank. */
2117  break;
2118  }
2119  p_xstream = p_xstream->p_next;
2120  }
2121  } else {
2122  /* Check if a certain rank is available */
2123  ABTI_xstream *p_xstream = p_global->p_xstream_head;
2124  while (p_xstream) {
2125  if (p_xstream->rank == rank) {
2127  return ABT_FALSE;
2128  } else if (p_xstream->rank > rank) {
2129  break;
2130  }
2131  p_xstream = p_xstream->p_next;
2132  }
2133  }
2134  /* Set the rank */
2135  p_newxstream->rank = rank;
2136  xstream_add_xstream_list(p_newxstream);
2138  p_global->num_xstreams++;
2139 
2141  return ABT_TRUE;
2142 }
2143 
2144 /* Change the rank of ES */
2145 static ABT_bool xstream_change_rank(ABTI_xstream *p_xstream, int rank)
2146 {
2147  if (p_xstream->rank == rank) {
2148  /* No need to change the rank. */
2149  return ABT_TRUE;
2150  }
2151  ABTI_global *p_global = gp_ABTI_global;
2152 
2154 
2155  ABTI_xstream *p_next = p_global->p_xstream_head;
2156  /* Check if a certain rank is available. */
2157  while (p_next) {
2158  if (p_next->rank == rank) {
2160  return ABT_FALSE;
2161  } else if (p_next->rank > rank) {
2162  break;
2163  }
2164  p_next = p_next->p_next;
2165  }
2166  /* Let's remove p_xstream from the list first. */
2167  xstream_remove_xstream_list(p_xstream);
2168  /* Then, let's add this p_xstream. */
2169  p_xstream->rank = rank;
2170  xstream_add_xstream_list(p_xstream);
2172 
2174  return ABT_TRUE;
2175 }
2176 
2177 static void xstream_return_rank(ABTI_xstream *p_xstream)
2178 {
2179  ABTI_global *p_global = gp_ABTI_global;
2180  /* Remove this xstream from the global ES list */
2183  xstream_remove_xstream_list(p_xstream);
2184  p_global->num_xstreams--;
2185 
2187 }
ABT_xstream_set_affinity
int ABT_xstream_set_affinity(ABT_xstream xstream, int num_cpuids, int *cpuids)
Bind an execution stream to target CPUs.
Definition: stream.c:1362
ABT_THREAD_STATE_TERMINATED
@ ABT_THREAD_STATE_TERMINATED
Definition: abt.h:415
HANDLE_WARNING
#define HANDLE_WARNING(msg)
Definition: abti_error.h:30
ABTU_min_int
static int ABTU_min_int(int a, int b)
Definition: abtu.h:45
ABTI_CHECK_NULL_SCHED_PTR
#define ABTI_CHECK_NULL_SCHED_PTR(p)
Definition: abti_error.h:184
ABTI_xstream_start_primary
void ABTI_xstream_start_primary(ABTI_xstream **pp_local_xstream, ABTI_xstream *p_xstream, ABTI_ythread *p_ythread)
Definition: stream.c:1463
ABT_ERR_INV_THREAD
#define ABT_ERR_INV_THREAD
Error code: invalid work unit.
Definition: abt.h:175
ABT_sched_predef
ABT_sched_predef
Predefined scheduler type.
Definition: abt.h:457
ABTI_sched_get_ptr
static ABTI_sched * ABTI_sched_get_ptr(ABT_sched sched)
Definition: abti_sched.h:11
xstream_update_max_xstreams
static void xstream_update_max_xstreams(int newrank)
Definition: stream.c:2013
xstream_join
static ABTU_ret_err int xstream_join(ABTI_local **pp_local, ABTI_xstream *p_xstream)
Definition: stream.c:1712
ABTI_xstream::ctx
ABTD_xstream_context ctx
Definition: abti.h:250
ABTI_thread_mig_data::f_migration_cb
void(* f_migration_cb)(ABT_thread, void *)
Definition: abti.h:373
ABT_bool
int ABT_bool
Boolean type.
Definition: abt.h:988
ABTI_XSTREAM_TYPE_PRIMARY
@ ABTI_XSTREAM_TYPE_PRIMARY
Definition: abti.h:65
ABT_ERR_CPUID
#define ABT_ERR_CPUID
Error code: an error related to CPU ID.
Definition: abt.h:390
ABTI_THREAD_REQ_TERMINATE
#define ABTI_THREAD_REQ_TERMINATE
Definition: abti.h:42
ABTI_sched_create_basic
ABTU_ret_err int ABTI_sched_create_basic(ABT_sched_predef predef, int num_pools, ABT_pool *pools, ABTI_sched_config *p_config, ABTI_sched **pp_newsched)
Definition: sched.c:658
ABTI_SCHED_NOT_USED
@ ABTI_SCHED_NOT_USED
Definition: abti.h:70
ABTI_SETUP_LOCAL_XSTREAM
#define ABTI_SETUP_LOCAL_XSTREAM(pp_local_xstream)
Definition: abti_error.h:68
ABTD_atomic_acquire_load_uint32
static uint32_t ABTD_atomic_acquire_load_uint32(const ABTD_atomic_uint32 *ptr)
Definition: abtd_atomic.h:928
ABTD_affinity_cpuset_apply
ABTU_ret_err int ABTD_affinity_cpuset_apply(ABTD_xstream_context *p_ctx, const ABTD_affinity_cpuset *p_cpuset)
Definition: abtd_affinity.c:426
ABTI_ythread_create_main_sched
ABTU_ret_err int ABTI_ythread_create_main_sched(ABTI_local *p_local, ABTI_xstream *p_xstream, ABTI_sched *p_sched)
Definition: thread.c:2239
ABT_thread
struct ABT_thread_opaque * ABT_thread
Work unit handle type.
Definition: abt.h:877
ABTI_thread_mig_data::p_migration_pool
ABTD_atomic_ptr p_migration_pool
Definition: abti.h:376
ABTI_xstream_create_primary
ABTU_ret_err int ABTI_xstream_create_primary(ABTI_xstream **pp_xstream)
Definition: stream.c:1443
ABT_xstream_self
int ABT_xstream_self(ABT_xstream *xstream)
Get an execution stream that is running the calling work unit.
Definition: stream.c:595
ABTD_xstream_context_print
void ABTD_xstream_context_print(ABTD_xstream_context *p_ctx, FILE *p_os, int indent)
Definition: abtd_stream.c:109
ABT_ERR_INV_XSTREAM
#define ABT_ERR_INV_XSTREAM
Error code: invalid executions stream.
Definition: abt.h:113
ABTI_thread::type
ABTI_thread_type type
Definition: abti.h:348
ABTI_sched_exit
void ABTI_sched_exit(ABTI_sched *p_sched)
Definition: sched.c:653
ABT_xstream_set_rank
int ABT_xstream_set_rank(ABT_xstream xstream, int rank)
Set a rank for an execution stream.
Definition: stream.c:685
xstream_update_main_sched
static void xstream_update_main_sched(ABTI_xstream **pp_local_xstream, ABTI_xstream *p_xstream, ABTI_sched *p_sched)
Definition: stream.c:1945
ABT_xstream_get_num
int ABT_xstream_get_num(int *num_xstreams)
Get the number of current existing execution streams.
Definition: stream.c:1097
xstream_add_xstream_list
static void xstream_add_xstream_list(ABTI_xstream *p_newxstream)
Definition: stream.c:2046
ABT_xstream_get_affinity
int ABT_xstream_get_affinity(ABT_xstream xstream, int max_cpuids, int *cpuids, int *num_cpuids)
Get CPU IDs of CPUs to which an execution stream is bound.
Definition: stream.c:1426
ABTI_CHECK_ERROR
#define ABTI_CHECK_ERROR(abt_errno)
Definition: abti_error.h:127
ABTI_sched::num_pools
size_t num_pools
Definition: abti.h:272
ABTI_sched::automatic
ABT_bool automatic
Definition: abti.h:267
ABTI_xstream::rank
int rank
Definition: abti.h:245
gp_ABTI_global
ABTI_global * gp_ABTI_global
Definition: global.c:18
ABTI_thread::p_arg
void * p_arg
Definition: abti.h:353
ABTI_THREAD_REQ_ORPHAN
#define ABTI_THREAD_REQ_ORPHAN
Definition: abti.h:46
ABTI_sched_get_handle
static ABT_sched ABTI_sched_get_handle(ABTI_sched *p_sched)
Definition: abti_sched.h:26
ABTI_thread::unit
ABT_unit unit
Definition: abti.h:349
ABT_sched_config
struct ABT_sched_config_opaque * ABT_sched_config
Scheduler configuration handle type.
Definition: abt.h:802
ABTI_xstream::type
ABTI_xstream_type type
Definition: abti.h:246
ABT_SCHED_DEFAULT
@ ABT_SCHED_DEFAULT
Definition: abt.h:459
ABTI_THREAD_TYPE_YIELDABLE
#define ABTI_THREAD_TYPE_YIELDABLE
Definition: abti.h:80
ABTI_thread::request
ABTD_atomic_uint32 request
Definition: abti.h:355
ABTI_INDENT
#define ABTI_INDENT
Definition: abti.h:56
ABTI_thread_get_ythread
static ABTI_ythread * ABTI_thread_get_ythread(ABTI_thread *p_thread)
Definition: abti_thread.h:52
xstream_return_rank
static void xstream_return_rank(ABTI_xstream *p_xstream)
Definition: stream.c:2182
ABTD_xstream_context_free
void ABTD_xstream_context_free(ABTD_xstream_context *p_ctx)
Definition: abtd_stream.c:63
ABTI_CHECK_TRUE_MSG
#define ABTI_CHECK_TRUE_MSG(cond, abt_errno, msg)
Definition: abti_error.h:158
ABTI_thread_get_id
ABT_unit_id ABTI_thread_get_id(ABTI_thread *p_thread)
Definition: thread.c:2439
ABTI_thread_mig_data
Definition: abti.h:372
ABTI_THREAD_REQ_NON_YIELD
#define ABTI_THREAD_REQ_NON_YIELD
Definition: abti.h:48
ABTI_SETUP_LOCAL_YTHREAD_WITH_INIT_CHECK
#define ABTI_SETUP_LOCAL_YTHREAD_WITH_INIT_CHECK(pp_local_xstream, pp_ythread)
Definition: abti_error.h:115
ABTI_pool_push
static void ABTI_pool_push(ABTI_pool *p_pool, ABT_unit unit)
Definition: abti_pool.h:53
ABTI_pool::u_create_from_thread
ABT_unit_create_from_thread_fn u_create_from_thread
Definition: abti.h:312
ABTI_xstream_run_unit
void ABTI_xstream_run_unit(ABTI_xstream **pp_local_xstream, ABT_unit unit, ABTI_pool *p_pool)
Definition: stream.c:1491
ABT_xstream_cancel
int ABT_xstream_cancel(ABT_xstream xstream)
Send a cancellation request to an execution stream.
Definition: stream.c:552
ABTI_thread
Definition: abti.h:344
ABTI_IS_ERROR_CHECK_ENABLED
#define ABTI_IS_ERROR_CHECK_ENABLED
Definition: abti.h:20
ABT_xstream_create
int ABT_xstream_create(ABT_sched sched, ABT_xstream *newxstream)
Create a new execution stream.
Definition: stream.c:80
ABTI_xstream_check_events
void ABTI_xstream_check_events(ABTI_xstream *p_xstream, ABTI_sched *p_sched)
Definition: stream.c:1507
ABTI_xstream
Definition: abti.h:240
ABT_xstream_get_main_sched
int ABT_xstream_get_main_sched(ABT_xstream xstream, ABT_sched *sched)
Retrieve the main scheduler of an execution stream.
Definition: stream.c:951
ABTI_sched_config
Definition: abti.h:296
xstream_remove_xstream_list
static void xstream_remove_xstream_list(ABTI_xstream *p_xstream)
Definition: stream.c:2092
ABT_pool
struct ABT_pool_opaque * ABT_pool
Pool handle type.
Definition: abt.h:828
ABTI_sched::p_ythread
ABTI_ythread * p_ythread
Definition: abti.h:273
ABT_xstream_get_rank
int ABT_xstream_get_rank(ABT_xstream xstream, int *rank)
Retrieve a rank of an execution stream.
Definition: stream.c:726
xstream_set_new_rank
static ABT_bool xstream_set_new_rank(ABTI_xstream *p_newxstream, int rank)
Definition: stream.c:2107
ABT_xstream_self_rank
int ABT_xstream_self_rank(int *rank)
Return a rank of an execution stream associated with a caller.
Definition: stream.c:637
ABTI_xstream::p_next
ABTI_xstream * p_next
Definition: abti.h:243
ABT_POOL_ACCESS_MPSC
@ ABT_POOL_ACCESS_MPSC
Definition: abt.h:527
ABTD_xstream_context_revive
void ABTD_xstream_context_revive(ABTD_xstream_context *p_ctx)
Definition: abtd_stream.c:94
ABTU_unreachable
#define ABTU_unreachable()
Definition: abtu.h:116
ABT_xstream_is_primary
int ABT_xstream_is_primary(ABT_xstream xstream, ABT_bool *is_primary)
Check if the target execution stream is primary.
Definition: stream.c:1131
ABTI_sched::used
ABTI_sched_used used
Definition: abti.h:266
ABT_sched
struct ABT_sched_opaque * ABT_sched
Scheduler handle type.
Definition: abt.h:795
xstream_start
static ABTU_ret_err int xstream_start(ABTI_xstream *p_xstream)
Definition: stream.c:1693
ABT_ERR_INV_SCHED
#define ABT_ERR_INV_SCHED
Error code: invalid scheduler.
Definition: abt.h:128
ABTI_pool
Definition: abti.h:300
ABTI_THREAD_TYPE_PRIMARY
#define ABTI_THREAD_TYPE_PRIMARY
Definition: abti.h:78
ABTI_xstream_get_handle
static ABT_xstream ABTI_xstream_get_handle(ABTI_xstream *p_xstream)
Definition: abti_stream.h:26
xstream_init_main_sched
static void xstream_init_main_sched(ABTI_xstream *p_xstream, ABTI_sched *p_sched)
Definition: stream.c:1935
abti.h
ABTI_pool_free
void ABTI_pool_free(ABTI_pool *p_pool)
Definition: pool.c:875
ABTI_THREAD_REQ_MIGRATE
#define ABTI_THREAD_REQ_MIGRATE
Definition: abti.h:44
ABTI_info_check_print_all_thread_stacks
void ABTI_info_check_print_all_thread_stacks(void)
Definition: info.c:895
ABTD_xstream_context_create
ABTU_ret_err int ABTD_xstream_context_create(void *(*f_xstream)(void *), void *p_arg, ABTD_xstream_context *p_ctx)
Definition: abtd_stream.c:48
ABTD_atomic_relaxed_store_uint32
static void ABTD_atomic_relaxed_store_uint32(ABTD_atomic_uint32 *ptr, uint32_t val)
Definition: abtd_atomic.h:1025
ABTI_ythread_exit
ABTU_noreturn void ABTI_ythread_exit(ABTI_xstream *p_local_xstream, ABTI_ythread *p_ythread)
Definition: thread.c:2304
ABTD_atomic_relaxed_load_int
static int ABTD_atomic_relaxed_load_int(const ABTD_atomic_int *ptr)
Definition: abtd_atomic.h:763
ABT_SYNC_EVENT_TYPE_OTHER
@ ABT_SYNC_EVENT_TYPE_OTHER
Definition: abt.h:653
ABT_xstream
struct ABT_xstream_opaque * ABT_xstream
Execution stream handle type.
Definition: abt.h:776
ABTI_thread_get_ythread_or_null
static ABTI_ythread * ABTI_thread_get_ythread_or_null(ABTI_thread *p_thread)
Definition: abti_thread.h:59
ABTI_pool_add_thread
static void ABTI_pool_add_thread(ABTI_thread *p_thread)
Definition: abti_pool.h:59
ABTI_thread::state
ABTD_atomic_int state
Definition: abti.h:354
ABTI_HANDLE_ERROR
#define ABTI_HANDLE_ERROR(n)
Definition: abti_error.h:121
ABT_xstream_create_basic
int ABT_xstream_create_basic(ABT_sched_predef predef, int num_pools, ABT_pool *pools, ABT_sched_config config, ABT_xstream *newxstream)
Create a new execution stream with a predefined scheduler.
Definition: stream.c:168
ABTD_xstream_context_set_self
void ABTD_xstream_context_set_self(ABTD_xstream_context *p_ctx)
Definition: abtd_stream.c:104
ABT_xstream_create_with_rank
int ABT_xstream_create_with_rank(ABT_sched sched, int rank, ABT_xstream *newxstream)
Create a new execution stream with a specific rank.
Definition: stream.c:250
ABTU_malloc
static ABTU_ret_err int ABTU_malloc(size_t size, void **p_ptr)
Definition: abtu.h:218
LOG_DEBUG
#define LOG_DEBUG(fmt,...)
Definition: abti_log.h:26
ABTI_sched_finish
void ABTI_sched_finish(ABTI_sched *p_sched)
Definition: sched.c:648
ABTI_ythread_create_root
ABTU_ret_err int ABTI_ythread_create_root(ABTI_local *p_local, ABTI_xstream *p_xstream, ABTI_ythread **pp_root_ythread)
Definition: thread.c:2213
ABTD_atomic_relaxed_store_int
static void ABTD_atomic_relaxed_store_int(ABTD_atomic_int *ptr, int val)
Definition: abtd_atomic.h:996
ABT_xstream_check_events
int ABT_xstream_check_events(ABT_sched sched)
Process events associated with a scheduler.
Definition: stream.c:1217
ABT_ERR_INV_UNIT
#define ABT_ERR_INV_UNIT
Error code: invalid work unit for scheduling.
Definition: abt.h:170
ABT_ERR_XSTREAM_STATE
#define ABT_ERR_XSTREAM_STATE
Error code: an error related to an execution stream state.
Definition: abt.h:261
ABT_POOL_FIFO
@ ABT_POOL_FIFO
Definition: abt.h:498
ABTI_pool_create_basic
ABTU_ret_err int ABTI_pool_create_basic(ABT_pool_kind kind, ABT_pool_access access, ABT_bool automatic, ABTI_pool **pp_newpool)
Definition: pool.c:843
ABTI_xstream::p_main_sched
ABTI_sched * p_main_sched
Definition: abti.h:248
ABTI_thread_mig_data::p_migration_cb_arg
void * p_migration_cb_arg
Definition: abti.h:374
ABT_xstream_set_main_sched_basic
int ABT_xstream_set_main_sched_basic(ABT_xstream xstream, ABT_sched_predef predef, int num_pools, ABT_pool *pools)
Set the main scheduler of an execution stream to a predefined scheduler.
Definition: stream.c:910
ABT_xstream_get_main_pools
int ABT_xstream_get_main_pools(ABT_xstream xstream, int max_pools, ABT_pool *pools)
Get pools associated with the main scheduler of an execution stream.
Definition: stream.c:988
ABTI_pool::u_get_thread
ABT_unit_get_thread_fn u_get_thread
Definition: abti.h:310
ABTI_XSTREAM_TYPE_SECONDARY
@ ABTI_XSTREAM_TYPE_SECONDARY
Definition: abti.h:66
ABT_xstream_set_cpubind
int ABT_xstream_set_cpubind(ABT_xstream xstream, int cpuid)
Bind an execution stream to a target CPU.
Definition: stream.c:1263
ABTI_thread_join
void ABTI_thread_join(ABTI_local **pp_local, ABTI_thread *p_thread)
Definition: thread.c:2277
ABTI_spinlock_release
static void ABTI_spinlock_release(ABTI_spinlock *p_lock)
Definition: abti_spinlock.h:42
ABTI_spinlock_acquire
static void ABTI_spinlock_acquire(ABTI_spinlock *p_lock)
Definition: abti_spinlock.h:28
ABT_unit
struct ABT_unit_opaque * ABT_unit
Work unit handle type for scheduling.
Definition: abt.h:856
ABTI_ythread::ctx
ABTD_ythread_context ctx
Definition: abti.h:381
ABTI_ASSERT
#define ABTI_ASSERT(cond)
Definition: abti_error.h:12
ABTI_sched_set_request
static void ABTI_sched_set_request(ABTI_sched *p_sched, uint32_t req)
Definition: abti_sched.h:57
ABTI_sched_discard_and_free
static void ABTI_sched_discard_and_free(ABTI_local *p_local, ABTI_sched *p_sched, ABT_bool force_free)
Definition: abti_sched.h:43
ABTI_sched::pools
ABT_pool * pools
Definition: abti.h:271
ABT_xstream_exit
int ABT_xstream_exit(void)
Terminate an execution stream that is running the calling ULT.
Definition: stream.c:501
ABTI_tool_event_thread_run
#define ABTI_tool_event_thread_run(p_local_xstream, p_thread, p_prev, p_parent)
Definition: abti_tool.h:288
ABTI_mem_init_local
void ABTI_mem_init_local(ABTI_xstream *p_local_xstream)
Definition: malloc.c:164
ABTI_local_get_local
static ABTI_local * ABTI_local_get_local(void)
Definition: abti_local.h:41
ABTI_xstream::state
ABTD_atomic_int state
Definition: abti.h:247
ABTI_global::num_xstreams
int num_xstreams
Definition: abti.h:179
ABTI_pool::u_free
ABT_unit_free_fn u_free
Definition: abti.h:313
ABT_xstream_join
int ABT_xstream_join(ABT_xstream xstream)
Wait for an execution stream to terminate.
Definition: stream.c:457
ABTI_local_set_xstream
static void ABTI_local_set_xstream(ABTI_xstream *p_local_xstream)
Definition: abti_local.h:60
ABTI_ythread_context_switch_to_parent
static ABTI_ythread * ABTI_ythread_context_switch_to_parent(ABTI_xstream **pp_local_xstream, ABTI_ythread *p_old, ABT_sync_event_type sync_event_type, void *p_sync)
Definition: abti_ythread.h:327
ABT_SUCCESS
#define ABT_SUCCESS
Error code: the routine returns successfully.
Definition: abt.h:90
ABTI_tool_event_thread_join
#define ABTI_tool_event_thread_join(p_local, p_thread, p_caller)
Definition: abti_tool.h:266
ABTI_xstream::p_root_pool
ABTI_pool * p_root_pool
Definition: abti.h:254
ABTI_local_get_local_uninlined
static ABTI_local * ABTI_local_get_local_uninlined(void)
Definition: abti_local.h:51
ABTU_ret_err
#define ABTU_ret_err
Definition: abtu.h:138
ABTI_ythread_free_root
void ABTI_ythread_free_root(ABTI_local *p_local, ABTI_ythread *p_ythread)
Definition: thread.c:2299
ABTI_ythread_get_handle
static ABT_thread ABTI_ythread_get_handle(ABTI_ythread *p_thread)
ABTI_SETUP_LOCAL_YTHREAD
#define ABTI_SETUP_LOCAL_YTHREAD(pp_local_xstream, pp_ythread)
Definition: abti_error.h:83
ABTI_global::p_xstream_head
ABTI_xstream * p_xstream_head
Definition: abti.h:180
ABTD_atomic_acquire_load_int
static int ABTD_atomic_acquire_load_int(const ABTD_atomic_int *ptr)
Definition: abtd_atomic.h:878
ABT_xstream_get_cpubind
int ABT_xstream_get_cpubind(ABT_xstream xstream, int *cpuid)
Get CPU ID of a CPU to which an execution stream is bound.
Definition: stream.c:1313
ABTI_THREAD_REQ_CANCEL
#define ABTI_THREAD_REQ_CANCEL
Definition: abti.h:43
ABTI_local_get_xstream_or_null
static ABTI_xstream * ABTI_local_get_xstream_or_null(ABTI_local *p_local)
Definition: abti_local.h:77
ABTI_global::xstream_list_lock
ABTI_spinlock xstream_list_lock
Definition: abti.h:182
ABTI_SCHED_MAIN
@ ABTI_SCHED_MAIN
Definition: abti.h:71
ABTI_xstream_get_local
static ABTI_local * ABTI_xstream_get_local(ABTI_xstream *p_xstream)
Definition: abti_stream.h:67
xstream_change_rank
static ABT_bool xstream_change_rank(ABTI_xstream *p_xstream, int rank)
Definition: stream.c:2150
ABT_TRUE
#define ABT_TRUE
True constant for ABT_bool.
Definition: abt.h:735
ABT_SCHED_NULL
#define ABT_SCHED_NULL
Definition: abt.h:1044
ABTI_pool_get_ptr
static ABTI_pool * ABTI_pool_get_ptr(ABT_pool pool)
Definition: abti_pool.h:11
ABTI_sched::request
ABTD_atomic_uint32 request
Definition: abti.h:270
xstream_schedule_task
static void xstream_schedule_task(ABTI_xstream *p_local_xstream, ABTI_thread *p_task)
Definition: stream.c:1853
ABT_XSTREAM_STATE_RUNNING
@ ABT_XSTREAM_STATE_RUNNING
Definition: abt.h:398
ABTI_sched_free
void ABTI_sched_free(ABTI_local *p_local, ABTI_sched *p_sched, ABT_bool force_free)
Definition: sched.c:837
ABTI_xstream_terminate_thread
static void ABTI_xstream_terminate_thread(ABTI_local *p_local, ABTI_thread *p_thread)
Definition: abti_stream.h:48
ABTI_sched
Definition: abti.h:265
ABTI_xstream::p_root_ythread
ABTI_ythread * p_root_ythread
Definition: abti.h:253
ABT_FALSE
#define ABT_FALSE
False constant for ABT_bool.
Definition: abt.h:737
ABTI_ythread
Definition: abti.h:379
ABT_xstream_free
int ABT_xstream_free(ABT_xstream *xstream)
Free an execution stream.
Definition: stream.c:396
xstream_migrate_thread
static ABTU_ret_err int xstream_migrate_thread(ABTI_local *p_local, ABTI_thread *p_thread)
Definition: stream.c:1899
ABTD_affinity_cpuset_apply_default
int ABTD_affinity_cpuset_apply_default(ABTD_xstream_context *p_ctx, int rank)
Definition: abtd_affinity.c:432
ABTD_ythread_context_switch
static void ABTD_ythread_context_switch(ABTD_ythread_context *p_old, ABTD_ythread_context *p_new)
Definition: abtd_ythread.h:73
ABT_ERR_INV_ARG
#define ABT_ERR_INV_ARG
Error code: invalid user argument.
Definition: abt.h:249
ABTI_CHECK_NULL_POOL_PTR
#define ABTI_CHECK_NULL_POOL_PTR(p)
Definition: abti_error.h:175
ABTD_affinity_cpuset::num_cpuids
size_t num_cpuids
Definition: abtd.h:36
ABTI_CHECK_NULL_XSTREAM_PTR
#define ABTI_CHECK_NULL_XSTREAM_PTR(p)
Definition: abti_error.h:166
ABT_xstream_get_state
int ABT_xstream_get_state(ABT_xstream xstream, ABT_xstream_state *state)
Get a state of an execution stream.
Definition: stream.c:1024
ABTU_free
static void ABTU_free(void *ptr)
Definition: abtu.h:211
ABTI_thread::p_parent
ABTI_thread * p_parent
Definition: abti.h:351
ABTD_atomic_fetch_or_uint32
static uint32_t ABTD_atomic_fetch_or_uint32(ABTD_atomic_uint32 *ptr, uint32_t v)
Definition: abtd_atomic.h:631
ABTI_ythread_context_switch_to_child
static ABTI_ythread * ABTI_ythread_context_switch_to_child(ABTI_xstream **pp_local_xstream, ABTI_ythread *p_old, ABTI_ythread *p_new)
Definition: abti_ythread.h:338
ABTD_affinity_cpuset_read
ABTU_ret_err int ABTD_affinity_cpuset_read(ABTD_xstream_context *p_ctx, int max_cpuids, int *cpuids, int *p_num_cpuids)
Definition: abtd_affinity.c:418
ABTD_xstream_context_join
void ABTD_xstream_context_join(ABTD_xstream_context *p_ctx)
Definition: abtd_stream.c:78
ABTI_xstream_get_ptr
static ABTI_xstream * ABTI_xstream_get_ptr(ABT_xstream xstream)
Definition: abti_stream.h:11
ABT_xstream_set_main_sched
int ABT_xstream_set_main_sched(ABT_xstream xstream, ABT_sched sched)
Set the main scheduler of an execution stream.
Definition: stream.c:815
ABTI_xstream_print
void ABTI_xstream_print(ABTI_xstream *p_xstream, FILE *p_os, int indent, ABT_bool print_sub)
Definition: stream.c:1559
ABTI_xstream_free
void ABTI_xstream_free(ABTI_local *p_local, ABTI_xstream *p_xstream, ABT_bool force_free)
Definition: stream.c:1523
ABTI_thread::p_last_xstream
ABTI_xstream * p_last_xstream
Definition: abti.h:350
ABTI_ythread::thread
ABTI_thread thread
Definition: abti.h:380
ABTI_THREAD_REQ_NOPUSH
#define ABTI_THREAD_REQ_NOPUSH
Definition: abti.h:47
ABTI_local
struct ABTI_local ABTI_local
Definition: abti.h:104
ABT_XSTREAM_NULL
#define ABT_XSTREAM_NULL
Definition: abt.h:1042
ABTI_tool_event_thread_cancel
#define ABTI_tool_event_thread_cancel(p_local_xstream, p_thread)
Definition: abti_tool.h:305
ABTI_global::set_affinity
ABT_bool set_affinity
Definition: abti.h:186
ABTI_SETUP_LOCAL_XSTREAM_WITH_INIT_CHECK
#define ABTI_SETUP_LOCAL_XSTREAM_WITH_INIT_CHECK(pp_local_xstream)
Definition: abti_error.h:109
ABTI_thread_revive
void ABTI_thread_revive(ABTI_local *p_local, ABTI_pool *p_pool, void(*thread_func)(void *), void *arg, ABTI_thread *p_thread)
Definition: thread.c:2138
ABTI_SETUP_WITH_INIT_CHECK
#define ABTI_SETUP_WITH_INIT_CHECK()
Definition: abti_error.h:59
ABTI_THREAD_REQ_BLOCK
#define ABTI_THREAD_REQ_BLOCK
Definition: abti.h:45
ABTD_ythread_cancel
void ABTD_ythread_cancel(ABTI_xstream *p_local_xstream, ABTI_ythread *p_ythread)
Definition: abtd_ythread.c:113
ABTI_CHECK_TRUE
#define ABTI_CHECK_TRUE(cond, abt_errno)
Definition: abti_error.h:137
ABTI_thread_unset_request
static void ABTI_thread_unset_request(ABTI_thread *p_thread, uint32_t req)
Definition: abti_thread.h:73
ABTI_sched_config_get_ptr
static ABTI_sched_config * ABTI_sched_config_get_ptr(ABT_sched_config config)
Definition: abti_config.h:12
ABTI_global
Definition: abti.h:177
ABTI_thread::f_thread
void(* f_thread)(void *)
Definition: abti.h:352
xstream_launch_root_ythread
static void * xstream_launch_root_ythread(void *p_xstream)
Definition: stream.c:1615
ABT_ERR_INV_XSTREAM_RANK
#define ABT_ERR_INV_XSTREAM_RANK
Error code: invalid executions stream rank.
Definition: abt.h:118
ABT_THREAD_STATE_RUNNING
@ ABT_THREAD_STATE_RUNNING
Definition: abt.h:411
ABT_xstream_revive
int ABT_xstream_revive(ABT_xstream xstream)
Revive a terminated execution stream.
Definition: stream.c:323
ABT_xstream_run_unit
int ABT_xstream_run_unit(ABT_unit unit, ABT_pool pool)
Execute a work unit.
Definition: stream.c:1169
ABTI_thread::p_pool
ABTI_pool * p_pool
Definition: abti.h:356
ABT_UNIT_NULL
#define ABT_UNIT_NULL
Definition: abt.h:1048
ABTI_xstream::p_prev
ABTI_xstream * p_prev
Definition: abti.h:242
ABTD_affinity_cpuset
Definition: abtd.h:35
ABTI_xstream_type
ABTI_xstream_type
Definition: abti.h:64
ABTI_local_get_xstream
static ABTI_xstream * ABTI_local_get_xstream(ABTI_local *p_local)
Definition: abti_local.h:86
ABT_xstream_equal
int ABT_xstream_equal(ABT_xstream xstream1, ABT_xstream xstream2, ABT_bool *result)
Compare two execution stream handles for equality.
Definition: stream.c:1060
ABTI_mem_finalize_local
void ABTI_mem_finalize_local(ABTI_xstream *p_local_xstream)
Definition: malloc.c:172
xstream_create
static ABTU_ret_err int xstream_create(ABTI_sched *p_sched, ABTI_xstream_type xstream_type, int rank, ABTI_xstream **pp_xstream)
Definition: stream.c:1640
ABTD_atomic_release_store_int
static void ABTD_atomic_release_store_int(ABTD_atomic_int *ptr, int val)
Definition: abtd_atomic.h:1065
ABTI_global::max_xstreams
int max_xstreams
Definition: abti.h:178
ABTI_SCHED_REQ_FINISH
#define ABTI_SCHED_REQ_FINISH
Definition: abti.h:38
ABTI_thread_get_ptr
static ABTI_thread * ABTI_thread_get_ptr(ABT_thread thread)
Definition: abti_thread.h:9
ABT_XSTREAM_STATE_TERMINATED
@ ABT_XSTREAM_STATE_TERMINATED
Definition: abt.h:400
ABTI_thread_get_mig_data
ABTU_ret_err int ABTI_thread_get_mig_data(ABTI_local *p_local, ABTI_thread *p_thread, ABTI_thread_mig_data **pp_mig_data)
Definition: thread.c:2315
ABTI_tool_event_thread_finish
#define ABTI_tool_event_thread_finish(p_local_xstream, p_thread, p_parent)
Definition: abti_tool.h:297
xstream_schedule_ythread
static void xstream_schedule_ythread(ABTI_xstream **pp_local_xstream, ABTI_ythread *p_ythread)
Definition: stream.c:1736
ABTD_atomic_relaxed_load_ptr
static void * ABTD_atomic_relaxed_load_ptr(const ABTD_atomic_ptr *ptr)
Definition: abtd_atomic.h:846
ABTD_affinity_cpuset::cpuids
int * cpuids
Definition: abtd.h:37
ABTI_thread_set_request
static void ABTI_thread_set_request(ABTI_thread *p_thread, uint32_t req)
Definition: abti_thread.h:68
ABT_xstream_state
ABT_xstream_state
State of an execution stream.
Definition: abt.h:396
ABTI_sched_print
void ABTI_sched_print(ABTI_sched *p_sched, FILE *p_os, int indent, ABT_bool print_sub)
Definition: sched.c:956
ABTI_THREAD_REQ_JOIN
#define ABTI_THREAD_REQ_JOIN
Definition: abti.h:41