1// RUN: %libomp-compile && env OMP_PLACES=cores %libomp-run | FileCheck %s
2// REQUIRES: ompt, linux
3#include "callback.h"
4#include <omp.h>
5#define __USE_GNU
6#include <sched.h>
7#undef __USE_GNU
8
9void print_list(char *function_name, int size, int list[]) {
10 printf("%" PRIu64 ": %s(0)=(%d", ompt_get_thread_data()->value, function_name,
11 list[0]);
12 int i;
13 for (i = 1; i < size; i++) {
14 printf(",%d", list[i]);
15 }
16 printf(")\n");
17}
18
19int main() {
20#pragma omp parallel num_threads(1)
21 {
22 printf("%" PRIu64 ": omp_get_num_places()=%d\n",
23 ompt_get_thread_data()->value, omp_get_num_places());
24 printf("%" PRIu64 ": ompt_get_num_places()=%d\n",
25 ompt_get_thread_data()->value, ompt_get_num_places());
26
27 int omp_ids_size = omp_get_place_num_procs(0);
28 int omp_ids[omp_ids_size];
29 omp_get_place_proc_ids(0, omp_ids);
30 print_list(function_name: "omp_get_place_proc_ids", size: omp_ids_size, list: omp_ids);
31 int ompt_ids_size = ompt_get_place_proc_ids(0, 0, NULL);
32 int ompt_ids[ompt_ids_size];
33 ompt_get_place_proc_ids(0, ompt_ids_size, ompt_ids);
34 print_list(function_name: "ompt_get_place_proc_ids", size: ompt_ids_size, list: ompt_ids);
35
36 printf("%" PRIu64 ": omp_get_place_num()=%d\n",
37 ompt_get_thread_data()->value, omp_get_place_num());
38 printf("%" PRIu64 ": ompt_get_place_num()=%d\n",
39 ompt_get_thread_data()->value, ompt_get_place_num());
40
41 int omp_nums_size = omp_get_partition_num_places();
42 int omp_nums[omp_nums_size];
43 omp_get_partition_place_nums(omp_nums);
44 print_list(function_name: "omp_get_partition_place_nums", size: omp_nums_size, list: omp_nums);
45 int ompt_nums_size = ompt_get_partition_place_nums(0, omp_nums);
46 int ompt_nums[ompt_nums_size];
47 ompt_get_partition_place_nums(ompt_nums_size, ompt_nums);
48 print_list(function_name: "ompt_get_partition_place_nums", size: ompt_nums_size, list: ompt_nums);
49
50 printf("%" PRIu64 ": sched_getcpu()=%d\n", ompt_get_thread_data()->value,
51 sched_getcpu());
52 printf("%" PRIu64 ": ompt_get_proc_id()=%d\n",
53 ompt_get_thread_data()->value, ompt_get_proc_id());
54
55 printf("%" PRIu64 ": omp_get_num_procs()=%d\n",
56 ompt_get_thread_data()->value, omp_get_num_procs());
57 printf("%" PRIu64 ": ompt_get_num_procs()=%d\n",
58 ompt_get_thread_data()->value, ompt_get_num_procs());
59 }
60
61 // Check if libomp supports the callbacks for this test.
62
63 // CHECK: 0: NULL_POINTER=[[NULL:.*$]]
64
65 // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: omp_get_num_places
66 // CHECK-SAME: ()=[[NUM_PLACES:[0-9]+]]
67 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_num_places()=[[NUM_PLACES]]
68
69 // CHECK: {{^}}[[MASTER_ID]]: omp_get_place_proc_ids
70 // CHECK-SAME: (0)=([[PROC_IDS:[0-9\,]+]])
71 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_place_proc_ids(0)=([[PROC_IDS]])
72
73 // CHECK: {{^}}[[MASTER_ID]]: omp_get_place_num()=[[PLACE_NUM:[-]?[0-9]+]]
74 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_place_num()=[[PLACE_NUM]]
75
76 // CHECK: {{^}}[[MASTER_ID]]: omp_get_partition_place_nums
77 // CHECK-SAME: (0)=([[PARTITION_PLACE_NUMS:[0-9\,]+]])
78 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_partition_place_nums
79 // CHECK-SAME: (0)=([[PARTITION_PLACE_NUMS]])
80
81 // CHECK: {{^}}[[MASTER_ID]]: sched_getcpu()=[[CPU_ID:[0-9]+]]
82 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_proc_id()=[[CPU_ID]]
83
84 // CHECK: {{^}}[[MASTER_ID]]: omp_get_num_procs()=[[NUM_PROCS:[-]?[0-9]+]]
85 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_num_procs()=[[NUM_PROCS]]
86
87 return 0;
88}
89

source code of openmp/runtime/test/ompt/misc/api_calls_places.c