blob: eef547097ea5ae5a4749addf4e719b0d6d6b7b4b [file] [log] [blame]
Jonathan Peyton614c7ef2015-09-21 20:41:31 +00001/* Global headerfile of the OpenMP Testsuite */
2
3#ifndef OMP_TESTSUITE_H
4#define OMP_TESTSUITE_H
5
6#include <stdio.h>
Jonathan Peyton1ab887d2016-05-23 17:50:32 +00007#include <stdlib.h>
Jonathan Peyton614c7ef2015-09-21 20:41:31 +00008#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 */
Alexey Bataevb0eae8d2015-11-02 13:43:32 +000016#define SLEEPTIME 1
Jonathan Peyton614c7ef2015-09-21 20:41:31 +000017
18/* Definitions for tasks */
19/**********************************************************/
20#define NUM_TASKS 25
21#define MAX_TASKS_PER_THREAD 5
22
Jonathan Peyton1ab887d2016-05-23 17:50:32 +000023#ifdef _WIN32
24// Windows versions of pthread_create() and pthread_join()
25# include <windows.h>
26typedef HANDLE pthread_t;
27
28// encapsulates the information about a pthread-callable function
29struct thread_func_info_t {
30 void* (*start_routine)(void*);
31 void* arg;
32};
33
34// call the void* start_routine(void*);
35static DWORD __thread_func_wrapper(LPVOID lpParameter) {
36 struct thread_func_info_t* function_information;
37 function_information = (struct thread_func_info_t*)lpParameter;
38 function_information->start_routine(function_information->arg);
39 free(function_information);
40 return 0;
41}
42
43// attr is ignored
44static int pthread_create(pthread_t *thread, void *attr,
45 void *(*start_routine) (void *), void *arg) {
46 pthread_t pthread;
47 struct thread_func_info_t* info;
48 info = (struct thread_func_info_t*)malloc(sizeof(struct thread_func_info_t));
49 info->start_routine = start_routine;
50 info->arg = arg;
51 pthread = CreateThread(NULL, 0, __thread_func_wrapper, info, 0, NULL);
52 if (pthread == NULL) {
53 fprintf(stderr, "CreateThread() failed: Error #%u.\n", GetLastError());
54 exit(1);
55 }
56 *thread = pthread;
57 return 0;
58}
59// retval is ignored for now
60static int pthread_join(pthread_t thread, void **retval) {
61 int rc;
62 rc = WaitForSingleObject(thread, INFINITE);
63 if (rc == WAIT_FAILED) {
64 fprintf(stderr, "WaitForSingleObject() failed: Error #%u.\n",
65 GetLastError());
66 exit(1);
67 }
68 rc = CloseHandle(thread);
69 if (rc == 0) {
70 fprintf(stderr, "CloseHandle() failed: Error #%u.\n", GetLastError());
71 exit(1);
72 }
73 return 0;
74}
75#else
76# include <pthread.h>
77#endif
78
Jonathan Peyton614c7ef2015-09-21 20:41:31 +000079#endif