LLVM OpenMP 19.0.0git
omp_testsuite.h
Go to the documentation of this file.
1/* Global headerfile of the OpenMP Testsuite */
2
3#ifndef OMP_TESTSUITE_H
4#define OMP_TESTSUITE_H
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <omp.h>
9
10/* General */
11/**********************************************************/
12#define LOOPCOUNT 1000 /* Number of iterations to slit amongst threads */
13#define REPETITIONS 10 /* Number of times to run each test */
14
15/* following times are in seconds */
16#define SLEEPTIME 1
17
18/* Definitions for tasks */
19/**********************************************************/
20#define NUM_TASKS 25
21#define MAX_TASKS_PER_THREAD 5
22
23// Functions that call a parallel region that does very minimal work
24// Some compilers may optimize away an empty parallel region
25volatile int g_counter__;
26
27// If nthreads == 0, then do not use num_threads() clause
28static void go_parallel() {
29 g_counter__ = 0;
30 #pragma omp parallel
31 {
32 #pragma omp atomic
34 }
35}
36
37static void go_parallel_nthreads(int nthreads) {
38 g_counter__ = 0;
39 #pragma omp parallel num_threads(nthreads)
40 {
41 #pragma omp atomic
43 }
44}
45
46static void go_parallel_spread() {
47 g_counter__ = 0;
48 #pragma omp parallel proc_bind(spread)
49 {
50 #pragma omp atomic
52 }
53}
54
55static void go_parallel_close() {
56 g_counter__ = 0;
57 #pragma omp parallel proc_bind(close)
58 {
59 #pragma omp atomic
61 }
62}
63
64static void go_parallel_master() {
65 g_counter__ = 0;
66 #pragma omp parallel proc_bind(master)
67 {
68 #pragma omp atomic
70 }
71}
72
73static inline int get_exit_value() {
74 return ((g_counter__ == -1) ? EXIT_FAILURE : EXIT_SUCCESS);
75}
76
77#ifdef _WIN32
78// Windows versions of pthread_create() and pthread_join()
79# include <windows.h>
80typedef HANDLE pthread_t;
81
82// encapsulates the information about a pthread-callable function
83struct thread_func_info_t {
84 void* (*start_routine)(void*);
85 void* arg;
86};
87
88// call the void* start_routine(void*);
89static DWORD WINAPI __thread_func_wrapper(LPVOID lpParameter) {
90 struct thread_func_info_t* function_information;
91 function_information = (struct thread_func_info_t*)lpParameter;
92 function_information->start_routine(function_information->arg);
93 free(function_information);
94 return 0;
95}
96
97// attr is ignored
98static int pthread_create(pthread_t *thread, void *attr,
99 void *(*start_routine) (void *), void *arg) {
100 pthread_t pthread;
101 struct thread_func_info_t* info;
102 info = (struct thread_func_info_t*)malloc(sizeof(struct thread_func_info_t));
103 info->start_routine = start_routine;
104 info->arg = arg;
105 pthread = CreateThread(NULL, 0, __thread_func_wrapper, info, 0, NULL);
106 if (pthread == NULL) {
107 fprintf(stderr, "CreateThread() failed: Error #%u.\n",
108 (unsigned) GetLastError());
109 exit(1);
110 }
111 *thread = pthread;
112 return 0;
113}
114// retval is ignored for now
115static int pthread_join(pthread_t thread, void **retval) {
116 int rc;
117 rc = WaitForSingleObject(thread, INFINITE);
118 if (rc == WAIT_FAILED) {
119 fprintf(stderr, "WaitForSingleObject() failed: Error #%u.\n",
120 (unsigned) GetLastError());
121 exit(1);
122 }
123 rc = CloseHandle(thread);
124 if (rc == 0) {
125 fprintf(stderr, "CloseHandle() failed: Error #%u.\n",
126 (unsigned) GetLastError());
127 exit(1);
128 }
129 return 0;
130}
131#else
132# include <pthread.h>
133#endif
134
135#endif
volatile int g_counter__
Definition: omp_testsuite.h:25
static void go_parallel()
Definition: omp_testsuite.h:28
static void go_parallel_nthreads(int nthreads)
Definition: omp_testsuite.h:37
static void go_parallel_master()
Definition: omp_testsuite.h:64
static void go_parallel_spread()
Definition: omp_testsuite.h:46
static void go_parallel_close()
Definition: omp_testsuite.h:55
static int get_exit_value()
Definition: omp_testsuite.h:73