20#include <sys/syscall.h>
35 return (
int)syscall(SYS_gettid);
42 int place = omp_get_place_num();
43 int num_procs = omp_get_place_num_procs(place);
44 int *ids = (
int*)malloc(
sizeof(
int) * num_procs);
45 omp_get_place_proc_ids(place, ids);
48 printf(
"Primary Thread Place: %d\n", place);
49 printf(
"Primary Thread mask: %s\n",
buf);
51 for (
i = 0;
i < num_procs; ++
i) {
58 for (
i = 0;
i < max_cpu; ++
i) {
62 for (
j = 0;
j < num_procs; ++
j) {
80 int root_id = *((
int*)arg);
94 printf(
"Initial application thread (pid=%d, tid=%d, spawner=%d) reached thread_func (will call OpenMP)\n", pid, tid,
spawner);
106 printf(
"Exactly %d threads in the #pragma omp parallel\n",
111 printf(
"OpenMP thread %d: gtid=%d\n", omp_get_thread_num(), gtid);
116 fprintf(stderr,
"error: place and affinity mask do not match for primary thread\n");
124 printf(
"New root pthread (pid=%d, tid=%d) reached thread_func\n", pid, tid);
130 pthread_mutex_lock(&
lock);
132 pthread_mutex_unlock(&
lock);
141 printf(
"root thread %d mask: ", root_id);
143 printf(
"initial affinity mask: %s\n",
buf);
144 fprintf(stderr,
"error: root thread %d affinity mask not equal"
145 " to initial full mask\n", root_id);
154int main(
int argc,
char** argv) {
156 if (argc != 3 && argc != 4) {
157 fprintf(stderr,
"usage: %s <num_roots> <register_workers_bool> [<spawn_root_number>]\n", argv[0]);
162 pthread_mutex_init(&
lock, NULL);
170 pthread_t *roots = (pthread_t*)malloc(
sizeof(pthread_t) *
num_roots);
171 int *root_ids = (
int*)malloc(
sizeof(
int) *
num_roots);
191 pthread_join(roots[
i], &
status);
195 pthread_mutex_destroy(&
lock);
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int mask
static volatile kmp_i18n_cat_status_t status
#define omp_set_num_threads
static int affinity_mask_isset(const affinity_mask_t *mask, int cpu)
static affinity_mask_t * affinity_mask_alloc()
#define AFFINITY_MAX_CPUS
static int affinity_mask_equal(const affinity_mask_t *mask1, const affinity_mask_t *mask2)
static void affinity_mask_free(affinity_mask_t *mask)
static size_t affinity_mask_snprintf(char *buf, size_t bufsize, const affinity_mask_t *mask)
static void get_thread_affinity(affinity_mask_t *mask)
int __kmpc_global_thread_num(void *)
affinity_mask_t * full_mask
int place_and_affinity_match()
volatile int num_roots_arrived
void * thread_func(void *arg)
int omp_get_num_threads()